View Full Version : SQL Errors on Windows Server
trendywebs
10/09/2006, 08:07
:confused: I've been working on a project. There are some queries which are working perfect on my linux server. when the script was shifted to my client's windows server i'm getting some error where mysql says that there's a syntax error... This is the query. Can anyone tell what's the problem??:(
$sqlupdate = "update static_page set submit_date=now(),";
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\",";
$sqlupdate = $sqlupdate ."where page_id=\"".$u_id."\"";
$res=mysql_db_query($dbname,$sqlupdate);
It's a syntax error but i'm not able to pinpoint the problem.
Regards,
Anirban.
End of the 2nd line, if I'm not mistaken. Your query will end like
update static_page set blahblah page_content="fdfdfd",where page_id=...
So there's no space between , and where
I may be wrong of course...
trendywebs
10/09/2006, 10:58
If its the space between the $c and o its something with the forum there's no space in between them in the sql query on the page. I don't know what problem otherwise.
Thanks,
Anirban.
If its the space between the $c and o its something with the forum there's no space in between them in the sql query on the page. I don't know what problem otherwise.
Thanks,
Anirban.
I think you should change this line:
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\",";
into :
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\" ";
ludesign
10/09/2006, 12:07
I think you should change this line:
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\",";
into :
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\" ";
As savire note, you have one extra comma right before WHERE statement, and this is wrong... :}
Also i don't mind to hurt you, but you should think about to change to better your coding style, not it's not clear and optimized enough. This is my opinion ;)
:p
trendywebs
10/10/2006, 12:42
:) thanks mates. It's sorted out now. But, i'm wondering why it was functioning perfectly on the linux server?? And Vasil...do give me your honest comments:) I'd love to hear about them. I do want to hear about good opinion and critics for my self improvement.
Regards,
Anirban.
ludesign
10/11/2006, 02:54
And Vasil...do give me your honest comments:) I'd love to hear about them. I do want to hear about good opinion and critics for my self improvement.
Sure I'll.
First mysql_db_query() use it only when you have to run a query to another mysql database, otherwise it's better to use mysql_select_db(); right after mysql_connect and to run all queries with mysql_query();
So next, .= operator means 'get the old value and assign the new one to it, so instead of using:
<?php
$someVar = 'something ';
$someVar = $someVar . 'more';
?>
You can do:
<?php
$someVar = 'something ';
$someVar .= 'more';
?>
It will save you some writting also it will be more clear and easy for the eyes.
And now let's talk about the SQL Syntax:
Here is your code:
$sqlupdate = "update static_page set submit_date=now(),";
$sqlupdate = $sqlupdate ."page_content=\"".trim(addslashes(stripslashes($content)))."\"";
$sqlupdate = $sqlupdate ."where page_id=\"".$u_id."\"";
Here is mie:
$sql = 'UPDATE static_page SET submit_date = now(), ';
$sql .= 'page_content = "'. trim(addslashes(stripslashes($content))) .'"';
$sql .= ' WHERE page_id = '. $u_id;
As You can note the code is more clear and easy for reading and understanding (or maybe that's how i see it :P).
First thing you can note is the .= operator, but I already talk about it so next one is ALL mysql Statements are written with uppercase chars, so you can easy break down the whole SQL code on first look. Next I'll suggest you to use ' instead of ". The difference is that "" will force the php to check the string for any variables inside it and '' won't do that. Here is an example:
<?php
$who = 'Mom';
$say = 'Hello, $who';
print $say; // will output Hello, $who
?>
And:
<?php
$who = 'Mom';
$say = "Hello, $who";
print $say; // will output Hello, Mom
?>
So if we use " we force the php to check the string for variables and this will slow down the script execution. So use " only when you want to use variables inside the string and use ' anywhere else.
And I think it's better to store the whole SQL QUERY in one variables without to break it... well I mean:
<?php
$sql = 'UPDATE static_page SET submit_date = now(),
page_content = "'. trim(addslashes(stripslashes($content))) .'"
WHERE page_id = '. $u_id;
?>
And Almost to forget, In your SQL when you have to deal with Digits you can skip " (for example: page_id = 5 instead of page_id = '5');
I don't mean 'You are not good, YOU ARE, i Just do not like your coding style, which don't means it's not good and useful, cuz it is.' And all I wrote are only suggestions to you.
Also I do not want to force you to change your coding style, cuz I don't mind it, i just want to be helpful, nothing more. Thanks.
:p
ludesign
10/11/2006, 10:00
I don't mean 'You are not good, YOU ARE, i Just do not like your coding style, which don't means it's not good and useful, cuz it is.' And all I wrote are only suggestions to you.
Also I do not want to force you to change your coding style, cuz I don't mind it, i just want to be helpful, nothing more. Thanks.
:p
Well the most funny part will be to quote myself :p
I just want to tell you that with YOU ARE and "cuz it is" i mean:
You are good programmer;
and
Your scripts are working good;
Sorry if i hurt you in any way i didn't mean it
:(
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.