当您单击提交按钮时,我尝试通过两个输入将信息插入数据库。但是当我点击它时它说它无法连接到localhost(其他一切都有效,所以我知道它必须是某种形式的语法问题)代码:
<form action="prices.inc.php" method="post">
<input class="price-list-input" type="text" id="priceupdate1" name="priceupdate1" required></input>
<input class="price-list-input2" type="text" id="priceupdate2" name="priceupdate2" required></input>
<input class="price-list-button" type="submit" id="priceupdate-button" name="priceupdate-button" value="Uppdatera"></input>
</form>
php ..
<?php
require_once('check_login.inc.php');
define('SECURE', true);
require_once('connection.php');
if(isset($_POST['priceupdate-button'])){
$info = trim(htmlspecialchars($_POST['priceupdate1'], $_POST['priceupdate2']));
// prepared statement
$stmt = $db->prepare('INSERT INTO prices (name, price) VALUES = (?, ?)');
$stmt->bind_param('ss', $_POST['priceupdate1'], $_POST['priceupdate2']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($info);
}
?>
答案 0 :(得分:1)
GOT IT WORKING ..所有问题都在于&#34; =&#34; @ Fred-ii-提到.. - Chumppe
发布为社区维基。我不想要代表,只是为了解决这个问题。
As I said in comments,VALUES = (?, ?)
等号不应该存在。
手册http://php.net/manual/en/mysqli.prepare.php
中的示例$stmt = $mysqli->prepare("INSERT INTO City (District) VALUES (?)");