mysql_query doesn't work with sql used in phpmyadmin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattmill30
Forum Newbie
Posts: 7
Joined: Wed Oct 07, 2009 12:59 pm

mysql_query doesn't work with sql used in phpmyadmin

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

You can't run two queries at once with mysql_query. Split them apart.
Post Reply