I've started this with only name and email field and query did run successfully, as it's working fine I added more fields updating the code. But this time it's not working, taking me to the same page not giving me any error.
<?php
require "config.php";
if(isset($_POST['name']) && isset($_POST['address']) && isset($_POST['city']) && isset($_POST['postalcode']) && isset($_POST['country']) && isset($_POST['email']) && isset($_POST['datepicker']) && isset($_POST['phone'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$postalcode = $_POST['postalcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$birthday = $_POST['datepicker'];
$phone = $_POST['phone'];
$IP = $_SERVER['REMOTE_ADDR'];
$date = date('Y-m-d H:i:s');
if(!empty($name) && !empty($address) && !empty($city) && !empty($postalcode) && !empty($country) && !empty($email) && !empty($birthday) && !empty($phone)) {
$query = "INSERT INTO `users` (name, address, city, postalcode, country, email, birthday, phone, IP, date) VALUES ('$name', '$address', '$city', '$postalcode', '$country', '$email', '$birthday' '$phone', '$IP', '$date')";
$result = mysql_query($query);
if($result) {
echo "Registered Successfully";
} else {
echo "You're required to fill in all the fields.";
}
}
}
?>
<form action="join.php" method="POST">
<p> <label for="name">Name:</label>
<input type="text" name="name" > </p>
<p> <label for="address">Address:</label>
<input type="text" name="address" > </p>
<p> <label for="city">City:</label>
<input type="text" name="city" > </p>
<p> <label for="postalcode">Postal Code:</label>
<input type="text" name="postalcode" > </p>
<p> <label for="country">Country:</label>
<input type="text" name="country" > </p>
<p> <label for="email">Email:</label>
<input type="text" name="email" > </p>
<p> <label for="birthday">Birthday:</label>
<input type="text" name="birthday" > </p>
<p> <label for="phone">Phone:</label>
<input type="text" name="phone" > </p>
<input type="submit" value="order">
</form>
I've pasted the code here: http://codepad.org/BuRFV276
you do not have any field named 'datepicker'.
Just replace all $_POST['datepicker']
by $_POST['birthday']
and you have syntax error in insert query. You missed comma between $ birthday
and $ phone
Do not use mysql_*
since all mysql_*
functions are deprecated use mysqli
or PDO
instead.
You're missing a comma here, between the $birthday
and $phone
variables-
'$birthday' '$phone',
// ^ right there
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.