0

Need help. I using 3 tables to store booking information: eventinfo, customer and testbook and I try to display records by using combo box to sort by username and eventID.

Problem is the combobox does not load data from database.

My code:

index.php

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4./jquery.min.js"></script>
<script type="text/javascript">
function showUser(str)
{
    if (str=="")
    {
        document.getElementById("txtHint").innerHTML="";
        return;
    }

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
    <option selected="selected">--Select user--</option>
    <?php
include('db.php');
$sql=mysql_query("select username, custNo from testbook");
while($row=mysql_fetch_array($sql))
{
    $id=$row['custNo'];
    $username=$row['username'];
    echo '<option value="'.$id.'">'.$username.'</option>';
 } ?>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>

getuser.php

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', '', '');
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("eventdb", $con);

$sql="SELECT * FROM testbook WHERE custNo = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Booth</th>
<th>Event</th>
<th>Date</th>
<th>Status</th>
<th>Booking ID</th>
</tr>";

while($row = mysql_fetch_array($result))
{
   echo "<tr>";
   echo "<td>" . $row['boothAlias'] . "</td>";
   echo "<td>" . $row['eventID'] . "</td>";
   echo "<td>" . $row['date'] . "</td>";
   echo "<td>" . $row['bstatus'] . "</td>";
   echo "<td>" . $row['bookingID'] . "</td>";
   echo "</tr>";
}
echo "</table>";

mysql_close($con);
?> 

Output:

output

5
  • When you view-source in the browser, do you see any PHP errors? Can you provide a link to a test version of the page? Commented Oct 5, 2011 at 3:51
  • i.imgur.com/F5CVP.jpg no php error, just do not load username from database Commented Oct 5, 2011 at 4:05
  • 1
    Are you certain that the query you make has any records? You should either be getting an error message, or the records should load. Make sure you have error reporting enabled - you can try turning on all errors for this page by putting the following at the top of the page <?php error_reporting(E_ALL); ?>. Errors may not necessarily appear on the screen if they are embedded inside of an HTML tag, so it's best to do view source (CTRL+U) and make sure there are no errors there. Commented Oct 5, 2011 at 4:18
  • I second @mellamokb most likely there is error in the code. Try moving the whole PHP section in index.php to be above the <select> tag so the error will be visible. Commented Oct 5, 2011 at 8:20
  • Can you provide the relevant source code of db.php as well? If you do, make sure you redact any confidential information such as usernames, passwords, server names, database names, etc. Commented Oct 5, 2011 at 14:59

1 Answer 1

1

You need to use $_GET ... You must get the "q" on getuser.php?q="" ...

So,therefore your query is:

$sql = "SELECT * FROM testbook WHERE custNo = '".$_GET['q']."' ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.