Page 1 of 1

mysql_query doesn't work with sql used in phpmyadmin

Posted: Sat Oct 10, 2009 11:36 am
by mattmill30
Hi,

I'm completely stumped with this problem.

Basically, the following script works perfectly in phpmyadmin, but generates the following error when run through mysql_query

Script:

Code: Select all

 
$host="localhost"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="database"; // Database name 
 
$con = mysql_connect($host,$username,$password)or die("cannot connect");
mysql_select_db($db_name, $con)or die("cannot select DB");
 
$sql="INSERT INTO companies (company_id,company_name,company_address1,company_address2,company_address3,company_address4,company_postcode,company_country,company_telephone)
VALUES (NULL,'$_POST[register_company_name]','$_POST[register_company_address1]','$_POST[register_company_address2]','$_POST[register_company_address3]',
'$_POST[register_company_address4]','$_POST[register_company_postcode]','$_POST[register_company_country]','$_POST[register_company_telephone]');
INSERT INTO users (user_email,user_password,user_title,user_forename,user_surname,user_telephone,user_extension,user_mobile,company_id)
VALUES ('$_POST[register_account_email]',PASSWORD('$_POST[register_account_password]'),'$_POST[register_user_title]','$_POST[register_user_forename]','$_POST[register_user_surname]','$_POST[register_user_telephone]','$_POST[register_user_extension]','$_POST[register_user_mobile]',last_insert_id());";
 
mysql_query($sql);
 
 
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 '; INSERT INTO users (user_email,user_password,user_title,user_forename,user_' at line 1


Has anyone any ideas as to what would be causing this error?

Thanks,

Matthew Millar

Re: mysql_query doesn't work with sql used in phpmyadmin

Posted: Sat Oct 10, 2009 12:50 pm
by requinix
You can't run two queries at once with mysql_query. Split them apart.