I've been trying to resolve this but i can't see the error. please help me. This is my code so far. What should i do? i checked every detail but cant find it. when i click the button, there's no error and it will return in the reservation.php page. I also have a "res_id" in my database which is auto increment. how should i include it in the insert statement?
Php code:
<?
$conn = mysqli_connect("localhost","root","") or die(mysql_error());
mysqli_select_db("hoteldb",$hoteldb) or die("no db found");
if(isset($_POST['confirm'])){
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$contact= $_POST['contact'];
$username= $_POST['username'];
$password= $_POST['password'];
$email= $_POST['email'];
$address= $_POST['address'];
$checkin= $_POST['checkin'];
$checkout= $_POST['checkout'];
$query="INSERT INTO reservation(fname,lname,contact,username,password,email,address,checkin,checkout)
VALUES ('$fname','$lname','$contact','$username','$password','$email','$address','$checkin','$checkout')";
mysql_query($query,$conn);
mysqli_close($conn);
}
?>
Html code:
<form action="reservation.php" method="post">
<div>
<label>Title:</label>
<select name="title">
<option value="ms">Ms.</option>
<option value="mr">Mr.</option>
<option value="mrs">Mrs.</option>
</select>
</div>
<div >
<label>First Name:</label>
<input type="text" name="fname">
</div>
<div>
<label>Last Name:</label>
<input type="text" name="lname">
</div>
<div>
<label>Phone Number:</label>
<input type="text" name="contact">
</div>
<div>
<label>Username:</label>
<input type="text" name="username" >
</div>
<div >
<label>Password:</label>
<input type="password" name="password" >
</div>
<div >
<label>Email Address:</label>
<input type="text" name="email" >
</div>
<hr>
<h5>Address</h5>
<div >
<label>Full Address:</label>
<input type="text" name="address" >
</div>
<hr>
<h5>Date</h5>
<div >
<legend>Check-in</legend>
<input type="date" name="checkin">
<legend>Checkout </legend>
<input type="date" name="checkout">
</div>
<input type="submit" name="confirm">
</form>
or is it because of the date picker? if so, can you please teach me how to use the date picker? its my first time using it. Thank you! :)
try to get error description: (add after $query's definition)
if (!mysqli_query($conn, $query)) {
echo("Error description: " . mysqli_error($conn));
}
Try turning on PHP errors to not get just an empty page.
http://php.net/manual/en/mysqli.query.php
mysql_query($query, $conn);
this should be
mysqli_query($conn, $query);
I also have a "res_id" in my database which is auto increment. how should i include it in the insert statement?
Since it's set to "auto increment", you dont need to do anything with it
Also, try looking at PDO, it's safer and takes less code to use.
When you connect to the database you use mysql, after this you are trying to insert data using mysqli_query, it is impossible. You have to replace
mysql_query($query,$conn);
with
mysqli_query($conn, $query);
so your php will look like this
<?
$conn = mysqli_connect("localhost","root","") or die(mysql_error());
mysqli_select_db("hoteldb",$hoteldb) or die("no db found");
if(isset($_POST['confirm'])){
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$contact= $_POST['contact'];
$username= $_POST['username'];
$password= $_POST['password'];
$email= $_POST['email'];
$address= $_POST['address'];
$checkin= $_POST['checkin'];
$checkout= $_POST['checkout'];
$query="INSERT INTO reservation(fname,lname,contact,username,password,email,address,checkin,checkout)
VALUES ('$fname','$lname','$contact','$username','$password','$email','$address','$checkin','$checkout')";
mysqli_query($conn, $query);
mysqli_close($conn);
}
?>
This is main problem.
You can use this templates any time u need insert something in your database
https://www.w3schools.com/php/php_mysql_insert.asp
If u want to use mysqli go to
Example (MySQLi Procedural) part
But I would recommend to use PDO;
The error in Mysqli_select_db statement.
You need correct your statement.
mysqli_select_db("hoteldb",$hoteldb) or die("no db found");
insted of this
mysqli_select_db($conn,"hoteldb") or die("no db found");
Related
I've small php project to list Covid-Test Labs, When you press the Update button for one of the records in the list of records, the data modification window opens, and when you enter it, the entries of other records are updated with the same information
How to solve this issue ?
<!-- Update Form -->
<form style = "font-size : 30px">
<input type="text" id="lab_name" class="fadeIn second" name="lab_name" placeholder="Laboratory Name" required>
<input type="text" id="test_price" class="fadeIn second" name="test_price" placeholder="Test Price" required>
<input type="text" id="lat" class="fadeIn second" name="lat" placeholder="Lat" required>
<input type="text" id="lon" class="fadeIn second" name="lon" placeholder="Lon" required>
<div class="dropdown">
<select name="lab_city" class="dropdown" required>
<option value="">--- Select City---</option>
<option value="Khartoum">Dubai</option>
<option value="Bahri">Bahri</option>
<option value="Omdurman">Paris</option>
</select>
<input type="file" name="image" id="image" required>
</div>
<input type="submit" id="submit" class="fadeIn fourth" value="Update">
</div>
</div>
</form>
<section>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "covidsd";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$lab_id = $_GET['lab_id'];
$lab_name= mysqli_real_escape_string($link, $_REQUEST['lab_name']);
$lab_city = mysqli_real_escape_string($link, $_REQUEST['lab_city']);
$test_price= mysqli_real_escape_string($link, $_REQUEST['test_price']);
$lat= mysqli_real_escape_string($link, $_REQUEST['lat']);
$lon= mysqli_real_escape_string($link, $_REQUEST['lon']);
$image= mysqli_real_escape_string($link, $_REQUEST['image']);
//$ServerURL = "http://192.168.43.236/AndroidUploadImage/$ImagePath";
$sql = "UPDATE laboratories SET lab_name ='$lab_name',lab_city ='$lab_city', test_price= '$test_price', lat='$lat', lon= '$lon', image= '$image' ". "WHERE lab_id='$lab_id' ";
if(mysqli_query($link, $sql)){
$message = "Laboratory has been updated successfully";
echo "<script type='text/javascript'>alert('$message');</script>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
I tried many solutions but not working
Each record in your table must have a unique id field. You will retrieve this field when loading your list. When modifying a record, you will send that id field again to PHP. Inside PHP you will use it in your SQL WHERE IdField=$ID.
You are using variable $lab_id In your PHP code $lab_id = $_GET['lab_id']; and this means that you have an input on your form with name lab_id. I can't see that input it in your HTML so you need to add it like that :
<form style = "font-size : 30px">
<input type="hidden" id="lab_id" name="lab_id" Value = "$lab_id">
<input type="text" id="lab_name" class="fadeIn second" name="lab_name" placeholder="Laboratory Name" required>
...............
...............
</form>
In your PHP code you must decide what kind of request you will accept either POST or GET. Now you are using a mix of $_GET and $_REQUEST. If you are modifying or inserting data, it will better to use $_POST. Getting variables is PHP code will looks like :
$lab_id = $_POST['lab_id'];
$lab_name= mysqli_real_escape_string($link, $_POST['lab_name']);
If you are using a framework which do the request, you can check it to make sure if it is sending lab_id, if it sends lab_id you will not need it inside form. You may also adjust the request type in your framework if you are using a one.
The problem I have: I made a "contact" form, which should send data to my database. All works good, no errors after I access the page from localhost, shows the result I wanted to see, but the database (localhost/phpmyadmin/..) doesn't update with any info.
This is my PHP:
if(isset($_POST['insert']))
{
$hostname = 'localhost';
$username = 'root';
$password = '';
$databaseName = 'nig';
$Nume = $_POST['nume'];
$Email = $_POST['email'];
$Telefon = $_POST['telefon'];
$Subiect = $_POST['subiect'];
$Mesaj = $_POST['mesaj'];
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$query = "INSERT INTO `amar` (`nume`, `email`, `telefon`, `subiect`, `mesaj`) VALUES ('$Nume','$Email','$Telefon','$Subiect','$Mesaj')";
$result = mysqli_query($connect,$query);
if($result)
{
echo 'Mesaj trimis.';
}else{
echo 'Mesaj netrimis';
}
mysqli_free_result($result);
mysqli_close($connect);
This is my HTML:
<form action="insert2.php" action="post">
<form role="form">
<div class="form-group">
<label for="nume">Nume complet</label>
<input type="text" class="form-control" name="nume">
</div>
<div class="form-group">
<label for="email">Adresa e-mail</label>
<input type="text" class="form-control" name="email">
</div>
<div class="form-group">
<label for="telefon">Telefon</label>
<input type="text" class="form-control" name="telefon">
</div>
<div class="form-group">
<label for="subiect">Subiect</label>
<input type="text" class="form-control" name="subiect">
</div>
<div class="form-group">
<label for="mesaj">Mesaj</label>
<textarea class="form-control" name="mesaj" rows="8"></textarea>
</div>
<input type="submit" name="insert" class="btn btn-theme" value="insert"></button>
</form>
And the result should be data in my MySQL. but the database isn't getting any data, what am I doing wrong?
You have two form tags, one inside the other.
Change this....
<form action="insert2.php" action="post">
<form role="form">
To this...
<form action="insert2.php" action="post">
Also, please note, your PHP code is open to SQL injection. Never trust user input. Always validate and/or escape user entered data prior to using it in a query. Or better yet, used prepared statements or stored procedures.
Update 1:
OK, sorry to hear this is not working. Please add the following mysqli error debugging so we can see what is happening.
Change this...
$result = mysqli_query($connect,$query);
To this...
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = mysqli_query($connect,$query)
if (!$result)) {
printf("Errormessage: %s\n", mysqli_error($connect));
}
Then run the code and see if you get any errors that may help us.
Update 2:
OK, try another piece of debugging.
After this...
$query = "INSERT INTO `amar` (`nume`, `email`, `telefon`, `subiect`, `mesaj`) VALUES ('$Nume','$Email','$Telefon','$Subiect','$Mesaj')";
Add this...
die($query);
Save and run the code.
You will be given a SQL query. Copy and paste that SQL query and run it in your database management tool (phpMyAdmin for example). See if the record is added when you manually run the query or if you are given any errors.
Let us know the outcome.
I have the tables users and register in my database. I've created a login page which starts a session using the users table, then people fill out a form to insert data into the register table. I've used the following code to insert the data. My code doesn't have errors but the thing is it is not inserted to my table. Please help me. Thanks.
<?php
include("includes/db.php");
session_start();
if(!isset($_SESSION['user_name'])){
header("location: login.php");
}
else { ?>
<html>
<body>
<h2>New users Signup!</h2>
<form action="login.php" method="post">
<input type="text" name = "firstname" placeholder="Firstname"/>
<input type="text" name = "lastname" placeholder="Lastname"/>
<input type="text" name = "address" placeholder="Address"/>
<input type="text" name = "contact" placeholder="Contact"/>
<input type="text" name = "email" placeholder="Email Address"/>
<input type="password" name = "password" placeholder="Password"/>
<div class = "bttn">
<button type="submit" name = "submit" class="btn btn-default">Signup</button>
</div>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$users_firstname = $_POST['firstname'];
$users_lastname = $_POST['lastname'];
$users_address = $_POST['address'];
$users_contact = $_POST['contact'];
$users_email = $_POST['email'];
$users_password = $_POST['password'];
$users_date = date('Y-m-d');
if($users_firstname=='' or $users_lastname=='' or $users_address=='' or $users_contact=='' or $users_email=='' or $users_password=='')
{
echo "<script>alert('Any of the fields is empty')</script>";
exit();
} else {
$insert_query = mysql_query("insert into users (users_firstname,users_lastname,users_address,users_contact,users_email,users_password,users_date) values ('$users_firstname','$users_lastname','$users_address','$users_contact','$users_email','$users_password','$users_date')");
$users_id=mysql_insert_id();
if(mysql_query($insert_query)) {
echo "<script>alert('post published successfuly')</script>";
}
}
}
} ?>
Now try this code:
<?php
include("includes/db.php");
session_start();
if(!isset($_SESSION['user_name'])){
header("location: login.php");
}
else {
?>
<html>
<body>
<?php
if(isset($_POST['submit']))
{
$users_firstname = $_POST['firstname'];
$users_lastname = $_POST['lastname'];
$users_address = $_POST['address'];
$users_contact = $_POST['contact'];
$users_email = $_POST['email'];
$users_password = $_POST['password'];
$users_date = date('Y-m-d');
if($users_firstname=='' or $users_lastname=='' or $users_address=='' or $users_contact=='' or $users_email=='' or $users_password=='')
{
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else
{
$insert_query = mysql_query("INSERT INTO `users` (users_firstname, users_lastname, users_address, users_contact, users_email, users_password, users_date) values ('$users_firstname', '$users_lastname', '$users_address', '$users_contact', '$users_email', '$users_password', '$users_date')");
$users_id=mysql_insert_id();
echo "<script>alert('post published successfuly')</script>";
}
}
?>
<h2>New users Signup!</h2>
<form action="" method="post">
<input type="text" name="firstname" placeholder="Firstname"/>
<input type="text" name="lastname" placeholder="Lastname"/>
<input type="text" name="address" placeholder="Address"/>
<input type="text" name="contact" placeholder="Contact"/>
<input type="text" name="email" placeholder="Email Address"/>
<input type="password" name="password" placeholder="Password"/>
<div class="bttn">
<button type="submit" name="submit" class="btn btn-default">Signup</button>
</div>
</form>
</body>
</html>
<?php } ?>
I have:
Repositioned your PHP code for inserting to be at the top of the form
changed <form action="login.php" to <form action="" because we are executing from the same page
Your query has already run so removed the if(mysql_query...
Removed the spaces in the form e.g. name = " nameofform" to name="nameofform"
I don't see any reason for having this $users_id=mysql_insert_id();, YOu should use auto-increment for the userID on your database
But since we don't know how you have connected to your database, because also that can be an issue: you can also try this way
<?php
//connect to DB
$hostname_localhost = "localhost"; //hostname if it is not localhost
$database_localhost = "databasename";
$username_localhost = "root"; //the username if it is not root
$password_localhost = "password_if_any"; //if no password leave empty
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
// include("includes/db.php");
if (!isset($_SESSION)) {
session_start();
}
if(!isset($_SESSION['user_name'])){
header("location: login.php");
}
else {
?>
<html>
<body>
<?php
if(isset($_POST['submit']))
{
$users_firstname = $_POST['firstname'];
$users_lastname = $_POST['lastname'];
$users_address = $_POST['address'];
$users_contact = $_POST['contact'];
$users_email = $_POST['email'];
$users_password = $_POST['password'];
$users_date = date('Y-m-d');
if($users_firstname=='' or $users_lastname=='' or $users_address=='' or $users_contact=='' or $users_email=='' or $users_password=='')
{
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else
{
$insert_query = sprintf("INSERT INTO `users` (users_firstname, users_lastname, users_address, users_contact, users_email, users_password, users_date) values ('$users_firstname', '$users_lastname', '$users_address', '$users_contact', '$users_email', '$users_password', '$users_date')");
mysql_select_db($database_localhost, $localhost);
$Result = mysql_query($insert_query, $localhost) or die(mysql_error());
echo "<script>alert('post published successfuly')</script>";
}
}
?>
<h2>New users Signup!</h2>
<form action="" method="post">
<input type="text" name="firstname" placeholder="Firstname"/>
<input type="text" name="lastname" placeholder="Lastname"/>
<input type="text" name="address" placeholder="Address"/>
<input type="text" name="contact" placeholder="Contact"/>
<input type="text" name="email" placeholder="Email Address"/>
<input type="password" name="password" placeholder="Password"/>
<div class = "bttn">
<button type="submit" name="submit" class="btn btn-default">Signup</button>
</div>
</form>
</body>
</html>
<?php } ?>
You should removed the whitespaces in your html-code:
Wrong
<input type="text" name = "firstname" placeholder="Firstname"/>
^^^^^
Correct
<input type="text" name="firstname" placeholder="Firstname"/>
Do not put the variables in single quotes:
$insert_query = mysql_query("INSERT INTO users
(users_firstname,users_lastname,users_address,users_contact,users_email,users_password,users_date)
VALUES
($users_firstname,$users_lastname,$users_address,$users_contact,$users_email,$users_password,$users_date)");
Update: This was wrong. The whole string is in double-quotes so the OP did correct and my notice was wrong. For information-purposes i will let stand the link to the documentation here.
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
Read more about single- and double-quotes in the PHP documentation.
Do not double-run the query/perform wrong function-call
$insert_query = mysql_query(".......");
........
if(mysql_query($insert_query)){
echo "<script>alert('post published successfuly')</script>";
}
You already have run the query in the first line. If you want to check if it was successful, you have to use if($insert_query) {}. The call mysql_query($insert_query) is wrong because mysql_query() returns a ressource instead of the sql-query.
Do not use mysql_*() function calls. You mysqli_*() instead.
Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_query()
PDO::query()
Check your use of session.
You are checking the $_SESSION for user_name and if it is not set, you are redirecting via header("location: login.php").
The problem is, that you are never inserting the user_name into the session, so it will always be not set.
You can set the value via $_SESSION['user_name'] = $_POST['user_name']. Have in mind that you have to set the session before checking the session-value. ;-)
remove action
Try this
<form action="" method="post">
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 7 years ago.
I have an issue with inserting the data that I gather from one of my forms into my database.
Each form adds data to a different table in the database(one into users and one into tasks).
I use one form for registration and I'll paste the important parts of the code below(this one is working).
This is the form part of the Register.php file
<form method="post" action="register_code.php">
<div class="FormElement">
<input name="user_name" type="text" class="Tfield" id="user_name" required placeholder="User Name">
</div>
<div class="FormElement">
<input name="password" type="password" class="Tfield" id="password" required placeholder="Password">
</div>
<div class="FormElement">
<input name="email" type="email" class="Tfield" id="email" required placeholder="E-mail">
</div>
<div class="FormElement">
<input name="first_name" type="text" class="Tfield" id="first_name" required placeholder="First Name">
</div>
<div class="FormElement">
<input name="last_name" type="text" class="Tfield" id="last_name" required placeholder="Last Name">
</div>
<div class="FormElement">
<input type="submit" id="Register" name="Register" value="Register" class="button">
</div>
This is the register_code.php file
<?php
require "DBconnect.php";
$post = $_POST;
if(isset($post)) {
session_start();
$UName = $post['user_name'];
$PW = md5($post['password']);
$FName = $post['first_name'];
$LName = $post['last_name'];
$Email = $post['email'];
$sql = $con->query("INSERT INTO users (user_name, password, email, first_name, last_name) VALUES ('$UName','$PW','$Email', '$FName', '$LName')");
if($sql)
header("Location: Registration_successful.php");
else
echo "Please try again to register";
}
include 'Register.php';
And another form I use to add data into another table(named tasks). The data I gather from this file will not insert into my database for some reason.
This is the form part of the Add_Task.php file:
<form method="post" action="Add_Task_code.php">
<div class="FormElement">
<input name="TName" type="text" class="Tfield" id="TName" required placeholder="Task name">
</div>
<div class="FormElement">
<input name="TDesc" type="text" class="TextField" id="TDesc" required placeholder="Task summary">
</div>
<div class="FormElement">
<input type="submit" id="Submit" name="Submit" value="Submit" class="button">
</div>
</form>
And this is the code from the Add_Task_code.php file
<?php
require 'DBconnect.php';
$post=$_POST;
if(isset($post))
{
$TaskName = $post['TName'];
$TaskDesc = $post['TDesc'];
$sqltask="INSERT INTO tasks ('TName','TDesc') VALUES ('$TaskName','$TaskDesc')";
if ($con->query($sqltask))
header("Location: Tasks.php");
else
header("Location: Add_Task.php");
}
?>
The file DBconnect.php only contains this:
<?php
$con= mysqli_connect("localhost", "root","","first_app")
?>
The problem is that even though the code is similar in both forms only one of them is working. Every time I run the Add_Task.php file it redirects me to the same page (as I instructed it) since it does not add anything to the database.
I also checked the tables just in case it adds something but it does not.
please set your primary_key(id) as auto increment in table tasks. if you not set it might be possible.
and change this line
$sqltask="INSERT INTO tasks ('TName','TDesc') VALUES ('$TaskName','$TaskDesc')";
like this :
$sqltask="INSERT INTO tasks (TName,TDesc) VALUES ($TaskName,$TaskDesc)";
You are mixing OOP style and Procedural Style in your code
You are used Procedural Style in your DBconnect.php file. And You are missing ; in your connection file.
DBconnect.php file should be:
<?php
$con= mysqli_connect("localhost", "root","","first_app");
?>
register_code.php code should be:
<?php
require "DBconnect.php";
$post = $_POST;
if(isset($post)) {
session_start();
$UName = $post['user_name'];
$PW = md5($post['password']);
$FName = $post['first_name'];
$LName = $post['last_name'];
$Email = $post['email'];
$sql = mysqli_query($con,"INSERT INTO users (user_name, password, email, first_name, last_name) VALUES ('$UName','$PW','$Email', '$FName', '$LName')");
if($sql)
header("Location: Registration_successful.php");
else
echo "Please try again to register";
}
include 'Register.php';
Add_Task_code.php file code should be:
<?php
require 'DBconnect.php';
$post=$_POST;
if(isset($post))
{
$TaskName = $post['TName'];
$TaskDesc = $post['TDesc'];
$sqltask="INSERT INTO tasks ('TName','TDesc') VALUES ('$TaskName','$TaskDesc')";
if (mysqli_query($con,$sqltask))
header("Location: Tasks.php");
else
header("Location: Add_Task.php");
}
?>
Try to make the below changes and see what the actual error is.then debug your code.
if($_SERVER['REQUEST_METHOD']=='POST')
{
$TaskName = $post['TName'];
$TaskDesc = $post['TDesc'];
$sqltask="INSERT INTO tasks ('TName','TDesc') VALUES ('$TaskName','$TaskDesc')";
if ($con->query($sqltask))
echo "Successfully Inserted";
else
echo "Error: " . $sqltask. "<br>" . mysqli_error($conn);
}
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, while I was trying to get some data into my database, I came across this problem, of which I have no clue how to fix it. It just gives no output at all. I am a total newbie to php and database registering. I am able to do some sql.
Also, while I was testing some stuff I came to the conclusion that when I have a small database(just user, email and password) I am able to insert some data into the database. That's why I made two separate databases.
Info about the db:
- Called datingsite
- two tables: 'User' and 'Eigenschappen'
- Both tables have a 'Lidnummer'(INT. Max 255) and set to index and AI
I am using portable xampp 1.8.3
Code:
Connect.php:
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysqli_select_db($connection,'datingsite');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>
Register.php:
<?php
require('connect.php');
/* If the values are posted, insert them into the database.
$sql = "SELECT * FROM `user`";
$res = mysql_query($sql);
$row = mysql_fetch_array($res) or die(mysql_error());
echo $row['email']. " - ". $row['wachtwoord'];*/
if (isset($_POST['email']) && isset($_POST['wachtwoord'])){
$email = $_POST['email'];
$wachtwoord = $_POST['wachtwoord'];
$Voornaam = $_POST['Voornaam'];
$Tweedenaam = $_POST['Tweedenaam'];
$Achternaam = $_POST['Achternaam'];
$Ben = $_POST['Ben'];
$Zoek = $_POST['Zoek'];
$Woonplaats = $_POST['Woonplaats'];
$Provincie = $_POST['Provincie'];
$Hobby1 = $_POST['Hobby1'];
$Hobby2 = $_POST['Hobby2'];
$Dag = $_POST['Dag'];
$Maand = $_POST['Maand'];
$Jaar = $_POST['Jaar'];
$Opleiding = $_POST['Opleiding'];
$query = "INSERT INTO 'user' ('Email', 'Wachtwoord', 'Voornaam', 'Tweedenaam', 'Achternaam', 'Ben', 'Zoek', 'Ingelogd')
VALUES (
'$email',
'$wachtwoord',
'$Voornaam',
'$Tweedenaam',
'$Achternaam',
'$Ben',
'$Zoek')";
$query2 = "INSERT INTO 'Eigenschappen' ('Woonplaats', 'Provincie', 'Hobby1', 'Hobby2', 'Dag', 'Maand', 'Jaar', 'Opleiding')
VALUES (
'$Woonplaats',
'$Provincie',
'$Hobby1',
'$Hobby2',
'$Dag',
'$Maand',
'$Jaar',
'$Opleiding')";
$result = mysql_query($query);
$res = mysql_query($query2);
if(($result)&($res)){
$msg = "User Created Successfully.";
}
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8" />
<title>Registreren op Chives</title>
<link href="../Css/inlog.css" rel="stylesheet"/>
<link href="../Css/styles.css" rel="stylesheet" />
</head>
<body class="back">
<?php
if(isset($msg) & !empty($msg)){
echo $msg;
}
?>
<div id="Inlog-Container" align="center">
<form action="" method="post">
<H1> Registreren </H1>
<H2> Email:</H2>
<input name="email" type="email" class="Input-box" required/>
<H2> Wachtwoord:</H2>
<input name="wachtwoord" type="password" class="Input-box" required/>
<div class="Radiolabelbox">
<fieldset class="" id="" >
<H2>Ik ben een:</H2>
<div class="Radiolabel">
<label>
<input type="radio" name="Ben" class="styled-radio" value="Man" required/>
Man
</label> <br />
<label>
<input type="radio" name="Ben" class="styled-radio" value="Vrouw"/>
Vrouw
</label>
</div>
</fieldset>
<fieldset class="">
<H2 class="">Ik zoek een:</H2>
<div class="Radiolabel">
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Man" required/>
Man
</label>
<br />
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Vrouw"/>
Vrouw
</label>
<br />
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Beide"/>
Beide
</label>
</div>
</fieldset>
</div>
<H2> Woonplaats:</H2>
<input name="Woonplaats" type="text" class="Input-box" required/>
<H2> Provincie:</H2>
<input name="Provincie" type="text" class="Input-box" required/>
<H2> Hobby 1:</H2>
<input name="Hobby1" type="text" class="Input-box" required/>
<H2> Hobby 2:</H2>
<input name="Hobby2" type="text" class="Input-box" required/>
<H2> Voornaam:</H2>
<input name="Voornaam" type="text" class="Input-box" required/>
<H2> Tweede naam:</H2>
<input name="Tweedenaam" type="text" class="Input-box" required/>
<H2> Achternaam:</H2>
<input name="Achternaam" type="text" class="Input-box" required/>
<H2> Geboortedag:</H2>
<input name="Dag" type="Number" class="Input-box" min="0" max="31" required/>
<H2> Geboortemaand:</H2>
<input name="Maand" type="Number" class="Input-box" min="0" max="12" required/>
<H2> Geboortejaar:</H2>
<input name="Jaar" type="Number" class="Input-box" min="1920" max="2000" required/>
<H2> Opleiding:</H2>
<input name="Opleiding" type="Text" class="Input-box" required/>
<input type="submit" value="GA VERDER" class="Roundbutton" id="Login" />
</form>
</div>
</body>
</html>
How can I get to fix my code so I can register into my database?
Any help is appreciated! Thanks in advance!
Ps. I'm sorry for the fact that most of the text in my code is in dutch.
First of all in insert statement use quotes only for text data, number don't need them, and neither table name need them
In if statement if(($result)&($res)) you are using bitwise operator rather you should use if(($result) && ($res)).
Similarly if(isset($msg) & !empty($msg)) here. It should be if(isset($msg) && !empty($msg))
Multiple problems seems in your code:
you are opening a mysqli_connection and using mysql_
$result = mysql_query($query); to run query. That is wrong.
It must be
$result = mysqli_query($connection, $query);
same for
$res = mysql_query($query2);
must be
$res = mysqli_query($connection, $query2);
php mysqli query : http://php.net/manual/en/mysqli.query.php
Check Procedural style in the above link for executing a php mysqli query.
Next:
You dont need ' (quotes) between your table field names when calling an insert query.
But your insert query contains quotes.
Please refer http://www.w3schools.com/php/php_mysql_insert.asp for php mysql insert statement.
Next:
Error in using AND operator
if(($result) & ($res))
Must be
if(($result) && ($res))
(Pointed out be Moid Mohd in his answer)
You have error in your first insert query.You mentioned eight columns but insert only seven values.
Please check and correct it.