【发布时间】:2019-09-07 17:45:50
【问题描述】:
我尝试了几个我在互联网上遇到的代码,但我无法达到我的目标,即创建一个具有 3 个下拉列表的表单,然后将插入的数据输入到 SQL 表中。
我的代码没有按预期工作,两周以来我一直在努力解决这个问题。因此,我将不胜感激任何减轻这种情况的帮助。
<?php
$ligacao = new mysqli("localhost", "root", "", "pap");
if ($ligacao->connect_errno == 0) {
if (isset($_POST['submit'])) {
$instic = $conn->query("INSERT INTO tickets(problema, eletrecidade, agua, assunto, info) VALUES('" . $_POST["prob"] . "', '" . $_POST["elet"] . "','" . $_POST["agua"] . "','" . $_POST["ass"] . "','" . $_POST["info"] . "')");
$instic->bind_param("sssss", $_POST["prob"], $_POST["elet"], $_POST["agua"], $_POST["ass"], $_POST["info"]);
$instic->execute();
}
}
$ligacao->close();
?>
<form method="POST" action="inserir.php" enctype="multipart/form-data">
<fieldset>
<!-- Escolher problema geral -->
<label>Problema Geral</label>
<select name="prob">
<option disabled selected hidden>Escolha uma opção...</option>
<option name="luz" value="Luz">Luz</option>
<option name="agua" value="Agua">Agua</option>
<option name="ele" value="Elevador">Elevador</option>
</select>
<!-- Escolher problemas eletrecidade -->
<label>Eletrecidade</label>
<select name="elet" id="elet">
<option disabled selected hidden>Escolha uma opção...</option>
<option name="semluz" value="Nao ha luz">Não há luz</option>
<option name="curto" value="Curto Circuito">Curto circuito</option>
</select>
<!-- Escolher problemas agua -->
<label>Agua</label>
<select name="agua" id="agua">
<option disabled selected hidden>Escolha uma opção...</option>
<option name="semagua" value="Nao ha agua">Não há água</option>
<option name="inund" value="Inundacao">Inundação</option>
</select>
<label for="assunto">Assunto:</label>
<input type="text" name="ass" id="ass" maxlength=100 placeholder="Assunto">
</fieldset>
<fieldset>
<label for="info">Info:</label>
<textarea type="text" name="info" id="info" maxlength=50 placeholder="Descrição detalhada"></textarea>
</fieldset>
<div>
<input type="reset" value="Limpar">
<input type="submit" value="Submeter">
</div>
</form>
【问题讨论】:
-
嗨@Daniel,您面临的具体问题是什么?
-
query与bind_param和execute没有意义。使用准备好的语句版本,在其中使用prepare然后绑定/执行。阅读documentation 了解您正在使用的功能/方法。 -
我不太了解这个,你能写一些代码来纠正我的吗?
-
不,我们是来帮助您完成自己的工作,而不是为您完成。看看php.net/manual/en/mysqli.prepare.php上的例子吧
-
好的,谢谢队友,但我不想定义变量的值,变量的值是由用户定义的,这是正确的吗? { $query = "INSERT INTO 门票 (problema, eletrecidade, agua, assunto, info) VALUES (?,?,?,?,?)"; $stmt = $mysqli->prepare($query); $stmt->bind_param("sssss", $val1, $val2, $val3, $val4, $val5); $val1 = $_POST['prob']; $val2 = $_POST['elet']; $val3 = $_POST['agua']; $val4 = $_POST['ass']; $val5 = $_POST['info']; }
标签: javascript php html css ajax