Page 1 of 1

saving data to two table at the same time.

Posted: Tue Feb 21, 2012 10:36 am
by makuletz27
i want to save the data from all_users table at the same time it will save to another table named profile_photo
but the only data that will save at profile_photo is the user ID

i tried to code it but i didn't get the result that i want....

Code: Select all

<?php
$db_connect=mysql_connect("localhost","root","");
if(!$db_connect) {
	die ("Could not connect: " . mysql_error());
}

mysql_select_db('my_db',$db_connect);

$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$MI = $_POST['MI'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Snumber = $_POST['Snumber'];
$Email = $_POST['Email'];
$Section = $_POST['Section'];
 
$sql1=("INSERT INTO all_users (id,Fname,Lname,MI,Username,Password,Snumber,Email,Section,User_type) VALUES
							('','$Fname','$Lname','$MI','$Username','$Password','$Snumber','$Email','$Section','student')");
	if (!mysql_query($sql1,$db_connect))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";



//i dont know if it correct 
$sql = mysql_query("SELECT * FROM all_users");
			
		
		while($info = mysql_fetch_array($sql)){
			$id=$info['id'];	
		}
$sqlFORimage =("INSERT INTO profile_photo(id,filename,size,image_path) VALUES
		('$id','','','')");
				
		
		
mysql_close($db_connect)
?>

Re: saving data to two table at the same time.

Posted: Tue Feb 21, 2012 12:38 pm
by makuletz27
problem solve ! ^_^