当您单击提交按钮时,我试图通过两个输入将信息插入数据库。但是当我点击它,它说它不能连接到本地主机(一切都工作,所以我知道它必须是某种形式的语法问题)代码:
<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);
}
?>
GOT IT WORKING..所有的问题都是@Fred-ii提到的"="。——Chumppe
作为社区wiki发布。我不需要代表这个,只是结束这个问题。
正如我在评论中所说的,VALUES = (?, ?)
等号不应该在那里。
手册中的示例http://php.net/manual/en/mysqli.prepare.php
$stmt = $mysqli->prepare("INSERT INTO City (District) VALUES (?)");