This topic is locked

Help Need on Updating a Table

6/14/2009 11:28:03 AM
PHPRunner General questions
author

Hey Guys and Girls,
I have been trying to update a table and I'm having an issue.
I'm adding the following code to Add Page..Before record added.
global $conn;

$strUpdate = "UPDATE participation set credit hours = '".$values["credit hours"]."' where District=".$values["District"];

echo $strUpdate;

db_exec($strUpdate,$conn)
Echo is returning: UPDATE participation set credit hours = '50' where District=Lamar
But I'm getting this php error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hours = '50' where District=Lamar' at line 1.
As always thanks for any help!

500466 6/14/2009

I have used this also with no luck:

global $dal;

$dal->participation->Value["credit hours"] = $values["credit hours"];
$dal->participation->Param["District"] = $values["District"];
$dat->participation->Update();
unset($values["credit hours"]);

return true


I get this: > Error description Undefined variable: dat


Again thanks for any help.

G
garethpDevClub member 6/14/2009

Hi
I use the followoing on after record added event ...

global $conn;

$strUpdate = "update parts set audit=now() where part='".$values["part"]."'";

db_exec($strUpdate,$conn);


This works as required.
Hope this helps

G
garethpDevClub member 6/14/2009

Hi
I did not look close enough, I think the problem is the naming of your field credit hour and the fact is has a space in it.
Instead of...
global $conn;

$strUpdate = "UPDATE participation set credit hours = '".$values["credit hours"]."' where District=".$values["District"];

echo $strUpdate;

db_exec($strUpdate,$conn)
Try...

global $conn;

$strUpdate = "UPDATE participation set `credit hours` = '".$values["credit hours"]."' where District=".$values["District"];

db_exec($strUpdate,$conn)
That should do it I think.
Gareth

500467 6/14/2009

Thank you!! I'm past that issue...but now I have another.
I'm getting this error now: > Unknown column 'Lamar' in 'where clause'


Where Lamar is the value of the district field. It is a field in both tables and a key on both of the tables.
Thank you so much...I'm so close.

G
garethpDevClub member 6/14/2009

Hi
Try this...

global $conn;

$strUpdate = "UPDATE participation set `credit hours` = '".$values["credit hours"]."' where District='".$values["District"]."'";

db_exec($strUpdate,$conn)


I am not an expert by any means but this is worth a try.
Gareth

500468 6/14/2009

Thanks!
I'm not getting any errors but it is not adding or updating any records.
Any Ideas? Thanks for your help...i'm so close!

500469 6/14/2009

Thanks garethp for all the help today.
I took the echo results and did a navicat query. > UPDATE participation set `credit.hours` = '0' where District='Lamar'

It worked.
At this point I don't know what I'm doing wrong.
As always...thank you for any help!

500470 6/14/2009

I got it working. for some reason the > return true;

was not added. I'm sure I deleted it. But it is all working now!!
Thanks again!