Reputation: 31
In PHP, I am attempting to insert sign up information into a database. I have worked through a bunch of errors and now I am not getting anything in my window after submitting the form and nothing writes to the database. The window comes up blank. I have researched answers but have found nothing to assist. I have re-written my VALUES statement several times using various techniques, both trying to use certain code characters and not using them. Characters include {}, [] and "" as well as ''.
I have not yet written statements to clean my data, I do realize this will be necessary, I just want to get the script functioning first.
The current code for my form resides in one file and my current PHP code resides in a different file which is referenced by the first file. Here is my current PHP code:
<?php
if (isset($_POST['submit']))
{
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$user_name = $_POST['user_name'];
$band_name = $_POST['band_name'];
$label_name = $_POST['label_name'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip_code = $_POST['zip_code'];
$email = $_POST['email'];
$confirm_email == ['email'];
$password = $_POST['password'];
$confirm_password == ['$password'];
$dbc = mysqli_connect('localhost', 'root', 'fishstench', 'Site Database.mwb.bak')
or die('Error connecting to MySQL server.');
$query = "INSERT INTO Users (User_ID, First_Name, Last_Name, User_Name, (SHA)Password, Email, Join_Date " .
"VALUES ('{$_POST[First_Name]}','{$_POST[Last_Name]}','{$_POST[User_Name]}','{$_POST[Password]},','{$_POST[Email]}','{$_POST[date]}')";
$query = "INSERT INTO Location (City, State, Zip_Code " .
"VALUES '{$_POST[City]}','{$_POST[State]}','{$_POST[Zip_Code]}')";
$query = "INSERT INTO Band_Name (Band_Name, Label_Name " .
"VALUES '{$_POST[Band_Name]}','{$_POST[Zip_Code]}')";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
mysqli_close($dbc);
echo 'Thanks for signing up!<br />';
} ?>
Upvotes: 2
Views: 109
Reputation: 5239
First, only the last query is gets executed, as you are overwriting the above 2 (I think that's not what you want?).
Check your $_POST
array if the submit(key)
is set, to pass the check, by using a var_dump
or print_r
just before the check.
if (isset($_POST['submit'])) {
....
}
These lines need to have assignment operator =
, instead of comparison operator ==
,
$confirm_email == ['email'];
$confirm_password == ['$password'];
Upvotes: 1
Reputation: 5443
You forgot a closing parenthesis in your first query. I think it should be:
$query = "INSERT INTO Users (User_ID, First_Name, Last_Name, User_Name, (SHA)Password, Email, Join_Date) " .
"VALUES ('{$_POST[First_Name]}','{$_POST[Last_Name]}','{$_POST[User_Name]}','{$_POST[Password]},','{$_POST[Email]}','{$_POST[date]}')";
Also, the parentheses in your other queries seem to be incorrect I think they should be:
$query = "INSERT INTO Location (City, State, Zip_Code) " .
"VALUES ('{$_POST[City]}','{$_POST[State]}','{$_POST[Zip_Code]}')";
$query = "INSERT INTO Band_Name (Band_Name, Label_Name) " .
"VALUES ('{$_POST[Band_Name]}','{$_POST[Zip_Code]}')";
In the future, to detect errors, check the result to see if there is an error:
$result = mysqli_query($query, $connection);
if (!$result) {
exit("mysqli_query() error: ", mysqli_error($connection), "\nquery was: $query\n");
}
Upvotes: 0