问题描述:

$customer_name = $_POST["customer_name"];

$address = $_POST["address"];

$currency = $_POST["currency"];

$contact_number = $_POST["contact_number"];

$email_address = $_POST["email_address"];

$temp_amount = $_POST["temp_mount"];

$ID = $_POST["ID"];

$host = "localhost";

$username = "tempdb";

$password = "123456";

$database = "tempdb";

$con = mysql_connect($host,$username,$password);

$db_selected = mysql_select_db($database, $con);

mysql_query("INSERT INTO temp_customer (ID,CustomerName,Address,Currency,ContactNumber,Email,Amount) VALUES ('".$ID."','".$customer_name."','".$address."','".$currency."','".$contact_number."','".$email_address."','".$temp_amount."'") or die(mysql_error());

mysql_close($con);

This is my code to insert the data into MySQL database, but when I run this nothing is displayed.

网友答案:

Try

"INSERT INTO temp_customer(ID,CustomerName,Address,Currency,ContactNumber,Email,Amount) VALUES ('ID', '$customer_name', '$address', '$currency', '$email_address', '$temp_amount')" or die(mysql_error());
网友答案:

First, I would change over to mysqli instead of mysql as it's a safer method to leverage mysql though PHP. Without knowing your data types, I left your insert statement alone I just fixed it up for use with mysqli.

$host = "localhost";
$username = "tempdb";
$password = "123456";
$database = "tempdb";
$db = new mysqli_connect($host, $username, $password, $database);

if($db -> connect_errno > 0){
    die("there was an error connecting to the db.");
}

$q = "INSERT INTO temp_customer (ID,CustomerName,Address,Currency,ContactNumber,Email,Amount) VALUES ('".$ID."','".$customer_name."','".$address."','".$currency."','".$contact_number."','".$email_address."','".$temp_amount."')";

if(!$result = $db->query($q)){
    //die("Error running the query");
    die($db->error);
}
$db->close();

Now if you hit a snag along the way, you'll know where you issue is and if you still have a problem with the query string, you can echo it to see if you are missing a value and need to change the way you are escaping your string although it should be fine.

网友答案:
mysql_query("INSERT INTO temp_customer (ID,CustomerName,Address,Currency,ContactNumber,Email,Amount) VALUES ('".$ID."','".$customer_name."','".$address."','".$currency."','".$contact_number."','".$email_address."','".$temp_amount."')") or die(mysql_error());
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^ HERE

You forgot the last bracket.

相关阅读:
Top