Click here to Skip to main content
14,696,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Notice: Undefined index: datepicker in C:\xampp\htdocs\psm1\studRequest1.php on line 5

Notice: Undefined index: message in C:\xampp\htdocs\psm1\studRequest1.php on line 6
Error : INSERT INTO booking (datepicker,message) VALUES ('','')

What I have tried:

  1  This is my html file
  3   <form class="modal-content animate" action="studRequest1.php"> 
  4              <div class="imgcontainer"> 
  5                  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span> 
  7              </div> 
  9              <div class="container"> 
 11  				<label for="datepicker">Date for Appointment</label><br>
 12  				<input type="text" id="datepicker" name="datepicker" width="30%" autocomplete="off" placeholder="Select Date Here" >
 14  				<br>
 15                  <label for="message">Message</label> <br>
 16  				<textarea rows="4" cols="50" type="message" id="message" placeholder="" name="message" required> </textarea>
 18  				<button type="submit" class="btn btn-primary" name="submit" value="submit">Submit</button>
 20              </div> 
 22              <div class="container" style="background-color:#f1f1f1"> 
 23                  <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> 
 24              </div> 
 25          </form> 

  1  <?php 
  3  session_start();
  4  	include ('connection.php');
  5  	$datepicker = $_POST['datepicker'];
  6  	$message = $_POST['message'];
  8  	$sql="INSERT INTO booking (datepicker,message)
  9  	VALUES ('$datepicker','$message')";
 12  							$resultInsert = mysqli_query($conn, $sql) or die(mysqli_error($sql));
 14  							if($resultInsert === TRUE)
 15  		{
 16  			echo"<script>alert('Data Insert');</script>";
 17     //          echo "<script>window.location.assign('studAppointment.php')</script>";
 18  		}
 19  		{
 21  				echo "Error : ". $sql . "<br>" . $conn -> error;
 22  					}
 25  ?>
Updated 23-Jun-20 8:29am
Richard MacCutchan 23-Jun-20 9:01am
Look at the error messages, you have two variables that are not defined. I see $message but not studNo. Is this the actual code that you are running?
Member 14871013 23-Jun-20 9:14am
I'm sorry I update already the problem.The problem is data is not inserted even when I submit the form it said insert. Help me please, it for my FYP
Richard MacCutchan 23-Jun-20 9:21am
The line numbers in the error messages do not match the code you have posted.
Member 14871013 23-Jun-20 9:26am
should I post entire code? it may include unnecessary part because this suppose to be a popup form
Richard MacCutchan 23-Jun-20 9:44am
No we do not need the entire code, but we do need all the parts that are connected to the problem. If the line numbers above are wrong then please indicate the exact lines that the error messages refer to.
Member 14871013 23-Jun-20 9:52am
Please take a look, I already update
Richard MacCutchan 23-Jun-20 10:16am
I think it is reasonable to assume that nothing is getting posted to your PHP code. So, you need to use your debugger to find out why, as we cannot run the code for you.
Member 14871013 23-Jun-20 11:05am
Hmmm ok thank you for trying
Richard MacCutchan 23-Jun-20 11:14am
See my suggestion below
Member 14871013 23-Jun-20 11:52am
OMG. I don't know how but it works thank you so much!!! I'm still new in programming.
Richard MacCutchan 23-Jun-20 12:36pm
As you are new I suggest you go to PHP Tutorial[^], and work through all the tutorials. It is a much better way to learn than Youtube videos

I see very different syntax in these two lines:
$datepicker = $_POST['datepicker'];
$message = $_POST($message);

Member 14871013 23-Jun-20 9:34am
it did not work :'(

Notice: Undefined index: datepicker in C:\xampp\htdocs\psm1\studRequest1.php on line 9

Fatal error: Uncaught Error: Function name must be a string in C:\xampp\htdocs\psm1\studRequest1.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\psm1\studRequest1.php on line 10
Luc Pattyn 23-Jun-20 9:48am
so you changed something, did not tell us what, and got a new error.
Maybe you 'fixed' what was correct?
Do you actually know PHP at all?
Be precise, show code (with linenumbers; your original post got edited so you can see how that is done) and tell us its behavior.
Member 14871013 23-Jun-20 9:54am
no the error i just sent here based on what solution u give me. Im sorry if it confusing
I have a suggestion. Your forma definition has the following line:
<form class="modal-content animate" action="studRequest1.php">

and according to the documentation, the default submit method is GET rather than POST. Try changing your PHP as follows:
$datepicker = $_GET['datepicker'];
$message = $_GET['message'];
$sql="INSERT INTO booking (datepicker,message) VALUES ('$datepicker','$message')";

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900