My values in my codes aren't inserted into mySQL. I input 5 but it will show 0. Any ideas?

0 votes
<?php
session_start();
?>
<?php
include 'dbconnect.php';
?>
<!DOCTYPE HTML>  

<html>
<head>
    <meta charset="UTF-8">
    <title>Welcome</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    <style type="text/css">
        body{ font: 14px sans-serif; text-align: center; }
    </style>
</head>
<body>
    <div class="page-header">
        <h1>BOOK A VENUE</h1>
    </div>
<body>  
<head>
<style>
.error {color: #FF0000;}
</style>
</head>

<?php
// define variables and set to empty values
$personsErr = 0;
$timeErr = "";
$persons = 0;
$time = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (empty($_POST["estimated number of people"])) {
      $personsErr = "An estimated number is required.";
    }

    if (empty($_POST["timeslot"])) {
        $timeErr = "A selection is required.";
      }

$link = mysqli_connect("localhost", "root", "", "venue booking");
$sql = "INSERT INTO timeslot (time ,persons) VALUES ('$time','$persons')";
mysqli_query($link, $sql);
 mysqli_close($link);

}    

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>Please enter the </h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  Estimated number of people: <input type="number" name="estimated number of people" value="<?php echo $persons;?>">
  <br>
  <span class="error">* <?php echo $personsErr;?></span>
  <br><br>
 
  Time Slot:
  <br>
  <span class="error">* <?php echo $timeErr;?></span>
  <br><br>
  <input type="radio" name="timeslot" <?php if (isset($time) && $time=="10am - 12pm") echo "checked";?> value="10am - 12pm">10am - 12pm
  <br><br>
  <input type="radio" name="timeslot" <?php if (isset($time) && $time=="12pm - 2pm") echo "checked";?> value="12pm - 2pm">12pm - 2pm
  <br><br>
  <input type="radio" name="timeslot" <?php if (isset($time) && $time=="2pm - 4pm") echo "checked";?> value="2pm - 4pm">2pm - 4pm  
  <br><br>
  <input type="submit" name="submit" value="Submit">   
  <br>
  <a href=welcome-user.php class="btn btn">Go back</a>

</form>
</body>
</html>
Jul 11 in Database by anonymous
• 120 points
39 views

1 answer to this question.

0 votes

Hello,

You can refer my corresponding sample web app and can cross check yours as you are having lots of syntax error:https://drive.google.com/drive/u/0/folders/1ez1rX_HVzA4gacGmfmkUVfxopYsyQQvp(contain E-COM wep page codes).

You can also refer the course designed to make you an expert in using PHP & MySQL and learn all that is required to create real world web applications with PHP & MySQL.

Hope it is helpfull!!
Thank you!!

answered Jul 13 by Niroj
• 44,800 points

Related Questions In Database

0 votes
1 answer

How can I check my all existing table in MySQL database?

Hi Pratik, I understand your problem regarding this ...READ MORE

answered Jul 1, 2019 in Database by sampriti
• 1,100 points
140 views
+1 vote
1 answer

How can I reset my auto_increment column in MYSQL?

Hi Pratim, I understand your issue. I think you ...READ MORE

answered Jul 1, 2019 in Database by sampriti
• 1,100 points
119 views
0 votes
1 answer

Find values in a comma separated string in a MySQL query

You can add commas to the left and ...READ MORE

answered Sep 10, 2018 in Database by Sahiti
• 6,290 points
6,640 views
0 votes
1 answer

How will I get all the rows from my table where name starts with 's' and ending with 'I'?

Hi Santanu, I understand your problem, You can try ...READ MORE

answered May 28, 2019 in Database by sampriti
• 1,100 points
117 views
0 votes
1 answer

MySQL query finding values in a comma separated string

To find MySQL query values in a comma-separated ...READ MORE

answered Oct 4, 2019 in Database by Daric
• 500 points
216 views
0 votes
1 answer
0 votes
1 answer

Types of tables in MySQL

MyISAM is the default table that is ...READ MORE

answered Aug 21, 2018 in Database by CodingByHeart77
• 3,710 points
397 views
0 votes
1 answer

TRIGGERS used in MySQL tables

The following TRIGGERS are allowed in MySQL:  BEFORE ...READ MORE

answered Aug 21, 2018 in Database by CodingByHeart77
• 3,710 points
65 views
0 votes
1 answer

How do I kill all the processes in Mysql “show processlist”?

Hello kartik, Mass killing operation saves time. Do it ...READ MORE

answered May 4 in Database by Niroj
• 44,800 points
56 views
0 votes
1 answer

I need query based on Timestamp in sqlserver

Hello  vnk, To get some familiarity try creating and ...READ MORE

answered Jun 30 in Database by Niroj
• 44,800 points
74 views