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, 2020 in Database by anonymous
• 120 points
782 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, 2020 by Niroj
• 82,880 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,120 points
1,223 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 2, 2019 in Database by sampriti
• 1,120 points
696 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,370 points
12,623 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,120 points
1,652 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
2,648 views
0 votes
1 answer

Can't connect to mysql server in workbench. Kindly please support. username: root & Password: 1234 (i gave)

Hey, @Arivukani, You can see once thing, the solution ...READ MORE

answered Mar 30, 2020 in Database by Gitika
• 65,910 points
1,567 views
0 votes
1 answer

How do I split a cell in Excel into two or more where they are divided horizontally?

Table cells should be combined. To make a ...READ MORE

answered Apr 6, 2022 in Database by gaurav
• 23,260 points
11,930 views
0 votes
0 answers

How can I show the table structure in SQL Server query?

Query: SELECT DateTime, Skill, Name, TimeZone, ID, User, ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,010 points
596 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, 2020 in Database by Niroj
• 82,880 points
2,189 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, 2020 in Database by Niroj
• 82,880 points
1,756 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP