Hi everyone,
I was hoping I could get a little help or a push in the right direction, I am new to php, and still learning.
Currently am trying to develop a site that can add, edit, delete and search from my MYSQL database. with the add, edit, delete part I feel pretty confident and should not have a issue. I am just having trouble with the search function. I can manually search my database and display everything within that table, but now I am trying to make it so that I can enter a first name and all the data about that person in the table will display.
currently I have 2 php files (search.php): with a "input type: textbox" and submit button ( so I can type a first name and hit search) and I also have a (searchresult.php): which I want to search for the first name I entered and display the cust_id, first name, last name and email (which are populated in my customers table within my database).
currently I am getting an error of: " warning mysql_fetch_array() expects parameter 1 to be resource, Boolean given" , iv been reading up about the issue but still not sure what to do from here, and was hoping for some help with my code, and maybe a better ( dumbed down ) explanation of the error.
Below ill show my code for both pages:
Below is my "search.php" code: just a simple / basic html.
<!DOCTYPE HTML>
<html>
<head>
<title>Conxbiz - Search Customer</title>
<link rel="stylesheet" type="text/css" href="../conxbiz/css/main.css">
<link href='http://fonts.googleapis.com/css?family=Englebert|Nova+Square' rel='stylesheet' type='text/css'>
</head>
<body>
<form name="form" action="searchresult.php" method="get">
<input name="firstname" type="text">
<input type="submit" name="search" value="Search">
</form>
<?php
?>
</body>
</html>
and below is my "searchresult.php" code:
<!DOCTYPE HTML>
<html>
<head>
<title>Conxbiz - Home</title>
<link rel="stylesheet" type="text/css" href="../conxbiz/css/main.css">
<link href='http://fonts.googleapis.com/css?family=Englebert|Nova+Square' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$firstname = $_GET['firstname'];
echo "<table>";
echo "<tr>";
echo "<th>cust_id</th>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>Email</th>";
echo "</tr>";
mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("conxbiz");
$query = mysql_query("SELECT * FROM customers WHERE firstname '$firstname'");
while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
$cust_id = $row['cust_id'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
echo "<tr>";
echo "<td>" . $row['cust_id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
so to re-cap, my aim is that I want to enter say "adam" into a textbox, hit search and have the php code pull up "cust_id, firstname,lastname and email" and display this to the screen.
I am guessing my coding is totally wrong but hope someone could help me!
thank you for any help / guidance in advance!