Jump to content

[SOLVED] SQL/PHP Update not working?


finalmen

Recommended Posts

Good evening,

 

I'am working on this script on which i want to be able to update a certain amount of variables.

 

$kwerie="UPDATE main_catagory SET keyword='$keyword'AND keyword2='$keyword2'AND keyword3='$keyword3' AND description='$description' AND name='$name' AND age='$age'AND picture='$picture'AND priority='$priority' AND alttext='$alttext' WHERE 'id' = $id ";
mysql_query($kwerie);

 

Is the code im using, the variables are coming true perfectly, although, it doesn't seem to insert it into the database....?

 

Any help is welcome, breaking my head over this for hours now.

 

Best Regards,

 

Finalmen

Link to comment
https://forums.phpfreaks.com/topic/160513-solved-sqlphp-update-not-working/
Share on other sites

mysql_query($kwerie) or die(mysql_error());

 

there's a problem with your SQL statement.  when doing an update, you dont put 'AND' between the statements you are updating, just use a comma delimiter between them

<?php
$kwerie="UPDATE main_catagory SET keyword='$keyword', keyword2='$keyword2', keyword3='$keyword3', description='$description', name='$name', age='$age', picture='$picture', priority='$priority', alttext='$alttext' WHERE 'id' = $id ";

 

The last suggestion someone else can confirm for me, but you may want to enclose all of your variables in the SQL statement with {}

The curly braces, when used with variable interpolation, is to disambiguate a variable with other characters around it. Like an array lookup.

 

<?php
$e = "here is some static text and here's an {$array['lookup']}";

 

If you have $array['lookup'] with now curly braces, it can be a bit ambiguous whether you want to look up the variable $array or together as a whole. One can treat "['lookup']" as a string rather as part of an array lookup index key. This is the same for method calls like -

 

<?php
$e = "here is some static text and here is a {$method->call()}";

 

Again, it's a bit ambiguous if you want to evaluate the variable $method or $method->call() as a whole.

 

Imagine you want something like -

<?php
$n = 42;
$e = "here is some static text and here is the {$n}nd character of this string";

 

Without the curly braces there, it's ambiguous right? $nnd and {$n}nd is different as you can see the huge difference it would make.

 

Hope this clears it up. By the way, you don't need the curly braces in your SQL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.