unidox Posted August 28, 2007 Share Posted August 28, 2007 I dont know whats wrong, but I keep getting this 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 '' at line 1 My file is: <?php $page = "admins"; $mysql_table = "cp_levels"; require_once("inc/db.inc.php"); require_once ("files/levels.php"); $selecta = "4.All&3.Roster&2.Staff&1.Admin"; $checkfields = "title"; $errors = "Please enter your name!"; $titles = "Your Name:&Login:&Home:&News:&Roster:&Links:&Leagues:&Matches:&Servers:&Sponsors:&Downloads:&Media:&Demos:&Setting:&Change_Pass:&Users"; $fields = "title&login&home&news&roster&links&leagues&matches&servers&sponsors&downloads&media&demos&settings&changepass&users"; $type = "text&select&select&select&select&select&select&select&select&select&select&select&select&select&select&select"; $size = "40&null&null&null&null&null&null&null&null&null&null&null&null&null&null&null"; $maxlength = "20&null&null&null&null&null&null&null&null&null&null&null&null&null&null&null"; $id_type = "level_id"; if ($_REQUEST['m'] == "4") { $choose = explode(".",$_POST['level_id']); $access = $choose[1]; $access2 = "title,login,home,news,roster,links,leagues,matches,servers,sponsors,downloads,media,demos,settings,changepass,users"; MYSQL_QUERY("UPDATE $mysql_table SET level_id='$access' WHERE $id_type=$id") or die (mysql_error()); showSuccess('Admin User Level Update'); header ("Location: index.php?page=admin_users"); } if (!$_REQUEST['m']) { getHeader(); createJSValid($checkfields,$errors); createForm($titles,$fields,$type,$size,$maxlength,'4'); } ?> The db is: `level_id` int(11) NOT NULL auto_increment, `title` varchar(20) NOT NULL default '', `login` int(2) NOT NULL default '0', `home` int(2) NOT NULL default '0', `news` int(2) NOT NULL default '0', `roster` int(2) NOT NULL default '0', `links` int(2) NOT NULL default '0', `leagues` int(2) NOT NULL default '0', `matches` int(2) NOT NULL default '0', `servers` int(2) NOT NULL default '0', `sponsors` int(2) NOT NULL default '0', `downloads` int(2) NOT NULL default '0', `media` int(2) NOT NULL default '0', `demos` int(2) NOT NULL default '0', `settings` int(2) NOT NULL default '0', `pass` int(2) NOT NULL default '0', `users` int(2) NOT NULL default '0', PRIMARY KEY (`level_id`) ) TYPE=MyISAM AUTO_INCREMENT=38 ; Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 First off, try putting quotes around the variables in your query. MYSQL_QUERY("UPDATE $mysql_table SET level_id='$access' WHERE '$id_type'='$id'") or die (mysql_error()); If that doesn't work, try using mysql_real_escape_string() on $acess, $id_type, and $id before you use them in your query. Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2007 Author Share Posted August 28, 2007 I did, the error stopped, but now it didnt update anything Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 Replace your query code with this: <?php $query = "UPDATE $mysql_table SET level_id='$access' WHERE '$id_type'='$id'"; echo $query; ?> Tell me what it prints out. Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2007 Author Share Posted August 28, 2007 UPDATE cp_levels SET level_id='3' WHERE 'level_id'='' Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2007 Share Posted August 28, 2007 ... SET level_id='$access' WHERE $id_type=$id ... According to the database table schema you posted, level_id is auto-incrementing PK so you shouldn't even be thinking of setting its value, and id_type is not a field in the table. Something's not right here. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 Your variable $id doesn't have a value, thats why it's not updating anything in the database. Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2007 Author Share Posted August 28, 2007 So how do I fix it? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 Well, You need to go back to where you assigned a value to $id, and figure out why the variable is out of scope, or figure out why nothing is being assigned to it. Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2007 Author Share Posted August 28, 2007 Ok, is there any other way to do it, I just want to update the DB. I am trying to have drop downs, and they choose admin,member,staff, whatever to certain pages, and it logs in the db as numbers. Can someone help? Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2007 Author Share Posted August 28, 2007 Anyone? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 Well, you need to ask yourself where your script retrieves the information to know which row in the database to update. Figure that out, and it will be easy to help you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.