I'm trying to create an address book, search the table from a form either OR, AND whatever but why does this script not work?
the error is in the fetch_array function, how can I fix this?
<?PHP
include 'config.php';
include 'opendb.php';
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter First Name:-<INPUT NAME="FirstName" TYPE="TEXT" id="FirstName" size="50" maxlength="50"><br>
Enter SurName:-<INPUT NAME="SurName" TYPE="TEXT" id="SurName" size="50" maxlength="50"><br>
<INPUT TYPE="SUBMIT" NAME="Search" id="SUBMIT" VALUE="Search">
</FORM>
<?PHP
$queryItem = array();
$result = array();
if (isset($_POST['FirstName'])){
$queryItem[] = 'FirstName="'.mysql_escape_string($_POST['FirstName']).'"';
}
if (isset($_POST['SurName'])){
$queryItem[] = 'SurName="'.mysql_escape_string($_POST['SurName']).'"';
}
# now you create your query statement (I assume AND)
$querySQL = "SELECT * FROM Addressbook WHERE ".implode(' AND ', $queryItem) or die(mysql_error());
$result = mysql_query($querySQL);
// get the entry from the result
while($row = mysql_fetch_array($result)) // Print out the contents
{
echo"<br>";
echo $row['FirstName']." ".$row['SurName'];
}
echo("$querySQL");
include 'close.php';
?>
the error is in the fetch_array function, how can I fix this?
<?PHP
include 'config.php';
include 'opendb.php';
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter First Name:-<INPUT NAME="FirstName" TYPE="TEXT" id="FirstName" size="50" maxlength="50"><br>
Enter SurName:-<INPUT NAME="SurName" TYPE="TEXT" id="SurName" size="50" maxlength="50"><br>
<INPUT TYPE="SUBMIT" NAME="Search" id="SUBMIT" VALUE="Search">
</FORM>
<?PHP
$queryItem = array();
$result = array();
if (isset($_POST['FirstName'])){
$queryItem[] = 'FirstName="'.mysql_escape_string($_POST['FirstName']).'"';
}
if (isset($_POST['SurName'])){
$queryItem[] = 'SurName="'.mysql_escape_string($_POST['SurName']).'"';
}
# now you create your query statement (I assume AND)
$querySQL = "SELECT * FROM Addressbook WHERE ".implode(' AND ', $queryItem) or die(mysql_error());
$result = mysql_query($querySQL);
// get the entry from the result
while($row = mysql_fetch_array($result)) // Print out the contents
{
echo"<br>";
echo $row['FirstName']." ".$row['SurName'];
}
echo("$querySQL");
include 'close.php';
?>