Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Insert data from one DB table to another

Featured Replies

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'"));

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"),
);

  • 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 :wacko:

Edited by drennan

  • 2 weeks later...
  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.