Jump to content

Php Mysql Error


pritam79

Recommended Posts

I created this mysql table using WAMP server's PHPMyAdmin interface- id_com (pk), idusr_com(fk),name_com, address_comAlso there is some PHP code as shown below-

require("db-connect.php");	   $db = db_connect();	   $name_com = mysql_real_escape_string($_POST['txtname_com'], $db);	   $address_com = mysql_real_escape_string($_POST['txtaddress_com'], $db);	   if($db)	    {		 if(isset($_POST['Add']))		  {					   // insert company name and location in company_com		    $sql = "INSERT INTO company_com(name_com, address_com)				    VALUES ('$name_com', '$address_com') WHERE idusr_com = ".$_SESSION[id_usr];		    mysql_query($sql, $db) or die(mysql_error($db));		    header('Location: company/index.php');		    exit();		  }		 if(isset($_POST['Update']))		  {								   // update company name and location in company_com			   $sql = "UPDATE company_com SET name_com = $name_com, address_com = $address_com				   WHERE idusr_com = ".$_SESSION[id_usr];		    mysql_query($sql, $db) or die(mysql_error($db));		    header('Location: company/index.php');		    exit();		   		  }		 }

But, on Inserting a record I am getting this error.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versionfor the right syntax to use near 'WHERE idusr_com = 92' at line 2And on updating I get this error.Unknown column 'Apple1' in 'field list'This is the table 'company_com' on browsing--___________________________________________id_com | idusr_com | name_com | address_com| PK- id_com, FK- id_usr___________________________________________| 7 | 88 | Apple | LA | 11 | 92 | | |-------------------------------------------This is the table 'user_usr' on browsing-- PK- id_usr____________________________________________________________________ id_usr | username_usr | password_usr | level_usr | email_usr |____________________________________________________________________| 88 | com1 | **** | 2 | com1gmail.com | 92 | com2 | **** | 2 | com2gmail.com |---------------------------------------------------------------------

Link to comment
Share on other sites

The INSERT statement doesn't have a WHERE clause, as far as I know. You need quotes around the values of your UPDATE query: UPDATE company_com SET name_com = '$name_com', address_com = '$address_com'

Link to comment
Share on other sites

  • 2 weeks later...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version All that means is you have an error in your select statement, Your missing some thing. Check you query line

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...