Forum Moderators: coopster

Message Too Old, No Replies

PhP and Mysql Help finding tables

         

phil2564

6:33 pm on May 17, 2004 (gmt 0)

10+ Year Member



I am new to PHP and MYSQL so don't laugh at my question I have 2 tables in my database one name female and one named male. I have a drop down menu in a html form with male and female on the menu with th e same values male and female and name and id called sex. When I person uses the drop down menu on my form I would like to display everyone from the male table or the female table. here is what I have been using could someone alter it so it will work or explain why I am get T VARIABLE problems.

Here is the PHP script:

<?php
$conn = mysql_connect("localhost","","");
mysql_select_db("models",$conn);
$_POST['sex']
$resultID = mysql_query("SELECT * FROM $_POST['sex']",$conn);
print "<table border = 1><tr><th>id</th>";
print "<th>name_first</th><th>name_last</th>";
print "<th>age</th><th>height</th><th>weight</th>";
while ($row = mysql_fetch_row($resultID))
{
print "<tr>";
foreach ($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
print "</table>";
mysql_close($conn);
?>
AND HERE IS MY FORM in HTML

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="firstconnect.php">
<select name="sex" id="sex">
<option>--</option>
<option value="male" selected>male</option>
<option value="female">female</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>

</body>
</html>

phil2564

6:46 pm on May 17, 2004 (gmt 0)

10+ Year Member



I got it Sorry to waste anyones time I needed to define the variable so what I did is:

$person = $_POST['sex'];
$resultID = mysql_query("SELECT * FROM $person",$conn);

AND IT IS NOW WORKING!

jatar_k

6:49 pm on May 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld phil2564

always satisfying to find it yourself after some initial frustration ;)