Page 1 of 1
Is this an id problem?
Posted: Tue Nov 03, 2009 12:04 pm
by RudyRodney
Is this an id problem or is there something I am missing? I am trying to get it to delete a comment...On this 'delete.php' page, $prof is the user sending the delete request, on the page that I'm trying to delete from, $auth is the sender of the comment.
$prof = new User($_GET['id']);
$query = "UPDATE ProfileComments SET status = 'dead' WHERE id = '".$prof->id."' LIMIT 1"; $request = mysql_query($query,$connection); ?>
should I replace a different variable in the query instead of '$prof->id' ?
I am not getting any errors, and its not deleting the comment from my page or marking it in the db as dead
thanks
Re: Is this an id problem?
Posted: Tue Nov 03, 2009 12:26 pm
by califdon
Two things to check: (1) what data type is the id field? You have single quotes around it, which is correct for a char or varchar data type, but incorrect for an int or other numeric data type. (2) you haven't shown the code for the User class, so it's impossible to know if it's returning a valid $prof->id value. When you have a problem like this, the very first thing to do is echo back the value of the critical fields, in this case $prof->id. Otherwise you're working totally blind.
Re: Is this an id problem?
Posted: Tue Nov 03, 2009 2:11 pm
by RudyRodney
thanks, I'm still having trouble, the only thing in my query I see that has single quotes is the dead. So I'm not sure what your are referring to, and also, when I'm trying to echo the value of '$prof->id"
Im doing it like this: echo '$prof->id" and its resulting: $prof->id naturally, how do I get it to echo the value.
I am new at this thank you for your patience.
Re: Is this an id problem?
Posted: Tue Nov 03, 2009 7:10 pm
by califdon
Here is what you posted as your query, copied and pasted here, within
Code: Select all
... [/php ] tags:[syntax=php]$query = "UPDATE ProfileComments SET status = 'dead' WHERE id = '".$prof->id."' LIMIT 1"; $request = mysql_query($query,$connection); ?>[/syntax]
One of the reasons to use the code tags here in the forum is to make it more readable. As you posted it, it is hard to see a single quote right next to a double quote.
When echoing a variable's value, use double quotes. When you use single quotes, PHP doesn't replace the variable name with its value.
Re: Is this an id problem?
Posted: Wed Nov 04, 2009 11:39 am
by RudyRodney
I understand you would put the var value in double quotes if it looked something like this:
$var = "value";
but my variable is set up like this
$var = $_GET['id'];
does that work? I am trying to get the value of a comment id so I can send it to the db as dead. Would 'post' be better?
I've been trying to get this to work for 3 days now! I am new at this. would more detailed examples of my code help you answer my question better?
THANK you!
Re: Is this an id problem?
Posted: Wed Nov 04, 2009 12:11 pm
by califdon
I am not referring to assigning a value to a variable. I am trying to point out that usually ID values are stored in a table as INTEGERS, not CHARACTERS. If that is true for your table, then your SQL statement is in error, because
you are surrounding the value in your SQL statement in single quotes.
1. In your table ProfileComments, is the
id field an INTEGER or a VARCHAR?
2. If, as I would expect, it is an INTEGER,
you must remove the single quotes surrounding the value for the id field:
Code: Select all
WHERE id = '".$prof->id."'
// should be:
WHERE id = ".$prof->id."
Re: Is this an id problem?
Posted: Wed Nov 04, 2009 12:41 pm
by superdezign
RudyRodney wrote:I've been trying to get this to work for 3 days now! I am new at this. would more detailed examples of my code help you answer my question better?
Yes.
~califdon is referring to your SQL code. That's it. However, MySQL is a forgiving system and, assuming you are using MySQL, it will work regardless of if you send your id value in single quotes or not. It knows what to expect and will parse the value itself.
But, back to the matter at hand. The problem is likely that the value "$prof->id" is not what you are expecting. We can't tell you though, as you have not given *any* insight at all about the structure of your User class.
Echo the $query variable before you run the query and look where the id should be. Is it what you expect it to be? What is it?