jackie11 Posted January 17, 2007 Share Posted January 17, 2007 Hi all :-\I am having some difficulty displaying data from my db when I request it based on a search of the field surname, when I run the query I get the message back Query was empty and I'm not sure what I'm doing wrongThe HTML code I am using is:[code]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>form.html</title> <link rel="stylesheet" href="etc/TJConsultants.css"></head><body><br><div id="wrapper"><div id="header"><div style="text-align: center;"><br></div><br></div><div id="centercolumn"><div style="text-align: center;"><br><br><a href="employee_index.php"><img style="border: 0px solid ; width: 428px; height: 42px;" alt="link1" src="etc/employee_index_link.bmp"></a><br><br><br><a href="form.php"><img style="border: 0px solid ; width: 430px; height: 44px;" alt="link2" src="etc/Form_link.bmp"></a><br><br><br><br><br><font style="font-family: Tahoma;" size="+1"><span style="color: rgb(0, 0, 102);">Search Employee Index -Please enter employee Surname</span></font><br><br><form name="form" action="search.php" method="get"> <input name="employee" type="text"> <input name="Submit" value="Search" type="submit"></form></div></div><div id="footer"><p style="text-align: left;"></p></div></div></body></html>[/code]The PHP script is:[code]<?php$user="root";$host="localhost";$password="";$database = "employee_index";mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee_index") or die(mysql_error());$sqlquery = "SELECT * FROM `employee` WHERE Surname LIKE '%$search%'"; $result = mysql_query($query)or die (mysql_error()); $XX = "No Record Found"; while ($row = mysql_fetch_array($query)) { $variable1=$row["row_Employee_ID"]; $variable2=$row["row_Surname"]; $variable2=$row["row_forename"]; $variable2=$row["row_Job_title"]; $variable2=$row["row_Office_location"]; $variable2=$row["row_Telephone"]; $variable2=$row["row_Email"]; $variable2=$row["row_Expertise"]; $variable2=$row["row_Hobbies"]; $variable2=$row["row_DOB"]; $variable2=$row["row_Picture"]; print ("this is for $variable1, and this print the variable2 end so on..."); } if (!$variable1) { print ("$XX"); } //end ?> [/code]Can anyone please help no one seems to know why its not working!!!!Please also bear in mind I am completely new to this so make it simpleMany ThanksJackie Link to comment https://forums.phpfreaks.com/topic/34630-search-help/ Share on other sites More sharing options...
The Little Guy Posted January 17, 2007 Share Posted January 17, 2007 Change:$result = mysql_query($query)To:$result = mysql_query($sqlquery) Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163175 Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 $sqlquery = "SELECT * FROM `employee` WHERE Surname LIKE '%$search%'"; You never define $search? Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163176 Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 Hi Thanks for your repliesThe Little GuyI changed this and I am now getting error messageWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\Database\Search.php on line 15No Record Found To JesiroseSorry I am not sure what you mean how do I go about definning this? sorry I a real newbie I've only been learning Mysql and php for a few daysThanksJackie Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163193 Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 $search is a variable. You never give it a value. It's empty. It is nothing...Before you try to use it, you need to do$search = $_POST['employee']; Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163195 Share on other sites More sharing options...
The Little Guy Posted January 17, 2007 Share Posted January 17, 2007 Now Change this:$row = mysql_fetch_array($query)To this:$row = mysql_fetch_array($result) Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163196 Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 HiI changed the code and its working better now, just got to fix a few other issuesMany Thanks for all your helpJackie Link to comment https://forums.phpfreaks.com/topic/34630-search-help/#findComment-163275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.