Jump to content

Error in display script


ianco

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.