angel55 Posted May 26, 2009 Share Posted May 26, 2009 SQL Insertion 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 ''' ,Agent_Name,Address, Postcode) values ('','ms,mc','lm,scl,','nmn')' at line 1 I got the above error , can anyone please help Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 your values got no $ << in them have they? Quote Link to comment Share on other sites More sharing options...
angel55 Posted May 26, 2009 Author Share Posted May 26, 2009 no i don't have those ($ >>) in my value Quote Link to comment Share on other sites More sharing options...
angel55 Posted May 26, 2009 Author Share Posted May 26, 2009 this is my code, i don't knw if there is any problem with that. <?php require("Config.php"); class agent { private $connection; function __construct() { //Empty constructor } function insert_agents($Agent_ID,$Agent_Name,$Address,$Postcode) { $esc_Agent_ID = mysql_real_escape_string($Agent_ID, $this->connection); $esc_Agent_Name = mysql_real_escape_string($Agent_Name, $this->connection); $esc_Address = mysql_real_escape_string($Address, $this->connection); $esc_Postcode = mysql_real_escape_string($Postcode, $this->connection); $sql="insert into agents( '' ,Agent_Name,Address, Postcode) values ('{$esc_Agent_ID}','{$esc_Agent_Name}','{$esc_Address}','{$esc_Postcode}')"; $result=mysql_query($sql, $this->connection); if(!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->connection); return $numofrows; } } function openDB() { $this->connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$this->connection) { die("SQL Connection error: " . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $this->connection); if(!$db_selected) { die("SQL Selection error: " . mysql_error()); } } function closeDB() { mysql_close($this->connection); } function getResult($sql) { $result = mysql_query($sql, $this->connection); if($result) { return $result; } else { die("SQL Retrieve Error: " . mysql_error()); } } } // End of Class agent class ?> <?php if (!$_POST) //page loads for the first time { ?> <form action=" <?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <br />Agent_ID:<input type="text" name="Agent_ID" /><br /> <br /> Agent_Name:<input type="text" name="Agent_Name" /><br /> <br />Address:<input type="text" name="Address" /><br /> <br />Postcode:<input type="text" name="Postcode" /><br /> <br /> <input type="submit" value="Save" /> </form> <?php } else { $Agent_ID = $_POST['Agent_ID']; $Agent_Name = $_POST['Agent_Name']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $db1 = new agent(); $db1->openDB(); $numofrows = $db1->insert_agents('',$Agent_Name,$Address,$Postcode); echo ""; $db1->closeDB(); } ?> Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 26, 2009 Share Posted May 26, 2009 why do you have single (double?) quotes for the first column name in your insert statement ? $sql="insert into agents( '' ,Agent_Name,Address, Postcode) what is the column name supposed to be ? Quote Link to comment Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 i have change tat but still it does not work.im really struggling to solve this one problem since yestrday. Quote Link to comment Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 the same error appeared in my other page aswell. <?php require("Config.php"); class properties { private $connection; function __construct() { //Empty constructor } function insert_properties($Type,$Price,$Address,$Postcode,$Photo,$IsAvailable ,$Agent_ID) { //$esc_Properties_ID = mysql_real_escape_string($Properties_ID , $this->connection); $esc_Type = mysql_real_escape_string($Type, $this->connection); $esc_Price = mysql_real_escape_string($Price, $this->connection); $esc_Address = mysql_real_escape_string($Address, $this->connection); $esc_Postcode = mysql_real_escape_string($Postcode, $this->connection); $esc_Photo = mysql_real_escape_string($Photo, $this->connection); $esc_IsAvailable = mysql_real_escape_string($IsAvailable, $this->connection); $esc_Agent_ID = mysql_real_escape_string($Agent_ID, $this->connection); $sql="insert into properties('',Type,Price,Address,Postcode,Photo,IsAvailable,Agent_ID) values ('','{$esc_Type}','{$esc_Price}','{$esc_Address}',' {$esc_Postcode}','{$esc_Photo}','{$esc_IsAvailable}','{Agent_ID}')"; $result=mysql_query($sql, $this->connection); if(!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->connection); return $numofrows; } } function openDB() { $this->connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$this->connection) { die("SQL Connection error: " . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $this->connection); if(!$db_selected) { die("SQL Selection error: " . mysql_error()); } } function closeDB() { mysql_close($this->connection); } function getResult($sql) { $result = mysql_query($sql, $this->connection); if($result) { return $result; } else { die("SQL Retrieve Error: " . mysql_error()); } } } // End of Class agent class ?> <?php if (!$_POST) //page loads for the first time { ?> <form action=" <?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <br /> Type:<input type="text" name="Type" /><br /> <br />Price:<input type="text" name="Price" /><br /> <br />Address:<input type="text" name="Address" /><br /> <br />Postcode:<input type="text" name="Postcode" /><br /> <br />Photo:<input type="file" name="Photo" /><br /> <br />Is Available:<input type="text" name="IsAvailable" /><br /> <br />AgentID:<input type="text" name="Agent_ID" /><br /> <br /> <input type="submit" value="Save" /> </form> <?php } else { $Type = $_POST['Type']; $Price = $_POST['Price']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Photo = $_POST['Photo']; $IsAvailable = $_POST['IsAvailable']; $Agent_ID = $_POST['Agent_ID']; $db1 = new properties(); $db1->openDB(); $numofrows = $db1->insert_properties($Type,$Price,$Address,$Postcode,Photo,IsAvailable,Agent_ID); echo "jhhjk"; $db1->closeDB(); } ?> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted May 27, 2009 Share Posted May 27, 2009 please use tags! Quote Link to comment Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 the other error is gone, now i got this error SQL Insertion error: Cannot add or update a child row: a foreign key constraint fails (`comreg098jayathas`.`properties`, CONSTRAINT `properties_ibfk_1` FOREIGN KEY (`Agent_ID`) REFERENCES `agents` (`Agent_ID`) ON DELETE CASCADE ON UPDATE CASCADE) 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.