query problem

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
User avatar
abzu
Forum Newbie
Posts: 8
Joined: Tue Aug 29, 2006 3:39 pm

query problem

Post by abzu »

I have written this script using dreamweaver and my own novice knowledge of PHP. Between the two I have managed to cobble something together that actually does what I want it to do. It may not be the prettiest thing in the world and I am sure there are easier ways to accomplish what I have done, but it works...almost.

I have tested every step right up to the very end and I can echo the correct values onto the screen up to the last part where I try to push some of those values to my database. The problem seems to be with the one line where I construct my update query. If I remove that one line everything else up to that point works great. With it therre I get nothing, not even an error.

here is the section where I think the problem is. Can someone take a look?

this is at the top of the script and is being used successfully to make connections in other places

Code: Select all

<?php  require_once('Connections/anthill.php');
Then at the end I have what I think is my problem section

Code: Select all

$newsubstring =$newsubstring.$antrec;
$thisid = $row_userset['ID'];
mysql_select_db($database_anthill, $anthill);
$query_subst = sprintf("UPDATE users SET subs='%s' WHERE ID='%s'",
   mysql_real_escape_string($newsubstring),
   mysql_real_escape_string($thisid));
   $subsreplace = mysql_query($query_subst, $anthill) or die(mysql_error());
If there doesn't seem to be an obvious proble here then I can post the whole script to see if it is coming from somewhere earlier (I am hoping not since everthing else is working and I don't want to mess with it any more)

Your help is much appreciated
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You dont acually state what the problem/error is, all you do is say there is one...

But what happens when you print the SQL Query? $query_subst ?

I usually for testing purposes put

Code: Select all

or die('Query failed: ' . mysql_error() . '<br>Query: <br>' . $sql);
To see what my built query looks like.

-NSF
User avatar
abzu
Forum Newbie
Posts: 8
Joined: Tue Aug 29, 2006 3:39 pm

Post by abzu »

Thank you so much. I did what you suggested and it showed me that the variable passing the value to SET was coming up empty. With that knowledge I followed the code and found the problem. Works great now.

Thanks again!
Post Reply