【问题标题】:How to retrieve a specific value from MySQL (PHP)如何从 MySQL (PHP) 中检索特定值
【发布时间】:2013-10-21 05:26:12
【问题描述】:

我是 PHP 新手,我想对这个小脚本进行一些输入。一切似乎都正常,但我需要知道如何检索已修改消息的“id”。

<?php
function updatemyinfos() {
$con=mysqli_connect("localhost","root","root","dbname");
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
**$id=**
$sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'";

if (!mysqli_query($con,$sql))
{
    die('Error: ' . mysqli_error($con));
}
echo '<p>Message modifié</p>';
mysqli_close($con);
}

if(isset($_POST['updatemessage']))
{
    updatemyinfos();
}
?>
<form action="#" method="post">
<textarea style="resize:none" cols="1" rows="1" name="message"id="textbox">'.$row['message'].'</textarea>           
<input type="submit" value="Soumettre" name="updatemessage" id="updatemessage">
</form>

编辑:我试过了。我没有收到任何错误消息,但数据库没有更新。但我得到了“回声”

消息修改

"
<?php
function updatemyinfos($id) {
$con=mysqli_connect("localhost","root","root","TP1AlexandreBouletCouture");
                if (mysqli_connect_errno())
                  {
                  echo "Failed to connect to MySQL: " . mysqli_connect_error();
                  }



                $sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'";




                if (!mysqli_query($con,$sql))
                  {
                  die('Error: ' . mysqli_error($con));
                  }
                echo '<p>Message modifié</p>';


                mysqli_close($con);
            }

            if(isset($_POST['updatemessage']))
            {
            updatemyinfos($_POST['updatemessage']);
            }
            ?>

【问题讨论】:

    标签: php mysql forms get sql-update


    【解决方案1】:

    更改这些行

    if(isset($_POST['updatemessage']))
    {
    updatemyinfos();
    }
    

    if(isset($_POST['updatemessage']))
    {
    updatemyinfos($_POST['updatemessage']);
    }
    

    还有这个

    function updatemyinfos()
    

    function updatemyinfos($id)
    

    【讨论】:

    • 我没有收到任何错误消息,但是当我提交表单时我的数据库没有更新。但我确实得到了 echo '

      Message modifié

      ';
    • 不应该;这个 $_POST[message] 是 $_POST['message']
    【解决方案2】:

    您好,请尝试以下查询,

        $sql1 = "Select id from table where message = '$_POST[message]'";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多