Hi all you guys,
Love to share an interesting problem with you all. I have a php page called client.html. This page has the function of retrieving records from a mysql database in phpmyadmin.
The input variable used to retrieve a record is called a customer id("id"). Now when the IDs are in my database, it's easily retrieved. But if the IDs are not in my database,i have to send a message to the user that the particular record does not exist. The problem with my code is that my brain just could not figure out why it isn't giving the error message, just "Parse error: parse error in c:\phpdev\www\query1.php on line 31" . Help me look at this code and tell me what's wrong
client.html
<html>
<head>
<title>Client ID</title>
</head>
<body bgcolor="#C0C0C0">
<FORM action="query.php" method="POST">
<p>Client ID/Name: <input type="text" name="id" value=" " size="5 "b maxlength="5"><input type="submit" value="Submit" name="submit"></p>
</FORM>
<p> </p>
<p> </p>
<p> </p>
<table cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr>
<td align="center"><a href="add.html">Add Record</a></td>
</tr>
</table>
<p> </p>
</body>
</html>
query.php
<html>
<?include("dbConnect.php"); ?>
<body>
<?php
// display individual record
if ($id) {
function check_for_rows($id) {
//run query and check for validity
$result = mysql_query("SELECT * FROM customer WHERE CustID =$id",$db);
if(mysql_num_rows($result)!==0){
return $result;
$myrow = mysql_fetch_array($result);
printf("Customer ID: %s\n<br>", $myrow["CustID"]);
printf("Company: %s\n<br>", $myrow["Company"]);
printf("Business Nature: %s\n<br>", $myrow["Business_nature"]);
printf("Contact person: %s\n<br>", $myrow["Contact_person"]);
printf("position: %s\n<br>", $myrow["Position"]);
printf("address: %s\n<br>", $myrow["Address"]);
printf("tel: %s\n<br>", $myrow["Tel"]);
printf("fax: %s\n<br>", $myrow["Fax"]);
printf("handphone: %s\n<br>", $myrow["Handphone"]);
printf("e-mail: %s\n<br>", $myrow["E-mail"]);
printf("website: %s\n<br>", $myrow["Website"]);
printf("birthday: %s\n<br>", $myrow["Birthday"]);
printf("remarks: %s\n<br>", $myrow["Remarks"]);}
}else
{
return false;
}
else{
echo "no record"; }
}
?>
</body>
</html>
dbConnect.php
<?
$db= mysql_connect ("localhost","root") or die ("Tak leh connect localhost");
mysql_select_db ("Client",$db) or die ("tak leh connect DB");
?>
So what's wrong with query.php?Let me clarify again. client.html is supposed to collect the id from the user and checks again the mysql database if the id exists in its customer table or not. If it doesn't, it returns a "no record" found. As simple as that. Not a big problem i think but i worked out a pool of sweat over it. Thanks for any solution to this wonderful problem.