Jump to content

Some Error ...


techiefreak05

Recommended Posts

I have a script that updates an image"headline" where the image id is .... what it is .. well heres the script:

[code]<h4>Your Uploaded Images</h4>
Here are the images you currently have. You can add a comment or headline to each image. A headline is a sentence that will display when a user views the image.<br>
<br>
<?php
// LINE 60 (see below) $sql = "SELECT * FROM `images` WHERE `userid` = '$_SESSION[id]'";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
$userID=$row['userid'];
$imgID=$row['id'];
$imgPATH=$row['imgPath'];
$headline=$row['headline'];
?>
<center>
<?php
if($_POST['update']){
echo "<b><font color=red>Comment Changed!</font></b><br><br>";
$sql = "UPDATE `images` SET `headline` = '$_POST[picComment]' WHERE `id` = '$_POST[imgID]' LIMIT 1";
$query = mysql_query($sql);
}
?>
<a href="imageView.php?imgID=<?php echo $imgID; ?>&userID=<?php echo $userID; ?>"><img src="<?php echo $imgPATH; ?>" width="250" height="250"></a><br>
<br>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
      <input type="hidden" value="<?php echo $imgID; ?>" name="imgID">
      <br>
<tr><td ><font color=black>Add A Headline:</font></td><td><input type="text" name="picComment" maxlength="100" value="<?php echo $headline; ?>"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="update" value="-Update-"></td></tr>
</table>
</form>
<hr width="55%">
</center>
<?php
}[/code]

everything is fine and dandy .. until i click "Update"  .. i mean it still updates the headline but it gives me this error alseo:
[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\imageUpload.php on line 60[/code]
Link to comment
Share on other sites

first of all, you've identified line 60 incorrectly.  when looking for a line number, always kill wrapping, as this will artificially inflate the current line counter.  line 60 is actually the line that uses mysql_fetch_array(), as you might guess from the error.

when you get an invalid resource error, it's often because your query is failing and has not returned a legitimate resource ID.  easiest way to avoid these in the future is to add an or die() clause to all of your queries to make sure you're notified IMMEDIATELY if a MySQL query is failing:

[code]$query=mysql_query($sql) or die(mysql_error());[/code]

my guess is that you don't actually have anything in $_SESSION[id], or it's being echoed improperly.  add the or die() clause and MySQL should spit out a clear enough error.
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.