Im getting this error:
Parse error: syntax error, unexpected $end in /hsphere/local/home/blah/blahblah.com/home/phonenumber.php on line 188. Problem is line 188 is </html> only. Also, I'm having problem making this code to work, it doesnt display the tables that I want

<?php
$selection = $_POST['person'];
$conn = mysql_connect("mrrrr.com","yyyyy","yyfffsd");


mysql_select_db("hhhh_ggg", $conn);

// For Students
if ($selection == 'student') {

$sql="SELECT student.first_name AS first,
             student.last_name AS last,
             student.phone AS phonenum
      FROM student
      ORDER BY last, first;";

$result = mysql_query($sql, $conn)
          or die(mysql_error());

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<title>Student Phone Book</title>';
echo '</head>';
echo '<body>';
echo '<h2>Student Phone Book</h2>';
echo '<table width="100%" border="2">';
   echo '<tr>';
      echo '<th>First Name</th>';
      echo '<th>Last Name</th>';
      echo '<th>Phone</th>';
   echo '</tr>';

   while ($row = mysql_fetch_array($result)) {
      echo "<tr>";
         echo "<td>";
         echo  $row["first"];
         echo "</td>";
         echo "<td>";
         echo  $row["last"];
         echo "</td>";
         echo "<td>";
         echo  $row["phonenum"];
         echo "</td>";
      echo "</tr>";

   }
echo '</table>';
mysql_close($conn);

//faculty
if ($selection == 'faculty') {

$sql="SELECT faculty.first_name AS first,
             faculty.last_name AS last,
             faculty.phone AS phonenum
      FROM faculty
      ORDER BY last, first;";

$result = mysql_query($sql, $conn)
          or die(mysql_error());

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<title>Faculty Phone Book</title>';
echo '</head>';
echo '<body>';
echo '<h2>Faculty Phone Numbers</h2>';
echo '<table width="100%" border="2">';
   echo '<tr>';
      echo '<th>First Name</th>';
      echo '<th>Last Name</th>';
      echo '<th>Phone</th>';
   echo '</tr>';

   while ($row = mysql_fetch_array($result)) {
      echo "<tr>";
         echo "<td>";
         echo  $row["first"];
         echo "</td>";
         echo "<td>";
         echo  $row["last"];
         echo "</td>";
         echo "<td>";
         echo  $row["phonenum"];
         echo "</td>";
      echo "</tr>";

   }
echo '</table>';
mysql_close($conn);

//department

if ($selection == 'department') {

$sql="SELECT department.first_name AS first,
             department.last_name AS last,
             department.phone AS phonenum
      FROM department
      ORDER BY last, first;";

$result = mysql_query($sql, $conn)
          or die(mysql_error());

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<title>Student Phone Book</title>';
echo '</head>';
echo '<body>';
echo '<h2>Department Phone Numbers</h2>';
echo '<table width="100%" border="2">';
   echo '<tr>';
      echo '<th>First Name</th>';
      echo '<th>Last Name</th>';
      echo '<th>Phone</th>';
   echo '</tr>';

   while ($row = mysql_fetch_array($result)) {
      echo "<tr>";
         echo "<td>";
         echo  $row["first"];
         echo "</td>";
         echo "<td>";
         echo  $row["last"];
         echo "</td>";
         echo "<td>";
         echo  $row["phonenum"];
         echo "</td>";
      echo "</tr>";

   }
echo '</table>';
mysql_close($conn);

//student

if ($selection == 'studentid') {

$sql="SELECT student.first_name AS first,
             student.last_name AS last,
             student.phone AS phonenum
      FROM student
      ORDER BY last, first;";

$result = mysql_query($sql, $conn)
          or die(mysql_error());

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<title>Student Phone Book</title>';
echo '</head>';
echo '<body>';
echo '<h2>Student Phone Book</h2>';
echo '<table width="100%" border="2">';
   echo '<tr>';
      echo '<th>First Name</th>';
      echo '<th>Last Name</th>';
      echo '<th>Phone</th>';
   echo '</tr>';

   while ($row = mysql_fetch_array($result)) {
      echo "<tr>";
         echo "<td>";
         echo  $row["first"];
         echo "</td>";
         echo "<td>";
         echo  $row["last"];
         echo "</td>";
         echo "<td>";
         echo  $row["phonenum"];
         echo "</td>";
      echo "</tr>";
   }
echo '</table>';
mysql_close($conn);
}
?>
<a href="test2.htm">Back to previous page</a>
</body>
</html>

Recommended Answers

All 8 Replies

I have a suggestion for you. Never post your username and password in a forum. :) You can still edit your post and replace username and password with null or * or whatever.
And also, fix your [code] tags .

And, the solution for your problem is, none of your code blocks are closed. if($selection == 'student') { is opened, but you have forgotten to close it after mysql_close($conn);

Thanks, sorry about that all fixed up

Oh gosh I just forgot to end it, thank you.

:) n/p ! Good luck.

how will you do this, if you click on th radio button and press submit it will also get the input value in text form and find it in the database
Note: same php code in my first post Line 143-184

<input type="radio" name="person" value="id" />A student. Type Student ID here: 
<input type="text"  name="studentid" value="" size="10" maxlength="8">

When you click submit, all the form elements (radio, checkbox, select, textbox, etc) inside a form will be submitted to the script mentioned in the action of the form (if no action is specified, it will submit to the same script).

<?php
if(isset($_POST['submit'])) {
   print "<pre>";
   print_r($_POST);
   print "</pre>";
}
<html>
<body>
<form method='post'>
<input type='radio' name='person' value='1' /> Person 1 <br />
<input type='radio' name='person' value='2' /> Person 2 <br />
Name: <input type='text' name='name' /> <br />
<input type='submit' name='submit' value='submit' />
</form>
</body>
</html>

In the above example, you will see all the posted form elements. Do whatever you want with it! I don't understand what you mean by "find it in the database". If you want to search a table, then use it in the query.

$value = $_POST['textboxname'];
$query = "select * from table where user = '$value'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0 ) {
echo "Found!";
} else {
 echo "Not found!";
}

something like that ?

P.S. Its 1 am and I am going to hit the sack. Cheers!

ok good night and thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.