我试图在php文件中设置更新功能从表单中获取数据但是它没有在phpmysql中更新它,这里是查询,可能是我遗漏了一些东西。
$query="UPDATE controlpanel1 SET ftitle_p1_1 = '$_POST[ftitle_p1_1]'";
答案 0 :(得分:1)
$query= $MysqliConnection->prepare("UPDATE controlpanel1 SET ftitle_p1_1 = ? WHERE id = ?"); //reason why it's not updating, probably. You have to tell the system where to update. Which row.
$query->bind_param("si", $title, $id); //string, integral - title and id(?). Just guessing.
$title = $_POST["title_p1_1"];
$id = $_GET["I_have_no_idea"]; // or $_POST["I_have_no_idea"];
$query->execute();
$query->close();
$MysqliConnection->close();
或者,请参考,this page。 请清理数据...即使使用预处理语句,我也会检查字符串是否有效。我太担心了,你不是吗?
答案 1 :(得分:0)
确保在php.ini配置文件中启用了mysqli扩展和pdo扩展。
那么你需要选择是否要采用程序或OO方式以及mysqli或PDO方式
这是程序性的mysqli:
$DBConnect = new mysqli("localhost", "root", "myCoolPW", "myDBname");
$FTitle = '_';
$FTitle = $_POST['ftitle_p1_1'];
echo " Test posted FTitle: " . $FTitle . " ";
$query = "
UPDATE controlpanel1
SET ftitle_p1_1 = '$FTitle'
WHERE id != '2'
",
echo " Test query: " . $query . " ";
mysqli_query($DBConnect, $query);
if (mysqli_affected_rows($DBConnect) == -1)
echo "NOT successfull :-(";
else
echo "SUCCESS!!! :-)";