sabo86 Posted September 13, 2008 Share Posted September 13, 2008 hello there.. am new to php and mysql stuffs... and really need your help.. I've taken this code from a tutorial, and it didn't work for my database... the html code is: <html> <head> <title> Fleifel's Browser</title> </head> <body> <h1> Fleifel's Browser</h1> <form action="results.php" method="post"> Browse the Category you want: <br> <select name="searchtype"> <option value"Accessories">Accessories <option value="European Office Furniture"> European Office Furniture <option value="Local Office Furniture"> Local Office Furniture <option value="School and University Furniture"> School and University Furniture <option value="Seatings"> Seatings </select> <br> Enter Search Term:<br> <input name="searchterm" type=text /> <br /> <input type="submit" value="Search" /> </form> </body> </html> and the php code is <html> <head> <title>Fleifel</title> </head> <body> <h1>Fleifel</h1> <? if (!$searchtype || !$searchterm) { echo "You have not entered search details. Please go back and try again."; exit; } $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); // // You will need to change the $database variable value to be your grace // user ID // $database = "fleifel"; @ $db = mysql_connect("localhost", $database); if (!$db) { echo "Error: Could not connect to database server. Please try again later."; exit; } @ $ok = mysql_select_db($database); if (!$ok) { echo "Error: Could not select database: $database. Please try again later."; exit; } $query = "select * from item where ".$searchtype." like '%".$searchterm."%'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo "<p><strong>".($i+1).".Model:"; echo htmlspecialchars(stripslashes($row["Model"])); echo "</strong><br> Description:"; echo htmlspecialchars (stripslashes($row["Description"])); } ?> </body> </html> After I perform the search, I get the following result: Fleifel Number of books found: ".$num_results." "; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo " ".($i+1).".Model:"; echo htmlspecialchars(stripslashes($row["Model"])); echo " Description:"; echo htmlspecialchars (stripslashes($row["Description"])); } ?> Suggestions please Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/ Share on other sites More sharing options...
seany123 Posted September 13, 2008 Share Posted September 13, 2008 Do you have a database set up? is this info correct? $db = mysql_connect("localhost", $database); Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640698 Share on other sites More sharing options...
xoligy Posted September 13, 2008 Share Posted September 13, 2008 helps if people post errors and put code in [ code ] [ /code ] tags, also where are your db username and password setup? as said do you have a db even setup with the right tables? Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640706 Share on other sites More sharing options...
Mchl Posted September 13, 2008 Share Posted September 13, 2008 To me it look like some unpaired quotes... But the code doesn't have any... Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640710 Share on other sites More sharing options...
unrelenting Posted September 13, 2008 Share Posted September 13, 2008 Without reading the entire code, there are no </option> tags Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640721 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 yes, i've setup the database and the user name is correct and there is no password! Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640728 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 The script you have has two issues: - It uses short tags (<?) not all PHP configurations have short_open_tag enabled. You should always use full PHP tags (<?php ?>) - It replies on register_globals. Register_globals is now depreciated and is disabled by default. It is soon to removed completely as of PHP6 Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640729 Share on other sites More sharing options...
448191 Posted September 13, 2008 Share Posted September 13, 2008 Wildteen is too courteous. I already locked this because of the title. Read the forum rules! # DON'T Describe your question or problem as urgent, super important, must have by tommorrow etc... The people who are answering your questions are contributing their time and expertise for free. If you have an urgent problem and need priority help, consider advertising in the Freelancing forum. Unlocked, but just as easily locked next time. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640733 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 Wildteen is too courteous. I already locked this because of the title. Read the forum rules! # DON'T Describe your question or problem as urgent, super important, must have by tommorrow etc... The people who are answering your questions are contributing their time and expertise for free. If you have an urgent problem and need priority help, consider advertising in the Freelancing forum. Unlocked, but just as easily locked next time. Was this locked? I didn't realise it had been. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640734 Share on other sites More sharing options...
448191 Posted September 13, 2008 Share Posted September 13, 2008 I locked it just before you posted. So possibly you didn't get the warning. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640735 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 Oh thanks for that remark.. I think we have something new.. the result.php page is showing the following: Notice: Undefined variable: searchtype in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 9 You have not entered search details. Please go back and try again. & line 9 in my code is: if (!$searchtype || !$searchterm) { echo "You have not entered search details. Please go back and try again."; exit; } !!! Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640737 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 This is the problem you face when register_globals is disabled. Looking at your code $searchtype and $searchterm should be $_POST['searchtype'] and $_POST['searchterm'] Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640741 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 thx.. but can you tell me exactly where to add it in my code? or where to replace it? I appreciate.. btw, I am sorry for writing it Urgent as a title, am new here and didn't know the rules.. thanks for letting me know. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640752 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 You just replace the variables I mentioned above with the new ones. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640753 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 42 Number of books found: Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640755 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 That's how i edited it: if (!$_POST['searchtype'] || !$_POST['searchterm']) { echo "You have not entered search details. Please go back and try again."; exit; } $_POST['searchterm'] = addslashes( $_POST['searchterm']); $_POST['searchterm'] = addslashes($_POST['searchterm']); Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640757 Share on other sites More sharing options...
448191 Posted September 13, 2008 Share Posted September 13, 2008 What makes you think $searchtype and $searchterm are suddenly defined when you use them in addslashes()? EDIT: nice save Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640759 Share on other sites More sharing options...
448191 Posted September 13, 2008 Share Posted September 13, 2008 Btw, you should've gotten notices. Be sure to set error reporting to at least E_ALL: "error_reporting(E_ALL);". At the top of the script loaded by the server. Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640764 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 what does this code do? The error now is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 43 Number of records found: Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640767 Share on other sites More sharing options...
448191 Posted September 13, 2008 Share Posted September 13, 2008 This is pointless. I respect that you're a noobie, but really. There has to be system to what you do. I suggest you read this tutorial first. It's about debugging so reading it should help you solve this problem. http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640768 Share on other sites More sharing options...
sabo86 Posted September 13, 2008 Author Share Posted September 13, 2008 thx i think i am getting some results Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640774 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 Now i am getting results, but not as I really want.. I edited the $query variable to: $query = "select * from items where Category = '%".$_POST['searchtype']."%'"; I am getting 0 results Is there a way that I want to get results selected from the drop menu? Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640806 Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 % is for comparison with LIKE. You don't use LIKE, lose the %. How on earth did you get that from the tut? Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640807 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 I am just new in programming.. execuse me Now i modified it to: $query = "select * from items where Category = '.$_POST['searchtype'].'"; I got this error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640811 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 help me out of this plz Quote Link to comment https://forums.phpfreaks.com/topic/124099-not-that-urgent-offer-your-free-help-at-any-time-you-wish/#findComment-640817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.