Page 1 of 3

MySQL query doesnt work

Posted: Wed Jul 26, 2006 2:50 pm
by adamb10

Code: Select all

mysql_query ("UPDATE settings SET 'title'='".$title."', 'username'='".$name."', 'email'='". $email."', 'tablewidth'='".$width."', 'menubar'='".$menubar."', 'postorder'='".postorder."', 'posting'='".$posting."', 'kwikpost'='".$kwikpost."', 'maxshow'='".$maxshow."', 'im'='".$im."', 'links'='".$links."', 'logo'='".$logo."', 'menubarlocation'='".$menubarlocation."', 'kwikpostlocation'='".$kwikpostlocation."'");
That query doesnt do anything, I dunno whats wrong with it. :(

Posted: Wed Jul 26, 2006 2:51 pm
by daedalus__

Code: Select all

$q = $mysql_query($sql) or print(mysql_error());
do error checking and read the manual

Posted: Wed Jul 26, 2006 2:57 pm
by kbrown3074
I see you have single quotes around your field names..not necessary. Also try putting just single quotes around your vars....see below Also..kinda disturbing..you will set every record to these values since you dont have a where clause. Also you missed a $ on the posting var

Code: Select all

mysql_query ("UPDATE settings SET title='$title', username='$name', email='$email', tablewidth='$width', menubar='$menubar', postorder='$postorder', posting='$posting', kwikpost='$kwikpost', maxshow='$maxshow', im='$im', links='$links', logo='$logo',menubarlocation='$menubarlocation', kwikpostlocation='$kwikpostlocation'");
[/url]

Posted: Wed Jul 26, 2006 3:02 pm
by daedalus__
single quotes are fine for fields that are strings and integers

Posted: Wed Jul 26, 2006 3:06 pm
by adamb10
I did try errors on and MySQL printed...

Code: Select all

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 ''title'='Testbook', 'username'='adam', 'email'='debailey@wi.rr.com', 'tablewidth' at line 1
I fixed the variable where no $ was btw.

Posted: Wed Jul 26, 2006 3:09 pm
by jamiel
Your field names need to have backticks (`) around them not quotes (')

Posted: Wed Jul 26, 2006 3:14 pm
by adamb10
Backticks didnt work either. :p I hate being a n00b at mysql.

Posted: Wed Jul 26, 2006 3:18 pm
by jamiel
Put all that sql into a variable called $sql .. then print_r($sql) just before the query.

Show us the output of that aswell as the new mysql_error() you are most likely getting.

Posted: Wed Jul 26, 2006 3:31 pm
by daedalus__
sorry kbrown and jamiel, didnt notice that he was single quoting field names and didn't mean to go against what you two said.

Posted: Wed Jul 26, 2006 3:32 pm
by adamb10

Code: Select all

print_r($sql)
    $sql = "mysql_query ("UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."'") or print(mysql_error())";
The variable has a parse error in it. I usually dont apply variables to big queries like this.

Posted: Wed Jul 26, 2006 3:33 pm
by daedalus__
you have to end every line with a semi colon ;/b]

Code: Select all

print("<pre>");
print_r($sql);
print("</pre>");

Posted: Wed Jul 26, 2006 3:35 pm
by daedalus__
adamb10 wrote:

Code: Select all

$sql = "UPDATE settings WHERE `title`='".$title."', `username`='".$name."', `email`='". $email."', `tablewidth`='".$width."', `menubar`='".$menubar."', `postorder`='".$postorder."', `posting`='".$posting."', `kwikpost`='".$kwikpost."', `maxshow`='".$maxshow."', `im`='".$im."', `links`='".$links."', `logo`='".$logo."', `menubarlocation`='".$menubarlocation."', `kwikpostlocation`='".$kwikpostlocation."'";

Posted: Wed Jul 26, 2006 3:41 pm
by RobertGonzalez
He needs to escape the vars. The '@' might be giving him problems.

Posted: Wed Jul 26, 2006 3:41 pm
by adamb10
MySQL didnt return an error that time but the query is still dead in the water.. :(

Posted: Wed Jul 26, 2006 3:52 pm
by daedalus__
What do you mean "dead in the water"?

Code: Select all

$r = mysql_query($sql);

print mysql_affected_rows($r);