joshuaceo Posted December 8, 2008 Share Posted December 8, 2008 Here is insertnames.php <html> <body> <form action="insert.php" method="post"> First Name: <input type="text" name="fname" /><br><br> Last Name: <input type="text" name="lname" /><br><br> <input type="submit" /> </form> </body> </html> Here is insert.php <?php $con = mysql_connect("localhost","crown_brownu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crown_brownies", $con); $sql="INSERT INTO users (fname, lname) VALUES ('$_POST[fname]','$_POST[lname]')"; $sql="INSERT INTO users_shiping (name) VALUES ('$_POST[name]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($con) ?> My question is how do I join fname and lname to become one name so that I can import this into users_shipping under name? Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/ Share on other sites More sharing options...
MatthewJ Posted December 8, 2008 Share Posted December 8, 2008 You should keep them separate then join them on display only... but if you really want to. $sql="INSERT INTO users_shiping (name) VALUES ('".$_POST[lname]."', ".$_POST['fname']."')"; That would insert "lname, fname" into the shipping table Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709848 Share on other sites More sharing options...
joshuaceo Posted December 8, 2008 Author Share Posted December 8, 2008 will it insert fname and lname in the the users_shipping table under name? basically i am trying to make fname and lname (example: John Smith). and turning those 2 values into name which would be the full name John Smith. Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709869 Share on other sites More sharing options...
void Posted December 8, 2008 Share Posted December 8, 2008 Are we talking about a basic string concatenation here? $sql = "INSERT INTO users_shiping (name) VALUES ('{$_POST[fname]} {$_POST[lname]}')"; Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709873 Share on other sites More sharing options...
joshuaceo Posted December 8, 2008 Author Share Posted December 8, 2008 It worked =D but now the information in table users didn't get submitted. Can you let me know what I am doing wrong? <?php $con = mysql_connect("localhost","crown_brownu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crown_brownies", $con); $password=md5($_POST[password]); $sql="INSERT INTO users (newsletters, updates, fname, lname, login, password, company, address1, address2, city, state, province, zip, country, email, email_mode, level, phone) VALUES ('$_POST[newsletters]','$_POST[updates]','$_POST[fname]','$_POST[lname]','$_POST[login]','$password','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[email_mode]','$_POST[level]','$_POST[phone]')"; $sql="INSERT INTO users_shipping (is_primary, name, company, address1, address2, city, state, province, zip, country) VALUES ('$_POST[is_primary]','{$_POST[fname]} {$_POST[lname]}','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709884 Share on other sites More sharing options...
void Posted December 8, 2008 Share Posted December 8, 2008 Well, it's because you overwrite your $sql variable afterwards. Use different variables. Function mysql_query() executes the query, not defining of a variable itself. Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709934 Share on other sites More sharing options...
joshuaceo Posted December 8, 2008 Author Share Posted December 8, 2008 I changed this line: if (!mysql_query($sql,$sql2,$con)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($con) ?> would that work? if not can you let me know what i should change. I really don't know much about php =( Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709936 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 $password=md5($_POST[password]); $sql="INSERT INTO users (newsletters, updates, fname, lname, login, password, company, address1, address2, city, state, province, zip, country, email, email_mode, level, phone) VALUES ('$_POST[newsletters]','$_POST[updates]','$_POST[fname]','$_POST[lname]','$_POST[login]','$password','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[email_mode]','$_POST[level]','$_POST[phone]')"; $res1 = mysql_query($sql); if (!mysql_error()) { $sql="INSERT INTO users_shipping (is_primary, name, company, address1, address2, city, state, province, zip, country) VALUES ('$_POST[is_primary]','{$_POST[fname]} {$_POST[lname]}','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]')"; $res2 = mysql_query($sql); } if (!mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709938 Share on other sites More sharing options...
joshuaceo Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks for all of the replys. So i would put everything together like this? <?php $con = mysql_connect("localhost","crown_brownu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crown_brownies", $con); $password=md5($_POST[password]); $sql="INSERT INTO users (newsletters, updates, fname, lname, login, password, company, address1, address2, city, state, province, zip, country, email, email_mode, level, phone) VALUES ('$_POST[newsletters]','$_POST[updates]','$_POST[fname]','$_POST[lname]','$_POST[login]','$password','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[email_mode]','$_POST[level]','$_POST[phone]')"; $res1 = mysql_query($sql); if (!mysql_error()) { $sql="INSERT INTO users_shipping (is_primary, name, company, address1, address2, city, state, province, zip, country) VALUES ('$_POST[is_primary]','{$_POST[fname]} {$_POST[lname]}','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]')"; $res2 = mysql_query($sql); } if (!mysql_error()) if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709946 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 <?php $con = mysql_connect("localhost","crown_brownu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crown_brownies", $con); $password=md5($_POST[password]); $sql="INSERT INTO users (newsletters, updates, fname, lname, login, password, company, address1, address2, city, state, province, zip, country, email, email_mode, level, phone) VALUES ('$_POST[newsletters]','$_POST[updates]','$_POST[fname]','$_POST[lname]','$_POST[login]','$password','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[email_mode]','$_POST[level]','$_POST[phone]')"; $res1 = mysql_query($sql); if (!mysql_error()) { $sql="INSERT INTO users_shipping (is_primary, name, company, address1, address2, city, state, province, zip, country) VALUES ('$_POST[is_primary]','{$_POST[fname]} {$_POST[lname]}','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]')"; $res2 = mysql_query($sql); }else { die('Error: ' . mysql_error()); } if (!mysql_error()){ die('Error: ' . mysql_error()); } echo "1 user added"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/136123-how-do-i-turn-firstname-and-last-name-to-full-name-source-attached/#findComment-709950 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.