0

I just uploaded a website on live before that I test on PHP local host and it's perfectly fine no errors at all. But when I upload it live the insert statements are not working. But other SQL is perfectly fine like retrieve select statements all others are perfectly fine. I'm already connected to the database.

<?php 
session_start();
error_reporting(0);
include('includes/dbconnection.php');

if(isset($_POST['submit']))
  {
    $name=$_POST['name'];
    $email=$_POST['email'];
    $services=$_POST['services'];
    $adate=$_POST['adate'];
    $atime=$_POST['atime'];
    $phone=$_POST['phone'];
    $aptnumber = mt_rand(100000000, 999999999);
    $sqlinsert = "INSERT INTO `tblappointment` (`AptNumber`, `Name`, `Email`, `PhoneNumber`, `AptDate`, `AptTime` ,`Services`) VALUES ('$aptnumber','$name','$email','$phone','$adate','$atime','$services')";

    if (!mysqli_query($con, $sqlinsert)) {
    die('error inserting new record');
    }
    $newrecord = "1 new record added to the database";
}
    

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>teethenjoy Dental Clinic Official Website</title>
        
    <link href="https://fonts.googleapis.com/css?family=Work+Sans:100,200,300,400,500,600,700,800,900" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i" rel="stylesheet">

    <link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
    <link rel="stylesheet" href="css/animate.css">
    
    <link rel="stylesheet" href="css/owl.carousel.min.css">
    <link rel="stylesheet" href="css/owl.theme.default.min.css">
    <link rel="stylesheet" href="css/magnific-popup.css">

    <link rel="stylesheet" href="css/aos.css">

    <link rel="stylesheet" href="css/ionicons.min.css">

    <link rel="stylesheet" href="css/bootstrap-datepicker.css">
    <link rel="stylesheet" href="css/jquery.timepicker.css">

    
    <link rel="stylesheet" href="css/flaticon.css">
    <link rel="stylesheet" href="css/icomoon.css">
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
      <?php include_once('includes/header.php');?>
    <!-- END nav -->

    <section id="home-section" class="hero" style="background-image: url(images/8.jpg);" data-stellar-background-ratio="0.5">
          <div class="home-slider owl-carousel">
          <div class="slider-item js-fullheight">
            <div class="overlay"></div>
            <div class="container-fluid p-0">
              <div class="row d-md-flex no-gutters slider-text align-items-end justify-content-end" data-scrollax-parent="true">
                <!--<img class="one-third align-self-end order-md-last img-fluid" src="images/1.png" alt=""> -->
                  <div class="one-forth d-flex align-items-center ftco-animate" data-scrollax=" properties: { translateY: '70%' }">
                    <div class="text mt-5">
                        <span class="subheading">teethenjoy Dental Clinic</span>
                        <h1 class="mb-4">Get Pretty Smile</h1>
                        <h2 class="mb-4">A SMILE is the PRETTIEST THING YOU'LL ever wear</h2>
                        
                       
                    </div>
                  </div>
                </div>
            </div>
          </div>

          <div class="slider-item js-fullheight">
            <div class="overlay"></div>
            <div class="container-fluid p-0">
              <div class="row d-flex no-gutters slider-text align-items-center justify-content-end" data-scrollax-parent="true">
              <!--  <img class="one-third align-self-end order-md-last img-fluid" src="images/2.png" alt=""> -->
                  <div class="one-forth d-flex align-items-center ftco-animate" data-scrollax=" properties: { translateY: '70%' }">
                    <div class="text mt-5">
                        <span class="subheading">teethenjoy Dental Clinic</span>
                        <h1 class="mb-4">Get a Confidence   </h1>
                        <h2 class="mb-4">A warm smile is the universal language of kindness</h2>
                        
                       
                    </div>
                  </div>
                </div>
            </div>
          </div>
        </div>
    </section>


<br>
    <section class="ftco-section ftco-no-pt ftco-booking">
        <div class="container-fluid px-0">
            <div class="row no-gutters d-md-flex justify-content-end">
                <div class="one-forth d-flex align-items-end">
                    <div class="text">
                        <div class="overlay"></div>
                        <div class="appointment-wrap">
                            <span class="subheading">Reservation</span>
                                <h3 class="mb-2">Make an Appointment</h3>
                            <form action="#" method="post" class="appointment-form">
                        <div class="row">
                          <div class="col-sm-12">
                            <div class="form-group">
                                  <input type="text" class="form-control" id="name" placeholder="Name" name="name" required="true">
                                </div>
                          </div>
                          <div class="col-sm-12">
                            <div class="form-group">
                                  <input type="email" class="form-control" id="appointment_email" placeholder="Email" name="email" required="true">
                                </div>

                          

                          </div>
                            <div class="col-sm-12">
                            <div class="form-group">
                                  <div class="select-wrap">
                              <div class="icon"><span class="ion-ios-arrow-down"></span></div>
                              <select name="services" id="services" required="true" class="form-control">
                                <option value="">Select Services</option>
                                <?php $query=mysqli_query($con,"select * from tblservices");
              while($row=mysqli_fetch_array($query))
              {
              ?>
                               <option value="<?php echo $row['ServiceName'];?>"><?php echo $row['ServiceName'];?></option>
                               <?php } ?> 
                              </select>
                            </div>
                                </div>
                          </div>
                          <div class="col-sm-12">
                            <div class="form-group">
                              <input type="text" class="form-control appointment_date" placeholder="Date" name="adate" id='adate' required="true">
                            </div>    
                          </div>
                          <div class="col-sm-12">
                            <div class="form-group">
                              <input type="text" class="form-control appointment_time" placeholder="Time" name="atime" id='atime' required="true">
                            </div>
                          </div>
                          <div class="col-sm-12">
                            <div class="form-group">
                              <input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" required="true" maxlength="10" pattern="[0-9]+">
                            </div>
                          </div>
                          </div>
                          <div class="form-group">
                          <input type="submit" name="submit" value="Book an Appointment" class="btn btn-primary">
                        </div>
                      </form>
                  </div>
                        </div>
                </div>
                    <div class="one-third">
                        <div class="img" style="background-image: url(images/9.jpg);">
                        </div>
                    </div>
            </div>
        </div>
    </section>

        
        <br>


   <?php include_once('includes/footer.php');?>
    
  

  <!-- loader -->
  <div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px"><circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee"/><circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00"/></svg></div>


  <script src="js/jquery.min.js"></script>
  <script src="js/jquery-migrate-3.0.1.min.js"></script>
  <script src="js/popper.min.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script src="js/jquery.easing.1.3.js"></script>
  <script src="js/jquery.waypoints.min.js"></script>
  <script src="js/jquery.stellar.min.js"></script>
  <script src="js/owl.carousel.min.js"></script>
  <script src="js/jquery.magnific-popup.min.js"></script>
  <script src="js/aos.js"></script>
  <script src="js/jquery.animateNumber.min.js"></script>
  <script src="js/bootstrap-datepicker.js"></script>
  <script src="js/jquery.timepicker.min.js"></script>
  <script src="js/scrollax.min.js"></script>
  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
  <script src="js/google-map.js"></script>
  <script src="js/main.js"></script>
    
  </body>
</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Welcome to Stack Overflow. 1) Check the error logs on your live server, they should tell you the exact error that's happening. 2) When posting a question, try to narrow your problem down and be as specific as you can ("not working" is very vague as it can mean a ton of things). 3) See this question about [SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) as the way you're writing your query is unsafe. – El_Vanja Jan 04 '21 at 10:48
  • 1
    Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Jan 04 '21 at 11:05
  • @El_Vanja i tried to use mysqli_connect_error();. and throw me an error that Field:"Remark" doesnt have a default value – solly molly channel Jan 04 '21 at 11:32
  • and i try to modify my database those column to null. and it worked. but im confusing what will be the result when i set that – solly molly channel Jan 04 '21 at 11:33
  • `mysqli_connect_error` can't ever give you such an error. You should never use that function, instead enable proper error reporting like I said. – Dharman Jan 04 '21 at 11:34
  • @Dharman i try to use prepared statements too but it doesnt work – solly molly channel Jan 04 '21 at 11:35
  • What do you mean it doesn't work? Please be more specific, I can't reply to that comment in any meaningful way. – Dharman Jan 04 '21 at 11:36
  • @Dharman it throw me the same error. – solly molly channel Jan 04 '21 at 11:49
  • Sure, but you don't even have the column `Remark` in your INSERT query. That problem is quite obvious. I am asking why would you not use prepared statements. Please always use prepared statements with parameter binding and forget about the other way. – Dharman Jan 04 '21 at 11:51
  • yes it dont have the Remark. because it will accept on the admin page. ow sure i think this time if i use prepared statements. i think it will work. cause i set the column to null – solly molly channel Jan 04 '21 at 11:53

0 Answers0