i am trying to insert my form data into my table 'supplier_registration', however this is not working, i am getting mysql 'ERROR', I am not sure why this is happening.
I am also wanting to insert the same form data into a second table 'supplier_session', but this time only inserting specific bits of the form data, '$cname' and '$creg'.
When a user lands on the page there ip address is inserted into the table 'supplier_session' so when this form is submitted i also want the supplier_session table to update an enum value 'form1_complete' from no to yes, where that user's ip or 'user_IP' exists in the table row. i am trying to d this by running three querys but its not working, please can someone show me where i am going wrong. Thanks
Database:
ID(AI) | company_name | company_reg_number | company_incorp_date | company_address | company_postcode | contact_name | contact_number | contact_email | company_vat_number | date_time | user_IP
Code:
<?php
session_start();
$db_hostname = 'localhost';
$db_database = 'hewden1';
$db_username = 'root';
$db_password = '';
$db_server = mysql_connect($db_hostname, $db_username, $db_password)
or die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
$cname = $_POST['cname'];
$creg = $_POST['creg'];
$address = $_POST['address'];
$post = $_POST['post'];
$contactn = $_POST['contactn'];
$contactt = $_POST['contactt'];
$contacte = $_POST['contacte'];
$vat = $_POST['vat'];
$incorp = $_POST['incorp'];
$ipaddress = $_SERVER["REMOTE_ADDR"];
$sql="INSERT INTO supplier_registration (company_name, company_reg_number, company_incorp_date, company_address, company_postcode, contact_name, contact_number, contact_email, company_vat_number, date_time, user_ip)
VALUES ('$cname', '$creg', '$incorp', $address', '$post', '$contactn', '$contactt', '$contacte', '$vat', NOW(), '$ipaddress')";
$result = mysql_query($sql);
$qry2 = "INSERT INTO supplier_session (company_reg_number, company_name) VALUES('$creg','$cname') WHERE user_IP = '$ipaddress'";
$result = @mysql_query($qry2);
$qry3="UPDATE supplier_session SET form1_completed = 'Yes' WHERE form1_completed = 'No' AND user_IP = '$ipaddress'";
$result = mysql_query($q);
if($result){
header("Location: index.php?registration=sucess");
}else {
echo "ERROR";
}
?>
html:
<form name="myForm" id="myform" action="company_info_process.php" onsubmit="return validateForm()" method="post">
<input type="text" id="field_cname" name="cname" class="field_cname">
<input type='text' name='creg' id="field_creg">
<input type='text' name='incorp' id="field_incorp">
<input type='text' name='vat' id="field_vat">
<input type='text' name='contactn' id="field_contactn">
<input type="text" name="contactt" id="field_contactt">
<input type="text" id="field_contacte" name="contacte">
<input type="text" id="field_address" name="address">
<input type="text" id="field_post" name="post"/>