jackie11 Posted January 18, 2007 Share Posted January 18, 2007 Hi everyone,Sorry its me again, just got help earlier with displaying my query (code below) and everything works great now apart from the picture which is not displaying, I've tried a number of things but I just can't manage to get it to display any advise? as I'm sure you can tell I am a beginner and just trying to get started with Mysql and php so any help would be great, I'm also looking to put an IF line in that if the surname search does not come up with a match it will bring up an error message[code]<html><head><title>Employee Index</title></head><body> <h1><img src="etc/Logo_pic_2.JPG"></h1><?php$search = "%" . $_POST["search"] . "%"; mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee_index") or die(mysql_error()); $query = "SELECT * FROM employee WHERE Surname LIKE '$search'"; $result = mysql_query ($query)or die(mysql_error()); if ($result) { while ($row = mysql_fetch_array ($result,MYSQL_ASSOC)) { $Employee_ID = $row['Employee_ID']; $Surname = $row['Surname']; $Forename = $row['Forename']; $Job_title = $row['Job_title']; $Office_location = $row['Office_location']; $Telephone = $row['Telephone']; $Email = $row['Email']; $Expertise = $row['Expertise']; $Hobbies = $row['Hobbies']; $DOB = $row['DOB']; $Picture = $row['Picture']; }} echo "<table cellspacing='15'>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo "<th>ID</th><th>Picture</th><th></TD><th>Surname</th><th>Forename</th><th>Job Title</th><th>Office Location</th><th>Telephone</th> <th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo " <td>$Employee_ID</td>\n <td><td><a href='../Database/pics/{$row['Picture']}' border='0'> <img src='../Database/pics/{$row['Picture']}' border='0' width='90' height='100'></a></td>\n <td>$Surname</td>\n <td>$Forename</td>\n <td>$Job_title</td>\n <td>$Office_location</td>\n <td>$Telephone</td>\n <td>$Email</td>\n <td>$Expertise</td>\n <td>$Hobbies</td>\n <td>$DOB</td>\n </tr>\n"; echo "<tr><td colspan='20'><hr></td></tr>\n"; echo "</table>\n"; ?></body></html>[/code]I promise when I have ghot a handle on mysql etc I will try and help someone else!Thanks againJackie Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/ Share on other sites More sharing options...
The Little Guy Posted January 18, 2007 Share Posted January 18, 2007 I would recommend putting everything between the table tags in the while loop.put the opening table tag above the loop, and the closing one below the loop Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163869 Share on other sites More sharing options...
jackie11 Posted January 18, 2007 Author Share Posted January 18, 2007 Hi Thanks for the reply, I tried that no difference!any other suggestions :-\Jackie Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163878 Share on other sites More sharing options...
The Little Guy Posted January 18, 2007 Share Posted January 18, 2007 what are you saving in the picture column? According to you code it should be just the file name... You should also add an alt attribute to your img tag Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163879 Share on other sites More sharing options...
jackie11 Posted January 18, 2007 Author Share Posted January 18, 2007 HiI'm still stuck on this, so any help would be greatly appricatedThanks :-\ Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163923 Share on other sites More sharing options...
boo_lolly Posted January 18, 2007 Share Posted January 18, 2007 [quote author=jackie11 link=topic=123014.msg508009#msg508009 date=1169146665]Hi Thanks for the reply, I tried that no difference!any other suggestions :-\Jackie[/quote]i [i]think[/i] this is what you want to do[code]<html><head><title>Employee Index</title></head><body> <h1><img src="etc/Logo_pic_2.JPG"></h1><?php /*put single quotes here outside your % symbols*/ search = "'%" . $_POST["search"] . "%'"; mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("employee_index") or die(mysql_error()); $query = "SELECT * FROM employee WHERE Surname LIKE ". $search .""; $result = mysql_query ($query)or die(mysql_error()); if(isset($result)){ echo "<table cellspacing=\"15\"\n>". "\t<tr>\n". "\t\t<td colspan=\"20\"><hr></td>\n". "\t</tr>\n". "\t<tr>\n". "\t\t<th>ID</th><th>Picture</th><th></TD><th>Surname</th>\n". "\t\t<th>Forename</th><th>Job Title</th><th>Office Location</th>\n". "\t\t<th>Telephone</th><th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>\n". "\t<tr>\n". "\t\t<td colspan=\"20\"><hr></td>\n". "\t</tr>\n"; while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ echo "\t<tr>\n". "\t\t<td>". $row['Employee_ID'] ."</td>\n". "\t\t<td><a href=\"../Database/pics/". $row['Picture'] ."\" border=\"0\">\n". "\t\t<img src=\"../Database/pics/". $row['Picture'] ."\" border=\"0\" width=\"90\" height=\"100\"></a></td>\n". "\t\t<td>". $row['Surname'] ."</td>\n". "\t\t<td>". $row['Forename'] ."</td>\n". "\t\t<td>". $row['Job_title'] ."</td>\n". "\t\t<td>". $row['Office_location'] ."</td>\n". "\t\t<td>". $row['Telephone'] ."</td>\n". "\t\t<td>". $row['Email'] ."</td>\n". "\t\t<td>". $row['Expertise'] ."</td>\n". "\t\t<td>". $row['Hobbies'] ."</td>\n". "\t\t<td>". $row['DOB'] ."</td>\n". "\t</tr>\n". "\t<tr>". "\t\t<td colspan=\"20\"><hr></td>\n". "</tr>\n"; } echo "</table>"; }?></body></html>[/code]you should always escape strings like[code]echo "Var: ". $var ."";[/code]and always escape double quotes:[code]echo "<font color=\"red\">red font</font>";/*NOT*/echo "<font color='red'>red font</font>";[/code]also, you really don't need to redefine your mysql_fetch_array variables.[code] $Employee_ID = $row['Employee_ID']; $Surname = $row['Surname']; $Forename = $row['Forename']; $Job_title = $row['Job_title']; $Office_location = $row['Office_location']; $Telephone = $row['Telephone']; $Email = $row['Email']; $Expertise = $row['Expertise']; $Hobbies = $row['Hobbies']; $DOB = $row['DOB']; $Picture = $row['Picture']; [/code]this [i]will[/i] get confusing when you're creating pages with a thousand lines of code. it's a good habit to not redefine them. especially if you're just calling them for a single while loop. it's not necessary. plus, if you reach an error, or something isn't showing up (like your image), you can be sure it isn't a misspelling of the redefined variable. if it is a spelling error, it will only be found in one place... you won't have to go back and find where you redefined it, and see if you misspelled it there too. hope this helps. Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163925 Share on other sites More sharing options...
jackie11 Posted January 18, 2007 Author Share Posted January 18, 2007 :)Hi boo_loolyThanks for reply, I have made the changes you have sugested but it brought up an error on line 10 first so I put iline 10 back to the way I had it. I am now getting the message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%finlay%' at line 1not to sure what this means?Jackie Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-163947 Share on other sites More sharing options...
boo_lolly Posted January 18, 2007 Share Posted January 18, 2007 [quote author=jackie11 link=topic=123014.msg508079#msg508079 date=1169151756] :)Hi boo_loolyThanks for reply, I have made the changes you have sugested but it brought up an error on line 10 first so I put iline 10 back to the way I had it. I am now getting the message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%finlay%' at line 1not to sure what this means?Jackie[/quote]can you post line 10, along with a few lines of code before it and a few lines after it?hmmmm, i know what the mysql error means, but i'm not sure why it's returning erroneous. you can diagnose these mysql issues by replacing $search with your own value. like this:[code]<?php /*instead of*/ $query = "SELECT * FROM employee WHERE Surname LIKE ". $search .""; /*type in a known value in your database*/ $query = "SELECT * FROM employee WHERE Surname LIKE valueinyourdatabase";?>[/code]and see what happens. if it still brings up an error, then something else is wrong. if it doesn't bring up an error, then the cause of the error is the $search variable. try that and post what happens. Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-164000 Share on other sites More sharing options...
jackie11 Posted January 18, 2007 Author Share Posted January 18, 2007 HiWhen I changed it to[code]search = "'%" . $_POST["search"] . "%'";[/code]I get the message Parse error: parse error, unexpected '=' in C:\Program Files\xampp\htdocs\test_3\Search.php on line 10So I changed it back When I changed it to: [code]/*type in a known value in your database*/ $query = "SELECT * FROM employee WHERE Surname LIKE Finlay"; [/code]I just get a blank screen with the image at the top of the page, I have pasted in my code again just to clarifyThanks again for looking at this for me![code]<html><head><title>Employee Index</title></head><body> <h1><img src="etc/Logo_pic_2.JPG"></h1><?php $search = "%" . $_POST["search"] . "%"; mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("employee_index") or die(mysql_error()); /*type in a known value in your database*/ $query = "SELECT * FROM employee WHERE Surname LIKE Finlay"; if(isset($result)){ echo "<table cellspacing=\"15\"\n>". "\t<tr>\n". "\t\t<td colspan=\"20\"><hr></td>\n". "\t</tr>\n". "\t<tr>\n". "\t\t<th>ID</th><th>Picture</th><th></TD><th>Surname</th>\n". "\t\t<th>Forename</th><th>Job Title</th><th>Office Location</th>\n". "\t\t<th>Telephone</th><th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>\n". "\t<tr>\n". "\t\t<td colspan=\"20\"><hr></td>\n". "\t</tr>\n"; while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ echo "\t<tr>\n". "\t\t<td>". $row['Employee_ID'] ."</td>\n". "\t\t<td><a href=\"../Database/pics/". $row['Picture'] ."\" border=\"0\">\n". "\t\t<img src=\"../Database/pics/". $row['Picture'] ."\" border=\"0\" width=\"90\" height=\"100\"></a></td>\n". "\t\t<td>". $row['Surname'] ."</td>\n". "\t\t<td>". $row['Forename'] ."</td>\n". "\t\t<td>". $row['Job_title'] ."</td>\n". "\t\t<td>". $row['Office_location'] ."</td>\n". "\t\t<td>". $row['Telephone'] ."</td>\n". "\t\t<td>". $row['Email'] ."</td>\n". "\t\t<td>". $row['Expertise'] ."</td>\n". "\t\t<td>". $row['Hobbies'] ."</td>\n". "\t\t<td>". $row['DOB'] ."</td>\n". "\t</tr>\n". "\t<tr>". "\t\t<td colspan=\"20\"><hr></td>\n". "</tr>\n"; } echo "</table>"; }?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-164005 Share on other sites More sharing options...
boo_lolly Posted January 18, 2007 Share Posted January 18, 2007 change [code]$search = "%" . $_POST["search"] . "%";[/code] to [code]$search = "'%". $_POST['search'] ."%'";[/code]pay close attention to the single quotes on the outsides of the %, and the singlequotes inside ['search']. not double quotes. try that and change this:[code]$query = "SELECT * FROM employee WHERE Surname LIKE Finlay";[/code]to this:[code]$sql = "SELECT * FROM employee WHERE Surname LIKE ". $search ."";$query = mysql_query($sql);[/code]now you can use:[code]while($row = mysql_fetch_array($query, MYSQL_ASSOC)){/*yada yada yada */}[/code]try that. Link to comment https://forums.phpfreaks.com/topic/34764-please-help-i-am-going-to-pull-my-hair-out-part-two/#findComment-164047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.