July 21, 201115 yr Hi guys, I'm using dreamweaver's PHP functions so please bear with me. I've setup a MySQL database with 2 tables 'company' and 'register'. Companies login with a username and password and get authenticated by the 'company' table. This contains 3 fields, userName, Password and CompanyName. Once logged in, people fill out a form to register a personal account. The info from the form inserts into the register table and this is working ok. Problem is, on submit I need to grab their companyName from the 'company' table and post it to 'companyName' in the register table but don't know how. I've already got the company name displaying on the page using <?php echo $row_Recordset1['companyName']; ?> so it's there for the taking! This is what i'm using to insert the form data to the register table, but how do I grab from another table? Thanks if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO register (fullName, telephone, email1, email2, newsletter, reminder, password1, password2, comments, agree) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['fullname'], "text"), GetSQLValueString($_POST['telephone'], "text"), GetSQLValueString($_POST['email1'], "text"), GetSQLValueString($_POST['email2'], "text"), GetSQLValueString($_POST['newsletter'], "text"), GetSQLValueString($_POST['reminder'], "text"), GetSQLValueString($_POST['password1'], "text"), GetSQLValueString($_POST['password2'], "text"), GetSQLValueString($_POST['comments'], "text"), GetSQLValueString(isset($_POST['agree']) ? "true" : "", "defined","'Y'","'N'"));
July 22, 201115 yr if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO register (fullName, telephone, email1, email2, newsletter, reminder, password1, password2, comments, agree, companyName) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['fullname'], "text"), GetSQLValueString($_POST['telephone'], "text"), GetSQLValueString($_POST['email1'], "text"), GetSQLValueString($_POST['email2'], "text"), GetSQLValueString($_POST['newsletter'], "text"), GetSQLValueString($_POST['reminder'], "text"), GetSQLValueString($_POST['password1'], "text"), GetSQLValueString($_POST['password2'], "text"), GetSQLValueString($_POST['comments'], "text"), GetSQLValueString(isset($_POST['agree']) ? "true" : "", "defined","'Y'","'N'"), GetSQLValueString($row_Recordset1['companyName'], "text"), );
July 28, 201115 yr Author Sorry, email alerts were going into my junk folder. thanks but didn't work, still not posting the data to the database. Edit// I forgot to include companyName in INSERT INTO register... Now I get 'Column count doesn't match value count at row 1' when the form is processed Edited July 28, 201115 yr by drennan
August 8, 201115 yr Author Just gone back to this. Changed things around a bit and I don't get the column match error anymore. I've now got a recordset getting 'name' from the company table and got this displaying in the page. But still can't insert this into 'company' in the register table, it's saying "column 'company' cannot be null". Here's the code.. Thanks if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO register (name, telephone, email1, email2, newsletter, reminder, password1, password2, comments, agree, company) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['fullname'], "text"), GetSQLValueString($_POST['telephone'], "text"), GetSQLValueString($_POST['email1'], "text"), GetSQLValueString($_POST['email2'], "text"), GetSQLValueString($_POST['newsletter'], "text"), GetSQLValueString($_POST['reminder'], "text"), GetSQLValueString($_POST['password1'], "text"), GetSQLValueString($_POST['password2'], "text"), GetSQLValueString($_POST['comments'], "text"), GetSQLValueString(isset($_POST['agree']) ? "true" : "", "defined","'Y'","'N'"), GetSQLValueString($row_Recordset1['name'], "text"));
Create an account or sign in to comment