superdupermodbutnot Posted October 6, 2009 Share Posted October 6, 2009 I got this from w3 but I think it's outdated. What will make this work? <?php $con = mysql_connect("localhost", "dbuser", "pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); mysql_query("insert into TableName ('$_POST[title]', '$_POST[data1]', '$_POST[data2]', '$_POST[data3]', '$_POST[data4]')") or die(mysql_error()); echo "The following information was entered into the database<br><br><br>"; echo "<b>Title:</b> $_POST[title]<br>"; echo "Thanks for taking the time to submit your information."; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176690-connection-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2009 Share Posted October 6, 2009 There is nothing out of date in the posted php code. If you are having a problem with that php code you would need to state what it is doing or not doing and what errors or other symptoms you are getting for any one to be able to help you with it. Quote Link to comment https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931523 Share on other sites More sharing options...
elabuwa Posted October 6, 2009 Share Posted October 6, 2009 mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$database")or die(mysql_error()); $sql = "INSERT INTO transactions(tr_id,acnum,debit,credit,stat) VALUES('$tracker_ID','$recac','$total_received','$z','$ss')"; mysql_query($sql); I think there is some thing wrong with your sql syntax. Quote Link to comment https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931533 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2009 Share Posted October 6, 2009 In programming there are several different ways of accomplishing any task. The actual sql posted is valid. You do not need to provide a list of column names if you are supplying a value for every column and the values are in the same order as the columns in the table. Quote Link to comment https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931557 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.