【问题标题】:data is not insert to my database table数据未插入到我的数据库表中
【发布时间】:2017-06-05 02:26:00
【问题描述】:
<?php

    $con = mysqli_connect('localhost','root','');

    if(!$con)
    {
        echo 'not connected to server';
        }

    if(!mysqli_select_db($con,'user_table'))
    {
        echo 'database not selected';
        }

    $mobilenumber = $_POST['mobilenumber'];
    $operator = $_POST['operator'];
    $state = $_POST['state'];

    $sql =  "INSERT INTO user_details (mobilenumber,operator,state) VALUES ('".$mobilenumber."','".$operator."','".$state."')";

    if(!mysqli_query($con,$sql))
    {
        echo 'not inserted';
        }
    else
    {
        echo 'inserted';
        }

    //$select="insert into user_details (mobilenumber,operator,state) VALUES ('".$mobilenumber."".$operator."".$state."')";
    //$sql=mysql_query($select);

    //print '<script type="text/javascript">';
    //print 'alert("the data is inserted.....")';
    //print '<script>';
    //mysql_close();
?>

<form method="post" action="insert.php" id="submitForm">

<select id="operator" type="select" ng-model="operatorName" ng-class="operatorError ? 'error-border':''" autocomplete="off" placeholder="Select operator" ng-click="showOperators($event);" name="operator" method=POST action=/insert.php class="form-control fetchoperators drpdwn-arrow ng-pristine ng-valid ng-touched" required>

<select name="state" class="state" id="state" required name="state" method="post" action="insert.php">

【问题讨论】:

  • 您是否希望有人在您发布代码时甚至尝试回答这个问题......?
  • 兄弟添加响应什么是消息(Response)。
  • 你有什么错误吗?电流输出是多少?此外,如果您无法连接到数据库,您应该继续尝试其余的,请尽量明确并指出您的问题或至少,您尝试了什么。帮助那些无偿帮助你的人!
  • 使用 提交可能会帮助您解决问题

标签: php sql phpmyadmin


【解决方案1】:

最简单的方法是尝试调试您的查询。 我会做的只是尽可能多的过程。

echo $sql;

如果可行,则复制结果并将其粘贴到我的 sql 服务器中。

然后检查您的连接对象,显然它看起来正确,但最好的方法是复制以下代码。试试这个

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "user_table";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql =  "INSERT INTO user_details (mobilenumber,operator,state) VALUES ('".$mobilenumber."','".$operator."','".$state."')";


if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?> 

更改凭据并检查响应并将其粘贴到 cmets 中,然后我们将继续。

【讨论】:

  • 您的代码似乎是静态的,每次操作都会插入相同的结果时没有 $variable
  • 哥我明明说你改了,。无论如何,请尝试我所描述的,我已经更新了整个代码供您尝试,。现在复制并粘贴
  • 您应该验证 dbname ,., 是否与您的 dbname 相同
【解决方案2】:

你应该使用

  mysqli_query($con,$sql) or die((mysql_error());

它会向你显示它没有在你的表中插入数据的错误

【讨论】:

    猜你喜欢
    • 2016-01-29
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多