Jump to content

Recommended Posts

Hello, I have 2 MySQL tables, one is for Companies and the other for Users.

 

The primary key for both is the field id_E.

 

Both tables have the fields id_E and E_nombre, this one being the company name.

 

I have created a PHP script to add a new user to the DB which contains a select menu. This menu shows a list of companies from the companies table and sends the company id (id_E) to the users table to create a new user.

 

My problem is that I would like the DB to automatically populate the E_nombre field on the Users table with the content of the E_nombre field of the companies table based on the id_E sent to the users table by the create new user form.

 

This is the query I use to create a new user.

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO t_usuarios (id_E, usuarionombre, usuariologin, usuariopassword) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_E'], "int"),
				   GetSQLValueString($_POST['usuarionombre'], "text"),
                       GetSQLValueString($_POST['usuariologin'], "text"),
                       GetSQLValueString($_POST['usuariopassword'], "text"));
                       //GetSQLValueString($_POST['usuariolastvisit'], "date"));

  mysql_select_db($database_amat_connect, $amat_connect);
  $Result1 = mysql_query($insertSQL, $amat_connect) or die(mysql_error());
}

 

I hope I have explained properly. Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/201402-help-with-populating-table/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.