简体   繁体   English

没有错误,sql是正确的,表未更新

[英]No errors, sql is right, table doesn't update

I'm trying to update my database via a simple form and for some reason, the table doesn't update. 我试图通过一个简单的表单更新数据库,由于某种原因,该表没有更新。 I tried the sql query inside phpmyadmin and it seemed to work fine. 我在phpmyadmin中尝试了sql查询,它似乎工作正常。

     <?php 
include("_/inc/session_handler.php");
include("_/inc/dbcon.php");
$uplform = "";

if(isset($_POST['insert'])){
    $post=$_POST['wish'];
    $succes="";
    $succes .="<h1>SUCCES</h1>";
    $insert_wish_sql="INSERT INTO wishlist(wish_id, wish, datetime)VALUES (null, '$post', CURDATE())";//insert new post
    echo $succes;
}



//The form

$uplform .="<form action=\"\"method=\"post\">";
$uplform .="<input type='text' name='wish' placeholder='wish'/>";
$uplform .="<input type=\"submit\" name=\"insert\" value=\"Upload\" />";
$uplform .="</form>";

?>

i even get the succes message, but nothing happens in the table. 我什至收到成功消息,但表中什么也没有发生。 what am i missing? 我想念什么?

UPDATE: I just went fully retarded. 更新:我只是完全智障。 i forgot to add 我忘了加

$link = mysql_connect($host, $login, $pw);
    mysql_select_db($database);

so i was basically not connected to the database 8-|. 所以我基本上没有连接到数据库8- |。 Thanx a lot! 非常感谢!

There may be one problem looking at your code is that it is not executed. 查看您的代码可能有一个问题是它没有执行。 SO execute it like this 所以像这样执行它

 $res = mysqli_query($conn, $insert_wish_sql);

But the bigger concern is your sql itself as you are passing null as the value for id. 但更大的问题是您的sql本身,因为您要传递null作为id的值。 Is your id is not primary or auto increment. 是您的ID不是主要的还是自动递增的。 If it is then it will fail always. 如果是这样,它将始终失败。

I miss your connection to a database server ( I guess its' that include) and finally if a connection exits, you need to send/execute your query. 我想念您与数据库服务器的连接(我想其中包括),最后,如果连接退出,则需要发送/执行查询。

The API's: PDO or mysqli is good for it. API的:PDO或mysqli很好。

or to test stuff, with the mysql API ( but I would not recommend it to use it live) http://ch1.php.net/manual/en/book.mysql.php 或使用mysql API进行测试(但我不建议它实时使用) http://ch1.php.net/manual/zh/book.mysql.php

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

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