I've successfully login with a user account and now i will like to insert records. As below is the code that has not been successful in inserting record.
<?php
session_start();
echo "Welcome: ". $_SESSION['role'];
?>
<?php
error_reporting(0);
if (!$_POST['submit'])
{
?
<html>
<body>
<br><br>
<fieldset >
Add a new user
<br>
<br>
<label for='username'>Username: </label>
<input type='text' name='username' id='username'/>
<label for='password'>Password: </label>
<input type='password' name='password' id='password' maxlength="50" />
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Role:
<br>
<select name="role">
<option value="" selected="selected"></option>
<option VALUE="Administrator"> Administrator</option>
<option VALUE="Secretary"> Secretary</option>
<option VALUE="Employee"> Employee</option>
</select>
<input type='submit' name='Submit' value='Submit' />
</form>
</fieldset>
<table width=100%>
</html>
</body>
<?php
}
else
{
$conn=odbc_connect("employee","","") or die (odbc_errormsg());
if (!$conn)
{
exit
("Connection Failed: " . $conn);
}
$query = "INSERT INTO empTable (empID, password, Role, Days left in MC, Days left in leave) VALUES" .
"('$_POST[username]', '$_POST[password]', '$_POST[role]', 14, 14)";
$result=odbc_exec($conn,$query) or die ("result error ".odbc_error().'-'.odbc_errormsg());
odbc_fetch_row($result);
odbc_close($conn);
}
After clicking the submit button and when i refresh my database, nothing comes out. Why is that so? Thanks alot
Access doesn't like column names with blanks. You have to mask them with [ ].
Change your INSERT query like this:
$query = "INSERT INTO empTable (empID, password, Role, [Days left in MC], [Days left in leave]) VALUES ..."
Related
<?php
$conn=mysqli_connect("localhost","root","","fesdb");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
if (isset($_POST['Insert']))
{
$txt = $_POST['text1'];
}
{
$query = "insert into table (Mytext) VALUES ('$txt')";
$result = mysqli_query($conn,$query);
if($result)
{
echo '<script>alert("record inserted")</script>';
}
else
{
echo ' Please Check Your Query ';
}
}
?>
<html>
<body>
<form action="" id="myForm" >
<input type='text' name="text1"><br>
<input type='text' name="text2"><br>
<input type='text' name="text3"><br>
<input type='text' name="text4"><br>
<input type='text' name="text5"><br>
<input type='text' name="text6"><br>
<input type='text' name="text7"><br>
<input type='text' name="text8"><br>
<input type='text' name="text9"><br>
<input type='text' name="text10"><br>
<input type='submit' name="Insert">
</form>
</body>
</html>
I am a beginner in PHP .. I have sql database with one Table , this table have one column .... I have 10 textboxes in my page with one button ... I want to insert each textbox into the table as separated record ... I know I should use loop (for each ...) to solve this problem ... but I dont know how do that ...
if possible help me with a sample
Im trying to save a variable in the $_Session[deptselect] and call it in a different page but confused to where to declare it. when i echo $_Session[deptselect] it gives blank.
I have already tried in multiple places like inside the form or below it but nothing seems to work. i want to send it from appointment to appointment2 but appointment2 seems to not get the variable.
I have already tried to use $_post[deptselect] to get the value in second page and i get it there but it disappears as soon as i press submit in the second page.
appointment.php
<?php
include("dbconnection.php");
session_start();
if(!isset($_SESSION['username'])) {
die("Please login");
}
$_SESSION['deptselect']=$_POST['deptselect'];
?>
<form class="" action="appointment2.php" method="post">
<fieldset>
<legend>Appointment</legend>
<label>Select Department</label>
<select class="" name="deptselect" required>
<option ></option>
<?php
$deptsql=mysqli_query($con,"select deptname,deptid from department where status='1'");
while ($row = mysqli_fetch_assoc($deptsql))
{
echo "<option id='deptselect' value='" . $row['deptid'] ."'>" . $row['deptname'] ."</option>";
}
?>
</select>
</fieldset>
<input type="submit" name="submit" value="Submit">
</form>
<?php
include("footer.php");
?>
appointment2.php
<?php
session_start();
if(!isset($_SESSION['username']))
{
include('footer.php');
die("Please login");
}
if(!empty($_POST)){
include("dbconnection.php");
$dept=$_SESSION['deptselect'];
echo $dept;
$daate=$_POST['date'];
$doc = $_POST['doc'];
$tiime=$_POST['time'];
$user=$_SESSION['username'];
$pd="SELECT * from patient where name='$user'";
$pid=mysqli_query($con,$pd);
while($row = mysqli_fetch_assoc($pid)){
$piid=$row['pid'];
}
$query="insert into appointment (deptid, docempid,pid,apptime,appdate) VALUES ('$dept','$doc','$piid','$tiime','$daate') " ;
//$res=mysqli_query($con,$query);
// echo "$query";
//echo "$dept";
}
?>
<body>
<form class="" action="appointment2.php" method="post">
<label>Select doctor</label>
<select class="" name="doc" >
<option ></option>
<?php
$dee=$_POST['deptselect'];
$_SESSION['id']=$dee;
$sql="SELECT * FROM doctor where deptid='$dee'";
$docsql= mysqli_query($con,$sql);
while ($row = mysqli_fetch_assoc($docsql))
{
echo "<option value='" . $row['docempid'] ."'>" . $row['name'] ."</option>";
}
?>
</select>
<br><br><br>
<label>Enter Time</label>
<input type="time" name="time" placeholder="enter time" >
<br><br><br>
<label>Enter date</label>
<input type="date" name="date" placeholder="enter date" >
<br> <br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
<?php include("footer.php");
?>
I want the $_session[deptselect] in appointment2.php so i can run the command the insert, i have zero knowledge of js so doing the dependent list thing is not possible. TIA
In the beginning of the first script you have:
if(!isset($_SESSION['username'])) {
die("Please login");
}
And in the beginning of the second:
if(!isset($_SESSION['username']))
{
include('footer.php');
die("Please login");
}
Both stop immediately, if $_SESSION['username'] is not set.
So how should $_SESSION['username'] ever be set, if your body code is never executed?
I am working on my project for school and is now stuck on this problem that I hope someone here my point me in the right direction.
I am designing a booking system which uses a web front and MySQL database. I have a few tables: Customers, Seats, Price, Booking and Screening. I am trying to insert data into the booking table from the other tables using there primary keys. however I keep getting the following error message: Incorrect integer value: '' for column 'customerid' at row 1
I have search every where but doesn't seem to get any solution. I have copied my code below.
<?php
$customerid=$_POST['customerid'];
$screeningid=$_POST['screeningid'];
$seatid=$_POST['seatid'];
$priceid=$_POST['priceid'];
$status=$_POST['status'];
$query = "INSERT INTO `booking`(bookingid, customerid, screeningid, seatid, priceid, bookingdate, status)
VALUES(NULL, '". mysql_real_escape_string($customerid)."', '". mysql_real_escape_string($screeningid)."', '". mysql_real_escape_string($seatid)."','". mysql_real_escape_string($priceid)."', 'DateTime()', '". mysql_real_escape_string($status)."')";
$result=mysql_query($query) or die (mysql_error());
// if successfully insert data into database, displays message "Successful".
if($result)
{
echo "<p>success</p>";
echo "<BR>";
}
else
{
echo mysql_error();
}
?>
This is my Form:
<div id="content">
<h2>Enter Booking Details Below</h2>
<form name="reg_form" action="bookingecho.php?action=add type=booking" onsubmit="return validate_reg()" method="POST" >
<table>
<tr>
<td>Customer</td>
<td> <select name="customerid">
<?php
//Perform database query
$query = ("SELECT * FROM customers
ORDER BY customerid DESC");
$result = mysql_query($query, $connection) or die (mysql_error());
// populate the select options with the results
while ($row = mysql_fetch_assoc($result))
{
//extract column
$customerid = $row['customerid'];
$fname = $row['fname'];
$lname = $row['lname'];
$telephone = $row['telephone'];
//use
echo "<option value>$customerid $fname $lname $telephone</option>";
}
?>
</select></td></tr>
<tr>
<td>Screening</td>
<td> <select name="screeningid">
<?php
//Perform database query
$query = ("SELECT * FROM screening");
$result = mysql_query($query, $connection) or die (mysql_error());
// populate the select options with the results
while ($row = mysql_fetch_assoc($result))
{
//extract column
$screeningid = $row['screeningid'];
$day = $row['day'];
$screeningdate = $row['screeningdate'];
$filmtitle = $row['filmtitle'];
//use
echo "<option value>$screeningid $day $screeningdate $filmtitle</option>";
}
?>
</select></td></tr>
<tr>
<td>Seat</td>
<td> <select name="seatid">
<?php
//Perform database query
$query = ("SELECT seats.seatid, seats.seatnumber, seats.seatclass
FROM seats
WHERE seatid
NOT IN (SELECT seatid FROM booking
WHERE screeningid = '$screeningid')
ORDER BY `Seats`.`seatid` ASC");
$result = mysql_query($query, $connection) or die (mysql_error());
// populate the select options with the results
while ($row = mysql_fetch_assoc($result))
{
//extract column
$seatid = $row['seatid'];
$seatnumber = $row['seatnumber'];
$seatclass = $row['seatclass'];
//use
echo "<option value>$seatid $seatnumber $seatclass</option>";
}
?>
</select></td></tr>
<tr>
<td>Concession</td>
<td> <select name="priceid">
<?php
//Perform database query
$query = ("SELECT * FROM price");
$result = mysql_query($query, $connection) or die (mysql_error());
// populate the select options with the results
while ($row = mysql_fetch_assoc($result))
{
//extract column
$priceid = $row['priceid'];
$concession = $row['concession'];
$cost = $row['cost'];
//use
echo "<option value>$priceid $concession $cost</option>";
}
?>
</select></td></tr>
<tr>
<td>Status</td>
<td>
<input type= radio name="status" value="Booked"> Booked
<input type= radio name="status" value="Reserved"> Reserved
</td>
</tr>
</select></td></tr>
</table>
<p align="center">
<td><input type="submit" name="submit" id= "submit" value="Add"/></td>
<input type="reset" value="Reset Form">
</p>
</form>
</div>
Use intval() for integer values.
Use mysql_real_escape_string on strings, Never for integers.
Single quotes around integer values in a mySQL query is optional.
Because intval() guarantees $customerid is an integer value, the quotes are not necessary and will never generate an error.
I have only included the two lines of code directly related to your customer id. The same likely applies to the other values as well.
$customerid=intval($_POST['customerid']);
$query = "INSERT INTO `booking`
(`bookingid`, `customerid`, `screeningid`,`seatid`,`priceid`, `bookingdate`, `status`)
VALUES(NULL,$customerid,'$screeningid','$seatid','$priceid',CURDATE(),'$status')";
Change:
<input name="status" value="Booked" type="radio"> Booked
<input name="status" value="Reserved" type="radio"> Reserved
To:
<input name="status" value="1" type="radio"> Booked
<input name="status" value="2" type="radio"> Reserved
Always submit integer values greater then zero whenever possible. They are easy to validate. To get the text back:
$statuses = array('unknown','booked','reserved')
$strStatus = $statuses[$status];
UPDATE FOREIGN KEY CONSTRAINT ERROR
A CONSTRAINT ERROR says you do not have a customer record for the added booking table. Or the foreign key is wrong. The foreign key is not needed.
You could combine the customer add, lookup and booking INSERT at the same time.
Rather than some sort of login to create or retrieve the customer record get the booking then during the last step in the booking process just ask for the phone number. Personally I do not care if someone were to query the system with my phone number and found out which seat I have. Some might. But asking for a a login in before getting the booking is a nuisance and a road block to finalizing the booking.
What I did was add the security ID
If they want to secure their seats with a password let it be their choice.
If the record does not exist, then ask for their name AFTER the seats are booked.
//$customerid = intval($_POST['customerid']);
$screeningid = intval($_POST['screeningid']);
$seatid = intval($_POST['seatid']);
$priceid = intval($_POST['priceid']);
$status = intval($_POST['status']);
$fname = mysql_real_escape_string($_POST['status']);
$lname = mysql_real_escape_string($_POST['lname']);
$telephone = intval(preg_replace('/[^D]/','',$_POST['telephone']));
//must have UNIQUE Index on `telephone`
$sql = "INSERT INTO `customer` (`customerid`,`fname`, `lname`, `telephone`)
VALUES(NULL,'', '', $telephone)";
$result = mysql_query($sql);
if(mysql_insert_id()){
$customerid = mysql_insert_id();
}
else{
list($customerid, $fname`, $lname,$id) = mysql_fetch_array(mysql_query(
"SELECT `customerid`,`fname`, `lname`, `telephone`,`id`
FROM `customer` WHERE `telephone`=$telephone"),MYSQL_NUM);
}
$query = "INSERT INTO `booking`
(`bookingid`, `customerid`, `screeningid`,`seatid`,`priceid`, `bookingdate`, `status`)
VALUES(NULL,$customerid,$screeningid,$seatid,$priceid,CURDATE(),$status)";
echo <<<EOT
<p>Your seats are booked.</p>
<form action="update.php" method="post">
<label>Last:</label>
<input type="text" name="lname" value="$lname" />
<br/>
<label>First:</label>
<input type="text" name="fname" value="$fname" />
<br/>
<label>Phone:</label>
<input type="tel" name="telephone" value="$telephone" />
<br/>
<p class="footnote">Security ID is optional</p>
<label>Security ID:</label>
<input type="text" name="id" value="$id" />
<br/>
<input type="hidden" name="phone" value="$telephone" />
<br/>
<div class="footnote">
If you want to keep your booking secure then enter a security id.
<br>If blank, no security ID will be necessary to retrieve your seats in the future.
<br/>This can be any number (e.g. PIN) word, or any characters.
<br/>Maximum 16 characters.</p>
<p>Do NOT use an existing high security password (e.g. your banking password)</p>
<h4>If you would like your seats sent to you via text,<br/>Select your mobile carrier<br/>This will also verify you entered the correct phone number</h4>
</div>
<label>Mobile Carrier</label>
<select>
<option value="">No Text / Land Line</option>
<option value="#message.alltel.com">Alltel</option>
<option value="#paging.acswireless.com">Ameritech</option>
<option value="#mmode.com">ATT Wireless</option>
<option value="#bellsouth.cl">Bellsouth</option>
<option value="#myboostmobile.com">Boost</option>
<option value="#mobile.celloneusa.com">CellularOne</option>
<option value="#mobile.mycingular.com">Cingular</option>
<option value="#sms.edgewireless.com">Edge Wireless</option>
<option value="#mymetropcs.com">Metro PCS</option>
<option value="#messaging.nextel.com">Nextel</option>
<option value="#mobile.celloneusa.com">O2</option>
<option value="#mobile.celloneusa.com">Orange</option>
<option value="#qwestmp.com">Qwest</option>
<option value="#pcs.rogers.com">Rogers Wireless</option>
<option value="#messaging.sprintpcs.com">Sprint PCS</option>
<option value="#teleflip.com">Teleflip</option>
</optgroup>
<option value="#msg.telus.com">Telus Mobility</option>
<option value="#email.uscc.net">US Cellular</option>
<option value="#vtext.com">Verizon</option>
</select>
<br/>
<input type="submit" value="Save Changes" />
</form>
EOT;
FORM SNIPPET
label {
width: 5em;
display: inline-block;
text-align: right;
}
.footnote {
margin: .5em 0 .5em 5em;
}
input[type="submit"] {
margin: 1em 6em;
}
h4 {
margin-bottom: 0;
}
<p>Your seats are booked.</p>
<form action="update.php" method="post">
<label>Last:</label>
<input type="text" name="lname" value="$lname" />
<br/>
<label>First:</label>
<input type="text" name="fname" value="$fname" />
<br/>
<label>Phone:</label>
<input type="tel" name="telephone" value="$telephone" />
<br/>
<p class="footnote">Security ID is optional</p>
<label>Security ID:</label>
<input type="text" name="id" value="$id" />
<br/>
<input type="hidden" name="phone" value="$telephone" />
<br/>
<div class="footnote">
If you want to keep your booking secure then enter a security id.
<br>If blank, no security ID will be necessary to retrieve your seats in the future.
<br/>This can be any number (e.g. PIN) word, or any characters.
<br/>Maximum 16 characters.</p>
<p>Do NOT use an existing high security password (e.g. your banking password)</p>
<h4>If you would like your seats sent to you via text,<br/>Select your mobile carrier<br/>This will also verify you entered the correct phone number</h4>
</div>
<label>Mobile Carrier</label>
<select>
<option value="">No Text / Land Line</option>
<option value="#message.alltel.com">Alltel</option>
<option value="#paging.acswireless.com">Ameritech</option>
<option value="#mmode.com">ATT Wireless</option>
<option value="#bellsouth.cl">Bellsouth</option>
<option value="#myboostmobile.com">Boost</option>
<option value="#mobile.celloneusa.com">CellularOne</option>
<option value="#mobile.mycingular.com">Cingular</option>
<option value="#sms.edgewireless.com">Edge Wireless</option>
<option value="#mymetropcs.com">Metro PCS</option>
<option value="#messaging.nextel.com">Nextel</option>
<option value="#mobile.celloneusa.com">O2</option>
<option value="#mobile.celloneusa.com">Orange</option>
<option value="#qwestmp.com">Qwest</option>
<option value="#pcs.rogers.com">Rogers Wireless</option>
<option value="#messaging.sprintpcs.com">Sprint PCS</option>
<option value="#teleflip.com">Teleflip</option>
</optgroup>
<option value="#msg.telus.com">Telus Mobility</option>
<option value="#email.uscc.net">US Cellular</option>
<option value="#vtext.com">Verizon</option>
</select>
<br/>
<input type="submit" value="Save Changes" />
</form>
The error message means you are getting an "empty string" ('') for customerid, which simply means that your first chunk of code is not getting any value at all for that field when the form is submitted.
Here is the problem:
echo "<option value>$customerid $fname $lname $telephone</option>";
The values between <option> and </option> are what will be displayed to the end-user, but they will not be submitted with your form, which means they won't be available to that first chunk of code.
To submit the customerid, you have to put it into the value part:
echo "<option value=$customerid>$customerid $fname $lname $telephone</option>";
You placed apostrophes around $customerid (and other non-string values) when it is actually an integer inside your database. Delete the apostropes (') around all values that are meant to be integers in your database (I have a feeling that is the case for many of your variables). Also please organize your code because it was extremely difficult to look at it without crying :)
<?php
$customerid=mysql_real_escape_string($_POST['customerid']);
$screeningid=$_POST['screeningid'];
$seatid=mysql_real_escape_string($_POST['seatid']);
$priceid=mysql_real_escape_string($_POST['priceid']);
$status=mysql_real_escape_string($_POST['status']);
$query = "INSERT INTO `booking`(bookingid, customerid,
screeningid, seatid, priceid, bookingdate, status)
VALUES (NULL, ". $customerid.", ". $screeningid.", ".
$seatid.", ".$priceid.", 'DateTime()', '".$status."')";
$result=mysql_query($query) or die (mysql_error());
// if successfully insert data into database, displays message "Successful".
if($result)
{
echo "<p>success</p><br>";
}
else
{
echo mysql_error();
}
?>
Also note, DateTime() is a php function, not an SQL command. I left it in the previous code but be aware that you should fix that error.
Let me know if this worked for you.
So I'm making a complaints page for a school project. I started off with a simple PHP form, which worked until I added a
if(isset($_POST['submit'])){ PHP code to be executed here }
Which didnt work anymore. So I decided to remove that line all together; and whenever I submit any form now, it fills in my MYsql table with 1's even though I am filling the text boxes of the form with text. I don't know if this a problem in mySQL configuration, I have another form that is suffering from the same issue.
I will describe the issue in more details below.
How my "Klacht" Table currently looks like (Excuse my links issue.. I can't post pictures because I dont have more than 10 reps..)
http://i.gyazo.com/6589558c59c4955f5cd48c335d79bdac.png
The structure of it
http://gyazo.com/51ab9d9184a4beb2197ce41f0b98b35b
My form code is a .php file, and I don't get a preview of my PHP code upon pressing the submit button. It just echos the message
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Prototype</title>
</head>
<body>
<h3>Klacht test</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br />Test nummer: <input type="text" name="Nr">
<br />Postcode<input type="text" name="Postcode">
<br />Datum<input type="Date" name="Datum">
<br />Tijd<input type="text" name="Tijd" >
<br />Soort klacht
<select name="Soort">
<option value=" "></option>
<option value="Geluid">Geluid</option>
<option value="Milieu">Milieu</option>
<option value="Veiligheid">Veiligheid</option>
</select>
<!-- Submit button -->
<br /><input type="submit" value="Versturen">
<input type="reset" value="Reset">
</form>
</body>
<?php
mysql_connect("localhost", "root", "") or die ("Could not connect to database");
mysql_select_db("schiphol") or die("could not select database");
$Nr = isset($_POST["Nr"]);
$Postcode = isset($_POST["Postcode"]);
$Datum = isset($_POST["Datum"]);
$Tijd = isset($_POST["Tijd"]);
$Soort = isset($_POST["Soort"]);
$query = ("INSERT INTO klacht (Nr, Postcode, Datum, Tijd, Soort)
VALUES ('$Nr', '$Postcode', '$Datum', '$Tijd', '$Soort')");
$resultaat = mysql_query($query) or die (mysql_error( ));
if($resultaat) echo "Uw klacht is toegevoegd" ; else echo "ERROR";
?>
</html>
So.. What am I doing wrong? As I mentioned above, another form is suffering from the same issue. It used to work but doesn't anymore.
Thanks in advance.
Your problem on isset() it return 0 or 1
You use blow code
<input type="submit" value="Versturen">
but you forgot to mention name
<input type="submit" name="submit" value="Versturen">
Try this it will work
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Prototype</title>
</head>
<body>
<h3>Klacht test</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br />Test nummer: <input type="text" name="Nr">
<br />Postcode<input type="text" name="Postcode">
<br />Datum<input type="Date" name="Datum">
<br />Tijd<input type="text" name="Tijd" >
<br />Soort klacht
<select name="Soort">
<option value=""></option>
<option value="Geluid">Geluid</option>
<option value="Milieu">Milieu</option>
<option value="Veiligheid">Veiligheid</option>
</select>
<!-- Submit button -->
<br /><input type="submit" name="submit" value="Versturen">
<input type="reset" value="Reset">
</form>
</body>
<?php
if(isset($_POST['submit'])){
echo "<pre/>";
print_r($_POST);
//die;
mysql_connect("localhost", "root", "") or die ("Could not connect to database");
mysql_select_db("schiphol") or die("could not select database");
$Nr = $_POST["Nr"];
$Postcode = $_POST["Postcode"];
$Datum = $_POST["Datum"];
$Tijd = $_POST["Tijd"];
$Soort = $_POST["Soort"];
$query = ("INSERT INTO klacht (Nr, Postcode, Datum, Tijd, Soort) VALUES ('$Nr', '$Postcode', '$Datum', '$Tijd', '$Soort')");
echo $query;
$resultaat = mysql_query($query) or die (mysql_error( ));
if($resultaat) echo "Uw klacht is toegevoegd" ; else echo "ERROR";
}
?>
Hi I think your problem is with isset() funtion. Actually isset() funtion will return a Boolean value based 1 or 0 . so please update your php section without isset() like below and try.
<?php
mysql_connect("localhost", "root", "") or die ("Could not connect to database");
mysql_select_db("schiphol") or die("could not select database");
$Nr =$_POST["Nr"];
$Postcode =$_POST["Postcode"];
$Datum = $_POST["Datum"];
$Tijd = $_POST["Tijd"];
$Soort = $_POST["Soort"];
$query = ("INSERT INTO klacht (Nr, Postcode, Datum, Tijd, Soort)
VALUES ('$Nr', '$Postcode', '$Datum', '$Tijd', '$Soort')");
$resultaat = mysql_query($query) or die (mysql_error( ));
if($resultaat) echo "Uw klacht is toegevoegd" ; else echo "ERROR";
?>
$var = is set($_POST['some_var']); // this will just return a 1 to $var if the post variable is set
Try this instead
if(isset($_POST['var'])){ $db_var = $_POST['var'];}
The following if(isset($_POST['submit'])){ PHP code to be executed here } did not work because you did not give a name to your button
<input type="submit" value="Versturen">
also as #Azeez Kallayi pointed out isset() returns boolean value.
Try this:
<?php
if(isset($_POST["Nr"],$_POST["Postcode"],$_POST["Datum]",$_POST["Tijd"],$_POST["Soort"])){
mysql_connect("localhost", "root", "") or die ("Could not connect to database");
mysql_select_db("schiphol") or die("could not select database");
$Nr = mysql_real_escape_string($_POST["Nr"]);
$Postcode = mysql_real_escape_string($_POST["Postcode"]);
$Datum = mysql_real_escape_string($_POST["Datum"]);
$Tijd = mysql_real_escape_string($_POST["Tijd"]);
$Soort = mysql_real_escape_string($_POST["Soort"]);
$query = ("INSERT INTO klacht (Nr, Postcode, Datum, Tijd, Soort)
VALUES ('$Nr', '$Postcode', '$Datum', '$Tijd', '$Soort')");
$resultaat = mysql_query($query) or die (mysql_error( ));
if($resultaat) echo "Uw klacht is toegevoegd" ; else echo "ERROR";
}else{?>
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Prototype</title>
</head>
<body>
<h3>Klacht test</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br />Test nummer: <input type="text" name="Nr">
<br />Postcode<input type="text" name="Postcode">
<br />Datum<input type="Date" name="Datum">
<br />Tijd<input type="text" name="Tijd" >
<br />Soort klacht
<select name="Soort">
<option value=" "></option>
<option value="Geluid">Geluid</option>
<option value="Milieu">Milieu</option>
<option value="Veiligheid">Veiligheid</option>
</select>
<!-- Submit button -->
<br /><input type="submit" value="Versturen">
<input type="reset" value="Reset">
</form>
</body>
</html>
<?php}?>
<?php
if(isset($_POST["Nr"],$_POST["Postcode"],$_POST["Datum]",$_POST["Tijd"],$_POST["Soort"])){
mysql_connect("localhost", "root", "") or die ("Could not connect to database");
mysql_select_db("schiphol") or die("could not select database");
$Nr = mysql_real_escape_string($_POST["Nr"]);
$Postcode = mysql_real_escape_string($_POST["Postcode"]);
$Datum = mysql_real_escape_string($_POST["Datum"]);
$Tijd = mysql_real_escape_string($_POST["Tijd"]);
$Soort = mysql_real_escape_string($_POST["Soort"]);
$query = ("INSERT INTO klacht (Nr, Postcode, Datum, Tijd, Soort)
VALUES ('$Nr', '$Postcode', '$Datum', '$Tijd', '$Soort')");
$resultaat = mysql_query($query) or die (mysql_error( ));
if($resultaat) echo "Uw klacht is toegevoegd" ; else echo "ERROR";
}else{?>
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Prototype</title>
</head>
<body>
<h3>Klacht test</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br />Test nummer: <input type="text" name="Nr">
<br />Postcode<input type="text" name="Postcode">
<br />Datum<input type="Date" name="Datum">
<br />Tijd<input type="text" name="Tijd" >
<br />Soort klacht
<select name="Soort">
<option value=" "></option>
<option value="Geluid">Geluid</option>
<option value="Milieu">Milieu</option>
<option value="Veiligheid">Veiligheid</option>
</select>
<!-- Submit button -->
<br /><input type="submit" value="Versturen">
<input type="reset" value="Reset">
</form>
</body>
</html>
<?php}?>
My current form submits data to two different tables, and I want the auto_incremented value from one table to also be stored in the second table.
<form method="POST" action="addcocktail.php" >
Cocktail Name: <input type="text" name="cocktailname" />
How To: <input type="text" name="howto" />
<br>
<select id="selectingred1" name="selectingred1">
<?php
$sql = "SELECT ingredientID, name FROM tblIngredient ".
"ORDER BY name";
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
echo "<option value=\"".$row['ingredientID']."\">".$row['name']."</option>\n ";
}
?>
</select>
<select id="quantity1" name="quantity1">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<br>
<input type="submit" value="add" />
</form>
addcocktail.php:
<?php include("databasecon.php"); ?>
<?php
mysql_select_db("mwheywood", $con);
//insert cocktail details
$sql="INSERT INTO tblCocktail (name, howto)
VALUES
('$_POST[cocktailname]','$_POST[howto]')";
$sql2="INSERT INTO tblRecipe (ingredientID, quantity)
VALUES
('$_POST[selectingred1]','$_POST[quantity1]'),
('$_POST[selectingred2]','$_POST[quantity2]'),
('$_POST[selectingred3]','$_POST[quantity3]'),
('$_POST[selectingred4]','$_POST[quantity4]')";
if (!mysql_query($sql,$con))
{
die('Error: you fail at life' . mysql_error());
}
echo "cocktail added";
if (!mysql_query($sql2,$con))
{
die('Error: you fail at life' . mysql_error());
}
echo "ingredients added";
mysql_close($con);
?>
so to put it simply, when I submit my form. I want the "cocktailID" of the posted data to "tblCocktail" to also save into "tblRecipe"
after executing the insert query, you can get the insert id if succeeded with mysql_insert_id() function.