Jump to content

Pulling My Hair Out! Spot the error?


tonyawelch

Recommended Posts

I know this has GOT to be a stupid syntax or spelling error somewhere, but I've been looking at the code too long and just can't see it, apparently.  Posting with all of my debugging lines.

 

    * your MySQL server version:  5.0.7.5

 

    * the raw MySQL statement in question [in a CODE block, and without any PHP variables]

 

				
$update_news_query = "UPDATE news SET newscat_id='$_POST[newscat_id]', news_headline 
='$_POST[news_headline]', news_content='$_POST[news_content]', 
new_rsimage='$new_rsimage', new_tnimage='$new_tnimage' WHERE news_id='$_POST[news_id]'";

echo $update_news_query;  //query works in phpMyAdmin

$update_news=mysql_query($update_news_query) or die(mysql_error()); //No Error returned

$rows = mysql_num_rows($update_news); //returns an invalid resource error
echo $rows; 

if ($update_news) //Returns true
{
echo "News has been updated";
}else
{
echo "System Error:  News could not be updated.  The site administrator has been notified of this error.";
}

 

    * any errors that MySQL returns to the client [from mysql_error()]

 

No errors are returned, but the row does not update when executed from the browser.

 

    * the table structure & column indexes of the relevant tables [via SHOW CREATE TABLE is preferred]

 

CREATE TABLE IF NOT EXISTS `news` (

  `news_id` int(10) unsigned NOT NULL auto_increment,

  `user_id` int(10) unsigned NOT NULL,

  `newscat_id` int(10) unsigned NOT NULL,

  `news_headline` varchar(80) NOT NULL,

  `news_content` mediumtext NOT NULL,

  `new_rsimage` varchar(80) default NULL,

  `new_tnimage` varchar(80) default NULL,

  `submitted` datetime NOT NULL,

  `approved` char(1) NOT NULL default 'N',

  PRIMARY KEY  (`news_id`)

)

 

 

    * a clear and concise description of what you want this statement to achieve

 

I'm just trying to update the damn table!  Done it a million times elsewhere; Think maybe I've been staring at code too long to see some silly error.

 

    * a description of what it's currently doing that's not to your liking

 

When I print out the query and test it in phpMyAdmin, it works fine, so I know the error is not in the query statement.  When I run the query from the browser, the "success" message (News has been updated.) returns, but the row is not updated.  Checking for rows affected returns a "not valid resource" error.

 

    * a brief listing of the types of things you've attempted so far

 

Stared at the code.  Stared at the code longer.  Retyped the code several times. Checked spelling.  Took a nap thinking I was brain-tired.  etc. etc.

Link to comment
Share on other sites

Well, you should have quotes around variable keys as they are strings, you should escape the data also, since it's being run in a query.

 

mysql_num_rows is for select query, you probably want mysql_affected_rows.

 

And probably becase $_POST['news_id'] doesn't exist. Try echoing out all your post data to see if it's what you expect.

Link to comment
Share on other sites

Well, you should have quotes around variable keys as they are strings, you should escape the data also, since it's being run in a query.

 

mysql_num_rows is for select query, you probably want mysql_affected_rows.

 

And probably becase $_POST['news_id'] doesn't exist. Try echoing out all your post data to see if it's what you expect.

 

Well, I put quotes around the strings and there was no change.  The mysql_affected_rows returns the same error.  $_POST['news_id'] does exist - as I said, I printed out the query and ran it in phpMyAdmin and it worked fine. 

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.