Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update db not working - syntax error? 1

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Can anyone see what's wrong with my syntax here:

Code:
$query = 'UPDATE cecil_service SET date='.$date.',odo='.$odo.',work='.$work.',workby='.$workby.',comments='.$comments.' WHERE id='.$record;

When I try to query, it dies.

Thanks.
 
Define "dies". What errors are you getting? The only thing I can see from first glance is that a date value should have quotes around it.

Print out $query to insure that your concatenation is building the string you think it should.

Cut-and-paste that string from your browser to your preferred MySQL management tool to see if it works as you think it should. ______________________________________________________________________
TANSTAAFL!
 
$query = 'UPDATE cecil_service SET date='.$date.',odo='.$odo.',work='.$work.',workby='.$workby.',comments='.$comments.' WHERE id='.$record;

You have a couple things going on. First, you need to put your end ' on record in WHERE id='.$record;

Second Try removing the concatenator from within your ''s you shouldn't need them. Here's a sample of one of my update queries that works with out the .'s

$priquery = "UPDATE prior SET
date = '$pdate',
court = '$pcourt',
county = '$pcounty',
cause = '$pcause',
charge = '$pcharge'
where id = '$id' LIMIT 1";

Hope that helps!

Brian
 
Oh, sorry. By dies I meant when I do "or die"... it dies. I'm not getting any errors... just no data.

I tried putting the ' at the end of the line. Then I get a parse error:

Code:
Parse error: parse error in /home/frozen/cecil/edit_record.php on line 15

lines:

Code:
13  if ($result){
14  echo '<br>';
15
16  echo '<font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Record modified. Thank you.</font>';
17
18 }

Thanks, folks.
 
Fixed!

Output:

Code:
$query = &quot;UPDATE cecil_service SET date='$date',odo='$odo',work='$work',workby='$workby',comments='$comments' WHERE id='$record'&quot;;

Thanks for your help.
 
Fixed!

Code:

Code:
$query = &quot;UPDATE cecil_service SET date='$date',odo='$odo',work='$work',workby='$workby',comments='$comments' WHERE id='$record'&quot;;

Thanks for your help.
 
I disagree with BiJae's recommendation. I see nothing wrong with your concatenation as you originally posted it. That's why you're getting the parse error in lines after it when you add the terminating single quote -- the quote was not needed.

My guess is that your query is well-formed, but that it simply returns zero rows. A resource handle with no rows in it is a valid resource handle.

Print out $query to the browser. Examine it to see that it is producing what you think it should.

If it looks like you think it should, copy-and-paste it into your preferred MySQL manager to test the query. What does it return?

Back in PHP, invoke the function mysql_num_rows() against the resource handle. How many rows are reported by the function? ______________________________________________________________________
TANSTAAFL!
 
Nevermind.

Although it doesn't hurt anything to put single quotes around all variables, they aren't needed for numeric types. ______________________________________________________________________
TANSTAAFL!
 
Yeah, I echoed $query before and got what I expected.

I didn't think anything was wrong with my concatenation. It works now so I'm happy with that.

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top