简体   繁体   English

PHP更新功能不起作用

[英]php Update function doesn't work

I'm trying to update row in mysql table with php, but for some reason it doesnt work. 我正在尝试使用php更新mysql表中的行,但是由于某些原因,它行不通。

I have validation and some checks on the variables and all of them works great, when I var_dump the variable in the php statement everything is great, so I guess the problem is in the query code to mysql. 我有验证和对变量的一些检查,它们都很好用,当我在php语句中var_dump变量时一切都很好,所以我猜问题出在到MySQL的查询代码中。 I will be really happy if you can help me! 如果您能帮助我,我将非常高兴!

This is the php part: 这是php部分:

if (isset($_POST['editIdea'])) {
    $editIdea = trim($_POST['editIdea']);
    $editIdea = preg_replace('/[^А–Яа-яА-ЯA-Za-z0-9\. -!?,.@]/u', '', $editIdea);
    $editMoney = trim($_POST['editMoney']);
    $editMoney = preg_replace('/[^0-9\.]/', '', $editMoney);
    $editLong = trim($_POST['editLong']);
    $editLong = preg_replace('/[^А–Яа-яА-ЯA-Za-z0-9\. -!?,.@]/u', '', $editLong);
    $idnow = $_SESSION['id'];
    $error = false;

    if(mb_strlen($editIdea)<3 || mb_strlen($editIdea)>40) {
    echo '<b><p id="wrongname"> *blabla1 </b></p>';
    $error=true;
    }    

    if(mb_strlen($editLong)<9 || mb_strlen($editLong)>400) {
    echo '<b><p id="wronglongtext">*blabla2</b></p>';
    $error=true;
    }

    if($editMoney == false) {
    echo '<b><p id="wrongmoney"> *blabla3 </p> </b>';
    $error=true;
    }              

    if (!$error){
        var_dump($editIdea);
        var_dump($editMoney);
        var_dump($editLong);
       $sql = "UPDATE `Registration` SET `nameidea` = '$editIdea' , `moneyidea` = '$editMoney' , `explainidea`= '$editLong' WHERE `id` = '$idnow' ";
    }
else { 
       echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }
}

So to say again my progress till now: 再说一遍我到目前为止的进展:

All var_dumps near the query statement are working great, variables have the information that I want to send. 查询语句附近的所有var_dumps都运行良好,变量具有我要发送的信息。 There are no errors in the php log. php日志中没有错误。 The statement doesn't go in the else, so I can't see any error or more information. 该语句不在其他语句中,因此我看不到任何错误或更多信息。

Also, i was trying with and without the "`" near the rows and database names. 另外,我正在尝试在行和数据库名称附近使用和不使用“`”。

Where is my mystake in the query syntax? 查询语法的秘密在哪里?

Thanks in advance again! 再次感谢您!

**All the names of the database and rows are correct and double checked. **数据库和行的所有名称正确无误,并经过仔细检查。

Add this code after $sql = .... 在$ sql = ...之后添加此代码。

$link = mysqli_connect("localhost", "my_user", "my_password", "db_name");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if (!mysqli_query($link, $sql)) {
    printf("Error message: %s\n", mysqli_error($link));
}

/* close connection */
mysqli_close($link);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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