ianco Posted May 16, 2010 Share Posted May 16, 2010 Hi all I'm getting the error mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/zxq.net/s/c/i/scienceproof/htdocs/new/incs/XMashEdit2.php on line 12 I want a form where the previous info shows up in the text area so that it can be edited and saved but I cant't see where i'm going wrong :'( mysql_select_db("scienceproof_zxq_sciencetest", $con); $options = $_POST["thing"]; $result="SELECT XMashTitle, XMashContent FROM XMash WHERE XMashTitle = $options"; while ($row=mysql_fetch_array($result)) { $content = $row['XMashContent']; } mysql_close($con); ?> <p>Editing <b><?=$options?></b></p> <form action="XMashEdit.php" method="post"> <textarea rows="10" cols="30" name="content"><?=$content?></textarea> <input type="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2010 Share Posted May 16, 2010 Your code does not have a mysql_query() statement in it to execute the query. Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059093 Share on other sites More sharing options...
ianco Posted May 16, 2010 Author Share Posted May 16, 2010 Even with it, it doesnt work Updated script: mysql_select_db("scienceproof_zxq_sciencetest", $con); $options = $_POST["thing"]; $sql="SELECT XMashContent FROM XMash WHERE XMashTitle = $options"; $result=mysql_query($sql); while ($row=mysql_fetch_array($result)) { $content = $row['XMashContent']; } mysql_close($con); ?> <p>Editing <b><?=$options?></b></p> <form action="XMashEdit.php" method="post"> <textarea rows="10" cols="100" name="content"><?=$content?></textarea> <input type="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059095 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2010 Share Posted May 16, 2010 If you are still getting the same error, it means that you query is failing due to an error. For debugging purposes, echo mysql_error(); on the next line after the line with the msyql_query() statement to find out why the query is failing. Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059102 Share on other sites More sharing options...
ianco Posted May 16, 2010 Author Share Posted May 16, 2010 That outputs 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 '!' at line 1 doesn't scream anything obvious to me Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059107 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2010 Share Posted May 16, 2010 I'm going to guess that XMashTitle is a character/string data type? If so, $options needs to be enclosed in single-quotes inside th query to make it a string. You also need to use mysql_real_escape_string() on $options before you put it into the query to prevent sql injection and prevent any other special characters in it (such as a quote) from breaking the sql syntax. Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059109 Share on other sites More sharing options...
ianco Posted May 16, 2010 Author Share Posted May 16, 2010 Bingo! Thanks for all the help Link to comment https://forums.phpfreaks.com/topic/201944-error-in-display-script/#findComment-1059110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.