godaddy宿主上未在php中运行特定查询

0pizxfdo  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(300)

我试图在我的php页面上运行insert查询,但它没有执行,并把我带到else部分。我已经检查过mysql的查询了。另外,我在同一个页面上有几个select查询,这些都很好用。所以我确信连接和访问db没有问题。这是我的密码:

<?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>';

            }

}
我已经检查了godaddy这里一个只需要localhost作为主机名。我知道我粘贴了一段很长的代码,但是不知道问题出在哪里。

bq3bfh9z

bq3bfh9z1#

你的代码末尾有一个拼写错误。

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>';

}

相关问题