Jump to content

SQL error


angel55

Recommended Posts

 

 

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

Link to comment
Share on other sites

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();

}

?>

Link to comment
Share on other sites

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();

}

?>

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.