barryflood22 Posted April 10, 2007 Share Posted April 10, 2007 i cant get it to work!!! search.php <HTML> <HEAD></HEAD> <BODY> <A href="../index.php"> <-- Back </A> <FORM NAME="search" METHOD="post" ACTION="searchresults.php"> Enter Last Name: <input name="Array[name]" type="text" id="Array[name]"><BR> <input type="submit" name="Submit" value="Submit"> </FORM> </BODY> </HTML> searchresults.php <HTML> <HEAD></HEAD> <BODY> <p><a href="../index.php">< back</a></p> <p> <?php $Array["name"] =trim ($Array["name"]); $Host="localhost"; $User="root"; $Password=""; $DBName="customer"; $TableName="customer"; $Link = mysql_connect($Host, $User, $Password); $Query="SELECT * from $TableName Where name = $Array[name]"; $Result= mysql_db_query ($DBName, $Query, $Link); while ($Row = mysql_fetch_array ($Result)){ print (" Name:$Row[name], $Row[address] Phone: $Row[postcode]<BR> "); } mysql_close ($Link); ?> </p> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/ Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 try changing this print (" Name:$Row[name], $Row[address] Phone: $Row[postcode]<BR> "); to echo "Name:$Row['name'], $Row['address'] Phone: $Row['postcode']<BR />"; Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226238 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 gave me this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 23 Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226239 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 hmm... how bout this? echo "Name: " . $Row['name'] . ", " . $Row['address'] . "Phone: " . $Row['postcode'] . "<BR />"; Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226243 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 says Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 19 line 19 is while ($Row = mysql_fetch_array ($Result)){ Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226244 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 ($Row = mysql_fetch_array($Result)){ or you can try ($Row = mysql_fetch_assoc($Result)){ Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226246 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 This is the way my code is at the minute <HTML> <HEAD></HEAD> <BODY> <p><a href="../index.php">< back</a></p> <p> <?php $Array["name"] =trim ($Array["name"]); $Host="localhost"; $User="root"; $Password=""; $DBName="customer"; $TableName="customer"; $Link = mysql_connect($Host, $User, $Password); $Query="SELECT * from $TableName Where name = $Array[name]"; $Result= mysql_db_query ($DBName, $Query, $Link); ($Row = mysql_fetch_array($Result)){ echo "Name: " . $Row['name'] . ", " . $Row['address'] . "Phone: " . $Row['postcode'] . "<BR />"; } mysql_close ($Link); ?> </p> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226247 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 you're missing the "if" in "($Row...." if ($Row = mysql_fetch_array($Result)){ Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226249 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 now says Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 19 Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226251 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 what if ou try this... sorry.. i'm still learning mysql... but this is working for me... if ($Row = mysql_fetch_assoc($Result)){ Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226255 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 Parse error: syntax error, unexpected ';' in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 19 i think that maybe it is trying to search the wrong type of field in the sql? e.g. varchar text etc. or does it make a difference? all my fields in the sql are varchar - apart from the unique id - it is an int Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226257 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 if you look at the code in my last post you'll see I removed a ';'... that was my bad... copy pasted from my code =) Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226258 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 nope, getting Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 19 Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226262 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 what's the value of $Array["name"]? Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226266 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 $Query="SELECT * from $TableName Where name = $Array[name]"; $Result= mysql_db_query ($DBName, $Query, $Link) OR DIE(mysql_error()); What is the error printing out? you may want to try this instead: $Query="SELECT * from $TableName Where name = '".$Array['name']."'"; $Result= mysql_db_query ($DBName, $Query, $Link) OR DIE(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226267 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\hoff_godd\Search_Records\searchresults.php on line 19 Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226268 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 i also belive it should be a ' arround the $Array["name"] the $Query $Query="SELECT * from $TableName Where name = '$Array[name]'"; maybe? hehe Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226269 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 well that changed something now, now im not getting any errors but its not actually displaying the results of the search Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226270 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 i learned this earlier today =) add this to the top of your php code error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226271 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 <HTML> <HEAD></HEAD> <BODY> <p><a href="../index.php">< back</a></p> <p> <?php $Array["name"] =trim ($Array["name"]); $Host="localhost"; $User="root"; $Password=""; $DBName="customer"; $TableName="customer"; $Link = mysql_connect($Host, $User, $Password); $Query="SELECT * from $TableName Where name = '".$Array['name']."'"; $Result= mysql_db_query ($DBName, $Query, $Link) or DIE(mysql_error()); while ($Row = mysql_fetch_array($Result)) { echo "Name: " . $Row['name'] . ", " . $Row['address'] . "Phone: " . $Row['postcode'] . "<BR />"; } mysql_close ($Link); ?> </p> </BODY> </HTML> Try that out. Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226273 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 I will now repost the scripts of boh pages SEARCH.PHP <HTML> <HEAD></HEAD> <BODY> <A href="../index.php"> <-- Back </A> <FORM NAME="search" METHOD="post" ACTION="searchresults.php"> Enter Last Name: <input name="Array[name]" type="text" id="Array[name]"><BR> <input type="submit" name="Submit" value="Submit"> </FORM> </BODY> </HTML> SEARCHRESULTS.PHP <HTML> <HEAD></HEAD> <BODY> <p><a href="../index.php">< back</a></p> <p> <?php $Array["name"] =trim ($Array["name"]); $Host="localhost"; $User="root"; $Password=""; $DBName="customer"; $TableName="customer"; $Link = mysql_connect($Host, $User, $Password); $Query="SELECT * from $TableName Where name = '$Array[name]'"; $Result= mysql_db_query ($DBName, $Query, $Link); if ($Row = mysql_fetch_assoc($Result)){ echo "Name: " . $Row['name'] . ", " . $Row['address'] . "Phone: " . $Row['postcode'] . "<BR />"; } mysql_close ($Link); ?> </p> </BODY> </HTML> PHPMYADMIN SCREENSHOT Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226274 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 Good luck man. I posted my suggestions seemingly ignored. Hopefully someone else can help you. Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226279 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 i didnt ignore it frost, sorry for not responding. It didnt make a difference, it done the exact same as what I had done. Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226282 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 any more ideas? Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226292 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 Either way, your name is not matching up. SQL is CasESenSitiVe and if $array['name'] has one case off than the value of name= it will not work. $Query="SELECT * from $TableName Where lower(name) = '".strtolower($Array['name'])."'"; And also make sure that there is a value in $Array['name'] Reasoning I am adding single quotes around the name and not omitting them is there is a check done on name without quotes as an index of an array it looks as that as a constant. Although it does not make a huge difference it is more efficient because the script takes name without single quotes as a constant. If you did define name as a constant this script would be skewed. Always best to do stuff the proper way. Anyhow try the lower out and see what happens. Link to comment https://forums.phpfreaks.com/topic/46498-solved-search-sql-database-records/#findComment-226299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.