Richard Yates Posted August 7, 2011 Share Posted August 7, 2011 I have a local php test server on my computer and I also upload to a web site server. Everything works fine on both servers except: I wrote a small utility to process mysql query strings. It works fine on the web site server. On the local server, SELECT queries run fine. UPDATE and INSERT give the above error. These exact same queries work fine in the same php script on the web server and they work fine in the phpMyAdmin SQL query utility on the local server. They fail only on the local server with the php script. The relevant script is: if (isset($_GET['searchget'])) { $search = $_GET['searchget']; } mysql_select_db($database_Salem_Harvest, $Salem_Harvest); $search=stripslashes($search); $rsSearch = mysql_query($search, $Salem_Harvest) or die(mysql_error()); $row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH) or die(mysql_error()); The last line is the one that dies. $search echoes out correctly. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted August 7, 2011 Share Posted August 7, 2011 what are the contents of $search coming from the URL? Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 7, 2011 Share Posted August 7, 2011 http://www.phpfreaks.com/forums/index.php?topic=276597.0 Quote Link to comment Share on other sites More sharing options...
Richard Yates Posted August 7, 2011 Author Share Posted August 7, 2011 The echo out right after stripslashes is, for instance: update pickers set fname='Dick' where ID_picker=1 This comes out exactly as it was input in the form. And again, this string works in phpMyAdmin on the local server and in the code I quoted on the web server. Quote Link to comment Share on other sites More sharing options...
Richard Yates Posted August 7, 2011 Author Share Posted August 7, 2011 to Voip03: The link you posted refers to reusing a variable in a while loop. I'm not doing that that I can see. There is no loop until I print out the query results and the error occurs before that. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 7, 2011 Share Posted August 7, 2011 Are you sure that is actually the code that's being executed? The error would tend to indicate that the query failed, therefore it should trigger the first die() clause and echo a MySQL error, not a php error. Quote Link to comment Share on other sites More sharing options...
Richard Yates Posted August 7, 2011 Author Share Posted August 7, 2011 "Are you sure that is actually the code that's being executed? The error would tend to indicate that the query failed, therefore it should trigger the first die() clause and echo a MySQL error, not a php error." thanks for the reply. Yes, I am sure. The same form works when a SELECT string is input. If I insert an 'exit;' after the stripslash line it prints the string correctly and stops. Checking further, i see in the database that the UPDATE query DOES change the data in the record correctly. Something else must happen when I am trying to print the records that are changed. The full code (leaving out some irrelevant html) is: <?php require_once('../Connections/Salem_Harvest.php'); $search = "SELECT * FROM pickers WHERE ID_picker = 1"; if (isset($_GET['searchget'])) { $search = $_GET['searchget']; } mysql_select_db($database_Salem_Harvest, $Salem_Harvest); $search=stripslashes($search); $rsSearch = mysql_query($search, $Salem_Harvest) or die(mysql_error()); $row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH) or die(mysql_error()); $keys = array_keys ($row_rsSearch); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SQL</title> </head> <body class="SH"> <div id="container"> <div id="mainContent"> <h2><strong>SQL search utility</strong></h2> <form id="search" name="search" method="get" action="SQL2.php"> Type SQL String and press 'Enter' <input name="searchget" type="text" id="searchget" value="<?php echo $search ?>" size="300" maxlength="300" /> </form> <p> </p> <table width="1220" border="1" cellpadding="2" cellspacing="2" id="rsearchresults"> <tr><?php for($i=1;$i<count($keys);$i=$i+2) { ?> <th><?php echo $keys[$i];?></td> <?php } ?> </th> <?php do { ?> <tr><?php for($i=0;$i<(count($row_rsSearch)/2);$i++) { ?> <td><?php echo $row_rsSearch[$i];?></td> <?php } ?> </tr> <?php } while ($row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH)); ?> </table> </div> <br class="clearfloat" /> </div> </body> </html> <?php mysql_free_result($rsSearch); ?> MOD EDIT: code tags added. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 7, 2011 Share Posted August 7, 2011 My feeling is that the error is related to the second call to mysql_fetch_array() in the code. Which line number does the error match up to? Quote Link to comment Share on other sites More sharing options...
Richard Yates Posted August 7, 2011 Author Share Posted August 7, 2011 line 7: $row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 7, 2011 Share Posted August 7, 2011 Hold on a second. You said that "UPDATE and INSERT queries give the above error", didn't you? mysql_fetch_* functions aren't used with UPDATE and INSERT queries; only SELECT queries. Quote Link to comment Share on other sites More sharing options...
Richard Yates Posted August 7, 2011 Author Share Posted August 7, 2011 Yikes! You are right. I don't know how I did that. I originally planned to parse the query to branch for UPDATE and then forgot that whole half of the job when I started testing the SELECT part. Thanks and sorry for the bother. <sheepish emoticon> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 Hold on a second. You said that "UPDATE and INSERT queries give the above error", didn't you? mysql_fetch_* functions aren't used with UPDATE and INSERT queries; only SELECT queries. good catch.. 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.