shotos Posted August 15, 2008 Share Posted August 15, 2008 hi all, trying to run a mysql query and i seem to have messed up with the quotes. so i get a syntax error on the query command $rename = 'alter table Element_'.trim($title).' change ' . $column_name $check_item . ' varchar(50)'; tanx in advance Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/ Share on other sites More sharing options...
ohdang888 Posted August 15, 2008 Share Posted August 15, 2008 post your error and the whole query Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617646 Share on other sites More sharing options...
shotos Posted August 15, 2008 Author Share Posted August 15, 2008 the error is: Parse error: syntax error, unexpected T_VARIABLE in /home/kwasi/public_html/modify_update.php on line 39 the code is $column_name = $_SESSION['column_name']; $rename = 'alter table Element_'.trim($title).' change ' . $column_name $check_item . ' varchar(50)'; $update = mysql_query($rename,$db->link) or die(mysql_error() . " Query was: $rename"); Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617654 Share on other sites More sharing options...
ohdang888 Posted August 15, 2008 Share Posted August 15, 2008 $column_name = $_SESSION['column_name']; $rename = 'alter table Element_'.trim($title).' change '.$column_name.$check_item.' varchar(50)'; $update = mysql_query($rename,$db->link) or die(mysql_error() . " Query was: $rename"); try it Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617662 Share on other sites More sharing options...
shotos Posted August 15, 2008 Author Share Posted August 15, 2008 it didn't work. this was the 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 'varchar(50)' at line 1 Query was: alter table Element_Trial change babybaby varchar(50) Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617670 Share on other sites More sharing options...
shotos Posted August 15, 2008 Author Share Posted August 15, 2008 it didn't work. this was the 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 'varchar(50)' at line 1 Query was: alter table Element_Trial change babybaby varchar(50) Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617671 Share on other sites More sharing options...
moselkady Posted August 15, 2008 Share Posted August 15, 2008 A small fix to ohdang888's solution: $rename = 'alter table Element_'.trim($title).' change '.$column_name.' '.$check_item.' varchar(50)'; Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617674 Share on other sites More sharing options...
moselkady Posted August 15, 2008 Share Posted August 15, 2008 One other thing, try to print $rename (or whatever you sql variable) in case you get an error to better figure out the problem. Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617676 Share on other sites More sharing options...
shotos Posted August 15, 2008 Author Share Posted August 15, 2008 finally it worked. thanks Link to comment https://forums.phpfreaks.com/topic/119895-solved-mysql-problem-with-quotes/#findComment-617681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.