ccrevcypsys Posted December 17, 2007 Share Posted December 17, 2007 So i get this error when i try to update the database. And im not sure why it is doing this... MySQL Error Occured n1064: 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 'N., `LastName`= Labowe, D.D.S., `EventName`= Endodontic Symposium, `EventDescrip' at line 1 n QUERY = UPDATE cou ses SET `FirstName`=Stua t N., `LastName`= Labowe, D.D.S., `EventName`= Endodontic Symposium, `EventDescription`= 6 panelists of local endodontists~Drs. Bell, Jarrett, Gray, Luckey, Carmichael, Reeves, and Iwasiuk. 1 hr. of clinical 1 hr. of business mtg., `EventDate`= 2004-10-13 , `EventHours`= 2, `RegNo`= , `SubHead`= WHERE id = 1; heres my code <?php if($_POST['EventName']){ if($_GET['i']==1){ $record["FirstName"] = $_POST["FirstName"]; $record["LastName"] = $_POST["LastName"]; $record["EventName"] = $_POST["EventName"]; $record["EventDescription"] = $_POST["EventDescription"]; $record["EventDate"] = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"]; $record["EventHours"] = $_POST["EventHours"]; $record["RegNo"] = $_POST["RegNo"]; $record["SubHead"] = $_POST["SubHead"]; $where = "id = ".$_GET['e']; $update = $db->update("courses", $record, $where); if($update == TRUE){ echo "This Section Has Updated"; }else{ echo "ERROR ERROR WE ARE GOING DOWN!"; } } }?> and $_GET['e'] = the id of the query. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 shouldn't "courses" be 'courses' Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 17, 2007 Share Posted December 17, 2007 I see two things going on: One there appear to be characters that are being dropped fromt he query. For example "courses" is shown as "cou ses" in your first code black. Second, none of your values are enclosed in single quotes. Where is the code that builds the $where variable? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 17, 2007 Share Posted December 17, 2007 see this part `EventDate`= 2004-10-13 , `EventHours`= 2, `RegNo`= , `SubHead`= WHERE id = 1; after regno, is it like that .... Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 17, 2007 Author Share Posted December 17, 2007 Where is the code that builds the $where variable? that is this $where = 'id = '.$_GET['e]; // The e is the id of the row n~ link=topic=172446.msg764588#msg764588 date=1197909643] see this part `EventDate`= 2004-10-13 , `EventHours`= 2, `RegNo`= , `SubHead`= WHERE id = 1; after regno, is it like that .... i added this part if(!empty($_POST['RegNo']) || !empty($_POST['SubHead'])){ $record['RegNo'] = $_POST['RegNo']; $record['SubHead'] = $_POST['SubHead'];} so if it is empty they wont show up. But there is still the same error and i changed "courses" to 'courses' and changed all the " to ' and the cou ses thing is just my debug error. It doesnt like to parse the r's or n's and i just forgot to change that one before i posted this Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 17, 2007 Author Share Posted December 17, 2007 there has to be somone who can help me figure this out... Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 17, 2007 Share Posted December 17, 2007 There are so many errors here, that it appears solving one just reveals another.. for example: $where = 'id = '.$_GET['e]; // The e is the id of the row is missing a closing single quote on the $_GET element ['e'] : $where = 'id = '.$_GET['e']; // The e is the id of the row Once all of these little oversights are cleared up, you might get some working code... PhREEEk Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 17, 2007 Author Share Posted December 17, 2007 no its there lol its just not on this. it seems the error is coming whenever there is a space or any different char. Could this be the problem if so then how can i fix it updated code if($_POST['EventName']){ if($_GET['i']==1){ $record['FirstName'] = $_POST['FirstName']; $record['LastName'] = $_POST['LastName']; $record['EventName'] = $_POST['EventName']; $record['EventDescription'] = $_POST['EventDescription']; $record['EventDate'] = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; $record['EventHours'] = $_POST['EventHours']; if(!empty($_POST['RegNo']) || !empty($_POST['SubHead'])){ $record['RegNo'] = $_POST['RegNo']; $record['SubHead'] = $_POST['SubHead'];} $where = 'id = '.$_GET['e']; $update = $db->update("courses", $record , $where); if($update == TRUE){ echo "This Section Has Updated"; }else{ echo "ERROR ERROR WE ARE GOING DOWN!"; } } Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 17, 2007 Author Share Posted December 17, 2007 could it be a prblem with this? <?php function update ($tablename, $record, $where) { if(!is_array($record)) die ($this->debug("array", "Update", $tablename)); $count = 0; foreach ($record as $key => $val) { if ($count==0) $set = "`".$key."`"."=".$val; else $set .= ", " . "`".$key."`". "= ".$val; $count++; } $query = "UPDATE ".$tablename." SET ".$set." WHERE ".$where."; "; $this->query = $query; mysql_query($query, $this->db); if ($this->error()) die ($this->debug()); if ($this->affected() > 0) return true; else return false; } // end update ?> This is my db.inc.php class for the update Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 17, 2007 Author Share Posted December 17, 2007 Then when i use a test row that has no spaces just test in every input area i get this error n1054: Unknown column 'Test' in 'field list' n QUERY = UPDATE `courses` SET `FirstName`=Test, `LastName`= Test, `EventName`= Test, `EventDescription`= Test, `EventDate`= 2007-12-18 , `EventHours`= 3 WHERE id = 1201; 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.