Click to See Complete Forum and Search --> : Updating a MySQL record via PHP


nko
01-04-2004, 11:43 PM
I think I'm having a PHP problem. I'm trying to do a simple
update on a single record. This is my code:

$results=mysql_query("update jobs set status=NULL where job_num
\"$_POST[job_num]\"");

$results ends up being "1", indicating success, as far as I can
tell, but the update isn't actually happening. If I put that
query in to a variable, print the variable to a web page, copy &
paste it to the mysql_monitor, and run it, it does exactly as I
want it to. So what am I doing wrong in the PHP portion?

theN
01-05-2004, 07:07 AM
Hi

There's a missing = after "where job_num". Is that a typo?

Shouldn't it be 'where job_num=\"$_POST[something]\"'


regards
akr

nko
01-05-2004, 10:35 AM
I got all excited when I saw that it was missing in my post, but I guess I hit a wrong button when posting. The "=" is there in my script.

Am I mistaken that mysql_query() is the right function to use for UPDATE queries? I know I can just stick an INSERT query in a mysql_query() and it'll run fine, no other actions needing to be taken. Do I have to do anything special for an UPDATE?

ConstantSpeed
01-05-2004, 04:39 PM
$results=mysql_query("update jobs set status=NULL where job_num
\"$_POST[job_num]\"");

If i'm not mistaken, don't you need a semicolon at the end of the mysql command, like this

$results=mysql_query("update jobs set status=NULL where job_num
\"$_POST[job_num]\";");

nko
01-05-2004, 04:48 PM
Technically yes, but doing it through PHP doesn't require that you do. The idea being that if you want to use those same queries on a different DBMS, you wont have to strip out the semicolons.

That said, I tried it :-). Nothing happened. Any other ideas? Thanks for the input thusfar! At the very least, it's exciting to see responses!

nko
01-05-2004, 08:51 PM
Alright, I figured it out. At *one* point, $_POST[job_num] equalled something, but something else was screwing me up. So I thought I'd ruled out that variable as a problem, but later I made it in to a problem. See, copy / paste means you've really gotta think about what you're copying!! I'm just a beginner, these things happen more often than it would to experienced scripters.... I hope.