PDA

View Full Version : Little bit of PHP help! :)



Fehm
04-04-2009, 11:39 AM
Hey!
What im trying to acheive is this:
I have a create user form, and i want for the person who is creating the user to be able to select a rank from a drop downlist and then insert it into a MySQL database.

I can do this easily, but what i would like, to make things simpler later on, is that when the user selects say: Admin from the drop downlist and presses submit, the rank that is inserted into the database is '1' and Mod would be '2', its in my knowledge to edit this and insert into the database its just how would i make it so that the user can see 'Admin' but what is inserted is '1'

Thanks for any help :)
Callum

Trinity
04-04-2009, 12:33 PM
<select>
<option value="1">Admin</option>
<option value="2">Mod</option>
</select>

Fehm
04-04-2009, 12:37 PM
<select>
<option value="1">Admin</option>
<option value="2">Mod</option>
</select>


How would i go about inserting that into my mysql database?

Fehm
04-04-2009, 12:38 PM
<select>
<option value="1">Admin</option>
<option value="2">Mod</option>
</select>


How would i go about inserting that into my mysql database?
and thank you! :)

Edit by Robbie! (Forum Super Moderator): Please do not double post within the time limit

Dentafrice
04-04-2009, 01:41 PM
<?php
if($_POST) {
$rank = $_POST["rank"];
mysql_query("INSERT INTO `stupid_table` (rank) VALUES('$rank')");
}
?>

<form name="test" method="post" action="test.php">
<select name="rank">
<option value="1">Administrator</option>
<option value="2">Moderator</option>
<option value="3">User</option>
</select>

<input type="submit" value="Add" />
</form>


If you selected "Administrator", it would be sent to $rank, and put in the database as "1".

Fehm
04-04-2009, 01:44 PM
Ive sorted that now! Sorry i didntwant to triple post!

Thanks for your help anyway!!
:)

Want to hide these adverts? Register an account for free!