Forum Moderators: coopster

Message Too Old, No Replies

UPDATE querry dieing every time

maybe because it's nested in an IF and SWITCH?

         

Target

12:00 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



I've ripped through just about every other problem with my site but this one. This sucker is bugging me because I CAN'T find any syntax errors.

Anyway, I'm getting "Couldn't update entry." Every time I try to get it to update, the server works, all insert and select querries work in the same databases and tables. It's just UPDATE that seems stuck.


switch ( $pdc_area )
{
case "members_only3":
if ( $members_only_option == 'insert_profile_update' )
{
while(list($k,$v)=each($_GET)){
$$k=$v;}
if (ereg(".", $id_number) == 1) {
$verify = "OK";
}
else {
print "<BR><BR><BR>One or more of the required fields was not filled in. <br>Hit your back button to review your entry.";
$verify = "bad"; {
die;
}}
// Bunch of other ereg tests to make sure I have all my variables and they are all non-null values.

mysql_query ("UPDATE 'pdc_members' SET 'First_Name'='$first_name', 'Last_Name'='$last_name', 'Game_Handle'='$game_handle', 'Email'='$email', 'Website'='$website', 'BIO'='$bio', 'Password'='$pass', 'Title'='$title' WHERE 'ID_Number'=='$id_number' LIMIT 1") or die ("Couldn't update entry.");

print "<center><br><br>Thanks. The entry for ";
print "$first_name &QUOT$game_handle&QUOT $last_name";
print " has been updated.<center>";

}
break;

Was think mabye it's because the UPDATE is nested inside an if which is in turn, nested inside a case. If so, how come select's and inserts DO work there? At a loss. Help if you can.

Thanks,
Matt

Birdman

12:50 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome, Target!

You don't have to enclose the table and field names with quotes, unless that name has a space in it or it is a reserved MySQL word(desc, etc). I doubt it's causing any problems though.

What I think is causing the problem is the double-equals in the where section of the query.

mysql_query ("UPDATE pdc_members SET First_Name='$first_name', Last_Name='$last_name', Game_Handle='$game_handle', Email='$email', Website='$website', BIO='$bio', Password='$pass', Title='$title' WHERE ID_Number='$id_number' LIMIT 1") or die ("Couldn't update entry because: ". mysql_error());

Try that out. Notice I added the mysql_error() function. It will help you debug.

print '$first_name "$game_handle" $last_name';

To avoid using &QUOT, enclose the string with single quotes and then you may use doubles within.

Regards,
Birdman

Sanenet

12:52 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why do you have the column names inside '? (ie SET 'First_Name'='$first_name').

Dont' know about MySQL, but under MSSQL server that generates an error. Ditto for the double equals sign in the where clause ( WHERE 'ID_Number'=='$id_number' ).

Target

1:26 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



Ok, I guess I'm confused about when double == signs are needed. Took one out (and the 's) symbols and she's all patched up and working now.

I used the ' symbols in front and back of the column names because I copied the UPDATE code from mysqladmin when I was doing an update in that. It "appears" to use the ' symbols in its sql code. No?

Much obliged! Site is nearly 100% operational now. I'm so happy.

[edited by: jatar_k at 5:03 pm (utc) on Oct. 28, 2004]
[edit reason] removed url [/edit]

Target

1:47 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



Ok, I looked up the syntax for == vs. just = in the mysql guide... and now I'm twice as confused as I was. Can anyone explain what == does in Enlish? Preferably "Southern redneck, I ain't so sharp" English?

Don't get me wrong, haven't run into any more problems, all working, just would like to know WHY.

Target

1:52 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



OH! Also!

That's neat about the single quotes eliminating the need for &quot BUT.. can it work like so?


print '<TD align="right">';

Yes?

If yes, COOL! BUT, what happens when I do this?


print '<TD align="right">Fred's Market</td>';

Won't that first apostrophe need to be broken out?

Like this?


print '<TD align="right">Fred\'s Market<td>';

Knock me on the head if I'm way out in left field.

- Matt

Birdman

2:17 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matt,

You are correct! Using single quotes when writing HTML is very handy but you will need to escape the instances of a single within. It's still waaay easier.

Here's another one for ya. Heredoc syntax [us2.php.net]!

$myHTML = <<<HTML
<TD align="right">Fred's Market<td>
HTML;

No escaping for any quotes needed this way.

As for the double equals, I can't find anything in the manual using that syntax. It is a popular operator [us2.php.net] syntax in programming languages though.

for example:
<?php
if ($e == 10) print '$e equals 10!'; //one equals will not work
?>