Reputation: 1
I'm having a problem with my data not going through to phpMyAdmin. The server and database connects the PHP but the data is not inserted into the table.
This is what I have so far.
<?php
$dbConnect = mysqli_connect("xxxxxxx", "xxxxx","xxxxx");
if (!$dbConnect)
die("<p>The database server is not available.</p>");
echo "<p>Successfully connected to the database server.</p>";
$dbSelect = mysqli_select_db( $dbConnect,"sxxxxxxx_db" );
if (!$dbSelect)
die("<p>The database is not available.</p>");
echo "<p>Successfully opened the database.</p>";
$sql = "INSERT INTO customer (Name,Password,Email,Phone) VALUES ('$_POST[namefield]', '$_POST[pwdfield]','$_POST[email]','$_POST[phone]' ) ";
mysqli_query($sql,$dbConnect);
mysqli_close($dbConnect);
if(isset($_POST['namefield']) && isset($_POST['pwdfield']) && isset($_POST['cpwdfield']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['submit']))
{
$name = $_POST['namefield'];
$password = $_POST['pwdfield'];
$cpassword = $_POST['cpwdfield'];
$email = $_POST['email'];
$phone = $_POST['phone'];
if ($_POST["pwdfield"] == $_POST["cpassword"])
mysqli_query("INSERT INTO user VALUES('','$password')") or die(mysqli_error());
else {
echo("Password did not match! Try again. ");
Upvotes: 0
Views: 2181
Reputation: 352
//Connect
$unsafe_variable = $_POST["user-input"];
$safe_variable = mysql_real_escape_string($unsafe_variable);
mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')");
//Disconnect
Upvotes: 1
Reputation: 1
change sql slightly
$sql = "INSERT INTO customer (Name,Password,Email,Phone) VALUES ('".$_POST['namefield']."', '".$_POST['pwdfield']."','".$_POST['email']."','".$_POST['phone']."' ) "
Upvotes: 0