Simple Problem I'm Sure - Dead Stuck and Deadline SOON

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
babinm
Forum Newbie
Posts: 1
Joined: Wed Jan 28, 2009 12:39 pm

Simple Problem I'm Sure - Dead Stuck and Deadline SOON

Post by babinm »

Here is my code:

if($targets=="")
{
echo "targets is empty. ";
$query="";

$targets="content.php?page_id=".$_SESSION['article_ID'];
echo "<br />target is: ".$targets;

$sql_update="UPDATE items SET target='".$targets."' WHERE item_ID=".$_SESSION['article_ID'];

echo $sql_update;

$query=mysql_query($sql_update)or die(mysql_error());

echo $query;
}


The output i'm being presented with (due to my echo's to find the error) is:

targets is empty
target is: content.php?page_id=14
UPDATE items SET target='content.php?page_id=14' WHERE item_ID=14
1
__________________________
Nothing runs after this. No error is produced. It is not updating my table. I can't understand it. If i run the query manually through database and copy and paste the SQL it runs fine, but through PHP it's not working. HELP...
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Simple Problem I'm Sure - Dead Stuck and Deadline SOON

Post by Reviresco »

Perhaps this might do it:

Code: Select all

 
 
$id = $_SESSION['article_ID'];
 
$sql_update="UPDATE items SET target='$targets' WHERE item_ID='$id' ";
 
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Simple Problem I'm Sure - Dead Stuck and Deadline SOON

Post by califdon »

Since your variables seem to have the values you intend and there are no errors, I would assume the issue is that the update you requested cannot be performed. For example, if no record matches the WHERE clause. You say that the query does work when you run it manually (how? phpMyAdmin?). I think I would substitute a SELECT query temporarily for your UPDATE query, to make sure that there really is a record and that it has all the fields that you name.
Post Reply