toney Posted March 7, 2012 Share Posted March 7, 2012 I am trying to display data from a database from a form entry here is the php <?php include('dbconnect.php'); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM child_info"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"file_number"); $field2-name=mysql_result($result,$i,"first_name"); $field3-name=mysql_result($result,$i,"middle_name"); $field4-name=mysql_result($result,$i,"last_name"); $field5-name=mysql_result($result,$i,"birthdate"); $field6-name=mysql_result($result,$i,"gender"); $field7-name=mysql_result($result,$i,"features"); $field8-name=mysql_result($result,$i,"diagnosis"); $field9-name=mysql_result($result,$i,"description"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> here is the form I am using <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td> Search by Name: </td> <td> First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br /> Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" /> </td> </tr> <tr> <td width="208"> Choose Male or Female: </td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td> Choose age range: </td> <td> <select name="first_age" id="first_age"> <option value="00">From</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> <select name="second_age" id="second_age"> <option value="00">To</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div></td> </tr> </table> </form> first problem is getting the form to use the php second problem is when i try to use the php alone is I get this error Parse error: syntax error, unexpected '=' in /home/fathersh/public_html/selectdata.php on line 17 17 is highlighted above in the php Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/ Share on other sites More sharing options...
Psycho Posted March 7, 2012 Share Posted March 7, 2012 Hmm, that's a pretty rough implementation on working with queries. But, the crux of your problem is that variables cannot have dashes in the name Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324920 Share on other sites More sharing options...
Psycho Posted March 7, 2012 Share Posted March 7, 2012 include('dbconnect.php'); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT file_number, first_name, middle_name, last_name, birthdate FROM child_info"; $result = mysql_query($query); mysql_close(); if(!$result) { echo "There was a problem getting the data"; } elseif(!$result) { echo "There were no results"; } else ( echo "<b><center>Database Output</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n"; echo "{$row['middle_name']}-name<br>\n"; echo "{$row['last_name']}-name<br>\n"; echo "{$row['birthdate']}-name<hr><br>\n"; } } Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324927 Share on other sites More sharing options...
Psycho Posted March 7, 2012 Share Posted March 7, 2012 Cleaned up form <?php $max_age = 18; $ageOptions = "<option value='00'>From</option>\n"; for($age=1; $age<=$max_age; $age++) { $ageOptions .= "<option value='{$age}'>{$age}</option>\n"; } ?> <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td>Search by Name:</td> <td> First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br /> Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" /> </td> </tr> <tr> <td width="208">Choose Male or Female:</td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td>Choose age range:</td> <td> <select name="first_age" id="first_age"> <?php echo $ageOptions; ?> </select> <select name="second_age" id="second_age"> <?php echo $ageOptions; ?> </select> </td> </tr> <tr> <td></td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324932 Share on other sites More sharing options...
toney Posted March 7, 2012 Author Share Posted March 7, 2012 <?php $con = mysql_connect("localhost","fathersh_search","blanked out"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fathersh_childsearch", $con); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT file_number, first_name, middle_name, last_name, birthdate FROM child_info"; $result = mysql_query($query); mysql_close(); if(!$result) { echo "There was a problem getting the data"; } elseif(!$result) { echo "There were no results"; } else ( "<b><center>Database Output</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n"; echo "{$row['middle_name']}-name<br>\n"; echo "{$row['last_name']}-name<br>\n"; echo "{$row['birthdate']}-name<hr><br>\n"; } } ?> this is the new code but now giving me new error : Parse error: syntax error, unexpected ';' in /home/fathersh/public_html/selectdata.php on line 27 in bold Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324944 Share on other sites More sharing options...
smerny Posted March 7, 2012 Share Posted March 7, 2012 27: echo "<b><center>Database Output</center></b><br><br>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324945 Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2012 Share Posted March 7, 2012 Look at it again. Do you notice something missing on that line? Maybe at the very beginning of it? Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324947 Share on other sites More sharing options...
Genesis730 Posted March 7, 2012 Share Posted March 7, 2012 also the line before (line 26) has a ( and needs a { Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324950 Share on other sites More sharing options...
toney Posted March 7, 2012 Author Share Posted March 7, 2012 ok i fixed the parse error there was a ) instead of a } but now it says I cant select the database I know the database details are correct <?php $con = mysql_connect("localhost","fathersh_search",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fathersh_childsearch", $con); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT file_number, first_name, middle_name, last_name, birthdate FROM child_info"; $result = mysql_query($query); if(!$result) { echo "There was a problem getting the data"; } else if(!$result) { echo "There were no results"; } else { echo "<b><center>Database Output</center></b><br><br>\n";"<b><center>Database Output</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n"; echo "{$row['middle_name']}-name<br>\n"; echo "{$row['last_name']}-name<br>\n"; echo "{$row['birthdate']}-name<hr><br>\n"; } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324951 Share on other sites More sharing options...
toney Posted March 7, 2012 Author Share Posted March 7, 2012 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fathersh/public_html/selectdata.php on line 29 in bold <?php $con = mysql_connect("localhost","fathersh_search","f33321rh"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fathersh_childsearch", $con); @mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())" $query = "SELECT file_number, first_name, middle_name, last_name, birthdate FROM child_info"; $result = mysql_query($query); if(!$result) { echo "There was a problem getting the data"; } else if(!$result) { echo "There were no results"; } else { echo "<b><center>Database Output</center></b><br><br>\n";"<b><center>Database Output</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<b>{$row['file_number']}-name{$row['first_name']}-name2</b><br>\n"; echo "{$row['middle_name']}-name<br>\n"; echo "{$row['last_name']}-name<br>\n"; echo "{$row['birthdate']}-name<hr><br>\n"; } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324957 Share on other sites More sharing options...
smerny Posted March 7, 2012 Share Posted March 7, 2012 echo "<b><center>Database Output</center></b><br><br>\n";"<b><center>Database Output</center></b><br><br>\n"; look at that line Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324960 Share on other sites More sharing options...
mikosiko Posted March 7, 2012 Share Posted March 7, 2012 this are 2 lines in your posted code: mysql_select_db("fathersh_childsearch", $con); @mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())" seems ok to you? ... mysql_select_db() twice? and the second with more than evident errors? Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324961 Share on other sites More sharing options...
smerny Posted March 7, 2012 Share Posted March 7, 2012 this are 2 lines in your posted code: mysql_select_db("fathersh_childsearch", $con); @mysql_select_db($database) 'or die ("Unable to select database: " . mysql_error())" seems ok to you? ... mysql_select_db() twice? and the second with more than evident errors? toney what are you using to edit your php? even a simple editor that color codes would give you a better idea of where you are messing up quotes. Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324964 Share on other sites More sharing options...
toney Posted March 7, 2012 Author Share Posted March 7, 2012 Dreamweaver is what I am using Quote Link to comment https://forums.phpfreaks.com/topic/258476-displaying-data-from-database/#findComment-1324966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.