简体   繁体   中英

particular query not running in php on Godaddy hosting

I am trying to run Insert query on my php page but its not executing and takes me to else part. I have checked query on MySQL its fine. Also I have couple of select queries on the same page, and those works fine. So I am sure there is no issue with the connection or accessing DB. Heres my code:

<?php
 session_start();
 include './db_config.php';

 if ((!isset($_SESSION['first_name']) == true)) {
unset($_SESSION['first_name']);
} 
$logged = $_SESSION['first_name'];

 if ((!isset($_SESSION['id']) == true)) {
unset($_SESSION['id']);
} 
$id = $_SESSION['id']; 

if ((!isset($_SESSION['email']) == true)) {
unset($_SESSION['email']);
}
$email= $_SESSION['email'];  


$query1 = "select * from user_master where id='$id'";
$result1 = mysqli_query($con, $query1);
$num1 = mysqli_num_rows($result1);
if ($num1 > 0) {
  while ($data = $result1->fetch_assoc()) {
    $branch_name = $data['branch_name'];

 } 
}
if(isset($_POST['save'])){
$cust_id=$_POST['cust_id']; 
$meter_no=$_POST['meter_no'];
$lock_no=$_POST['lock_no'];
$customer_name=$_POST['customer_name'];
$customer_type=$_POST['customer_type'];
$customer_zone=$_POST['customer_zone'];
$status=$_POST['status'];
$phoneno=$_POST['phoneno'];
$city=$_POST['city'];
$address=$_POST['address'];
$houseno=$_POST['houseno'];
$ownership=$_POST['ownership'];
$landmark=$_POST['landmark'];
$opening_reading=$_POST['opening_reading'];
$opening_reading_date=$_POST['opening_reading_date'];
$branch_name=$_POST['branch_name'];
$created_on=$_POST['created_on'];
$created_by=$_POST['created_by'];
$email=$_POST['email']; 
$consumption=0;
$current_reading=$opening_reading;
$status1="True";
$total_bill=0;
$total_paid=0;
$total_dues=0;

$select="insert into meter(cust_id,meter_no,lock_no,customer_name,customer_type,customer_zone,status,phoneno,city,address,houseno,ownership,landmark,opening_reading,opening_reading_date,created_on,branch_name,created_by,email)
 VALUES('$cust_id','$meter_no','$lock_no','$customer_name','$customer_type','$customer_zone','$status','$phoneno','$city','$address','$houseno','$ownership','$landmark','$opening_reading','$opening_reading_date','$created_on','$branch_name','$created_by','$email')";
            if ($r = mysqli_query($con, $select)) {
            else {
                echo '<script language="javascript">';
                echo 'alert("Information Not Inserted!!!");';
                //echo 'window.location.href="bill_generation.php";';
                echo '</script>';

            }

}

I have Checked on Godaddy HERE that one need just Localhost as host name. I know I have pasted a long piece of code, however dont know where the issue is.

You have a typo at the end of your code.

if ($r = mysqli_query($con, $select)) {
    echo 'data inserted successfully !';
    // do something ?
} // this one is missing 
else {
    echo '<script language="javascript">';
    echo 'alert("Information Not Inserted!!!");';
    //echo 'window.location.href="bill_generation.php";';
    echo '</script>';

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM