heshan Posted June 24, 2011 Share Posted June 24, 2011 Hi all, I want to insert data to my "account_details" table and at the same time update it in my "account"table. Here is the coding which ONLY passes data to my "account_details" table. But NOTHING will happen to my "account" table. Can anyone help me out to find the error.... The 2 tables look like this. account_details (account_number, nic, full_name, name_with_initials, phone_number, address, gender, date_of_birth ) account (account_number, account_type, fd_period, account_type, account_balance, account_interest ) <?php $connect=mysql_connect('localhost','root',''); mysql_select_db('bank',$connect); $nic = $_POST['nic']; $full_name = $_POST['full_name']; $name_with_initials = $_POST['name_with_initials']; $phone_number = $_POST['phone_number']; $address = $_POST['address']; $gender = $_POST['gender']; $date_of_birth = $_POST['date_of_birth']; $account_type = $_POST['account_type']; $fd_period = $_POST['fd_period']; $insert_query = "INSERT INTO account_details ( nic, full_name, name_with_initials, phone_number, address, gender, date_of_birth ) VALUES ( '$nic', '$full_name', '$name_with_initials', '$phone_number', '$address', '$gender', '$date_of_birth' )"; //Run a switch on the chosen type of account if($_POST['account_type'] == "abhimani_plus") { if($_POST['gender']!="female") { //Show error messages here echo "You do not meet the critera required to open this account.";exit; } } //Account Creation Here $r = mysql_query ($insert_query); if($r) { echo "A new Account number ".mysql_insert_id()." has been created successfully.";die(); } $query = "UPDATE account SET 'account_type' = '$account_type', 'fd_period' = '$fd_period' WHERE 'account_number' = '$account_number'"; mysql_query($query) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/ Share on other sites More sharing options...
mikesta707 Posted June 24, 2011 Share Posted June 24, 2011 is there a mysql error? Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/#findComment-1234110 Share on other sites More sharing options...
heshan Posted June 24, 2011 Author Share Posted June 24, 2011 The data does not pass to my "account" table. I think there should be an error in my UPDATE query.. Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/#findComment-1234115 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2011 Share Posted June 24, 2011 You have single-quotes around your column names (three places), thereby making them strings instead of column names. The WHERE clause is FALSE because you are testing if the string 'account_number' is the same as what is in the $account_number variable. Unless $account_number contained the string 'account_number', the WHERE clause is false and the query is not even being executed. Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/#findComment-1234117 Share on other sites More sharing options...
heshan Posted June 24, 2011 Author Share Posted June 24, 2011 Then how can i sought it out..Can you give me the correct coding? Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/#findComment-1234127 Share on other sites More sharing options...
heshan Posted June 24, 2011 Author Share Posted June 24, 2011 Thanks both of u...now it works... Link to comment https://forums.phpfreaks.com/topic/240265-problem-in-the-coding-of-passing-data-into-tables/#findComment-1234350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.