我想用新数据更新数据库,这样当您将文本放在文本框中然后单击提交按钮时,数据将被发送到具有特定ID的数据库.我要发送的只是亮度,代码如下.当我写这样的东西,然后运行它时,我收到403错误:禁止访问.我怎样才能解决这个问题?
<?PHP function updater($value,$id){ // Create connection $conn = new MysqLi( 'localhost','user_name','','data_base_name' ); // Check connection if ($conn->connect_error) { die("Connection Failed: " . $conn->connect_error); } $sql = "UPDATE table_name SET name=$value WHERE id=$id"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } //$conn->close(); } ?> <!DOCTYPE html> <html> <header> </header> <body> <form action="<?PHP updater($_POST['name'],1); ?>" method="post" style="height:50px;width:50px;"> <input type="text" name="name" /><br><br> <input type="submit" /><br/> </form> </body> </html>
像这样:
原文链接:https://www.f2er.com/php/136894.html<?PHP function updater($value,$id){ // Create connection $conn = new MysqLi( 'localhost','pass','data_base_name' ); $value =MysqLi_real_escape_string($conn,$value); $id =MysqLi_real_escape_string($conn,$id); // Check connection if ($conn->connect_error) { die("Connection Failed: " . $conn->connect_error); } $sql = "UPDATE table_name SET name='{$value}' WHERE id='{$id}'"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $conn->close(); } if(isset($_POST['name'])){ updater($_POST['name'],$_POST['id']) } ?> <!DOCTYPE html> <html> <header> </header> <body> <form action="" method="post" style="height:50px;width:50px;"> <input type="hidden" name="id" value="1" /> <input type="text" name="name" /><br><br> <input type="submit" /><br/> </form> </body> </html>