lingo5 Posted May 11, 2010 Share Posted May 11, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.