954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Submit data to multiple tables

I'm new to PHP and I'm some trouble writing to multiple tables from the same form. When I run the following script it will not write the data to XINFO but it will write to ATTRIB1. If I take ATTRIB1 out of the script it will work properly and once again write to XINFO. I can't figure out what I'm doing wrong. Any help would be greatly appreciated.

// Insert fields into XINFO 
	 $sql = "INSERT INTO xinfo SET
	 
first_name='$fn',
last_name='$ln',
city='$city',
state_province='$state',
country='$cntry',
other_country='$ocntry',
dob='$dob',
email='$em' ";

// Insert fields into ATTRIB1
	$sql = "INSERT INTO attrib1 
	
example='$x1' ";
CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

You are overwriting your $sql variable with the second statement. Try running the first SQL statement before you set the $sql variable, or you could change your second statement to use a new variable, for example $sql2.

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

Thanks darkagn. A quick $exec = mysql_query() between statements did the trick.

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You