PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$query = "SELECT name FROM names";
$result = @mysql_query ($query);
if ($result) {
echo '<form><select name="names">';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<option value="$rowї0]">$rowї0]\n";
}
echo '</select></form>';
mysql_free_result ($result);
} else {
echo '<p>The box could not be created due to a system error. Please try again later.</p>';
}
mysql_close();
?>
But i want to have the information posted to the database when i click the submit button. so then instead of typing the name of the person every time you can select it out of the box. i cant figure out how to do it though. help is appreciated.
if(!empty($_POST))
{
$name = mysql_escape_string($_POST['names']);
$sql = 'SELECT name FROM names where name = ''' . $name . '''';
$query = mysql_query( $sql ) or die(mysql_error());
if( mysql_num_rows( $query ) > 0 )
{
// user was found in the database, do whatever you want here
}
else
{
// user wasn't in the database, hacking attempt.
}
}
well, i dont need to check if a certain name is selected, because the list of names in the box just came from the dbase. on the form, it will have that box with all the names in it, and a box for the date, and a text area for a comment. you would select which name you want the comment under, enter the date, and type the comment. when you hit submit, the name date and comment are added to a different table. i know how to go and post textboxes to the dbase but not those menus.
I do those to make sure someone isn't trying to add random garbage or hack into the server.
inserting a select works exactly like inserting a textbox. If you have multiple selection allowed, then it can get tricky, (mildly) as you'll have to name the select tag with an array note: