buds2000 Posted June 23, 2007 Share Posted June 23, 2007 What woul cause a search string from my form not to be seen by the php script it calls. The same form and script work fine on one table but not another? Here is the html.... <html> <head><title>Searching</title> </head> <body bgcolor=#ffffff> <form method="post" action="writers.php"> Search the Database for<BR> listings by the writers name.<BR> <table border=1 align=left> <tr><td align=right><B>Search for:</B></td><td><input type=text name='writer' style="background:#9BADCA" size=20 maxlength=255></td></tr> <tr><td></td><td align=right><input type=submit></td></tr> </table> </form> </body> </html> Here is the php... <? include("config.php"); if ($srch) // perform search only if a string was entered. { include("opendb.php"); $query = "select * from writers WHERE name = '$writer'"; $result = mysql_query($query) or die('Error, query failed'); if ($result) { echo "Here are the results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>Name</td> <td align=center bgcolor=#00FFFF>Publishing</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $name=$r["name"];// Writers Name $pubtag=$r["pubtag"];// Publisher echo "<tr> <td>$name</td> <td>$pubtag</td></tr>"; } // end while echo "</table>"; } else { echo "problems...."; } } else { echo "Search string is empty. <br> Go back and type a string to search"; } ?> ======================================================================= Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 Change this <? include("config.php"); if ($srch) // perform search only if a string was entered. { include("opendb.php"); $query = "select * from writers WHERE name = '$writer'"; $result = mysql_query($query) or die('Error, query failed'); To this and try: <? include("config.php"); $writer=stripslahes($_POST['writer']); if ($srch) // perform search only if a string was entered. { include("opendb.php"); $query = "select * from writers WHERE name = '$writer'"; $result = mysql_query($query) or die('Error, query failed'); Quote Link to comment Share on other sites More sharing options...
buds2000 Posted June 23, 2007 Author Share Posted June 23, 2007 So i found the error on line 2 and changed ($srch) to ($writer) But still get the error message as if no search string was entered. Quote Link to comment Share on other sites More sharing options...
buds2000 Posted June 23, 2007 Author Share Posted June 23, 2007 Got this error when i tried. Fatal error: Call to undefined function: stripslahes() in /home/brittonj/public_html/catalog/writers.php on line 3 Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 Ok try this bcoz u have error in ur form: <html> <head><title>Searching</title> </head> <body bgcolor=#ffffff> <form method="post" action="writers.php"> Search the Database for<BR> listings by the writers name.<BR> <table border=1 align=left> <tr><td align=right><B>Search for:</B></td><td><input type=text name='writer' style="background:#9BADCA" size=20 maxlength=255></td></tr> <tr><td></td><td align=right><input type=submit name='search' Value='Search'></td></tr> </table> </form> </body> </html> Now in ur php code change to this: <?php include("config.php"); if (isset($_POST['search'])) // perform search only if a string was entered. { include("opendb.php"); $writer=mysql_real_escape_string($_POST['writer']); $query = "select * from writers WHERE name = '$writer'"; $result = mysql_query($query) or die('Error, query failed'); Quote Link to comment 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.