Jump to content

Recommended Posts

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

?>

Link to comment
https://forums.phpfreaks.com/topic/176690-connection-code/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931523
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931533
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176690-connection-code/#findComment-931557
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.