我正在尝试进入php和mysql,我创建了这个表单,用于将数据插入到我的数据库中,但是在填写表单时,没有数据插入到sql数据库中。将信息插入到具有多个外键的表中。调试sql时,我收到错误消息:错误查询:插入正确值的bud('belp,idkjoper,idgjenstand')值('7500','3','1')。
我怀疑问题在于,我正试图建立一个包含买家姓名的列表,然后将出价注册为买家ID。我正试图绕过必须记住买家ID才能出价的问题,但取而代之的是将买家名称显示在列表中,在选择买家名称后,将买家ID插入数据库。
如果您能抽出一天的时间来看一看,我将不胜感激:)
下面是sql段。
<?php
$tilkobling=mysqli_connect ("localhost","root","root", "bruktbutikk");
$sql="select navn,etternavn from kjøper";
$datasett = $tilkobling->query($sql);
$conn=mysqli_connect ("localhost","root","root", "bruktbutikk");
$sql1="select beskrivelse,idgjenstand from gjenstand";
$datasett1=$conn->query($sql1);
if(isset($_POST["submit"]))
{
$sql =sprintf("INSERT INTO bud(beløp,idkjoper,idgjenstand) VALUES
(%s,%s,%s)",
$tilkobling->real_escape_string($_POST["lstnavn"]),
$tilkobling->real_escape_string($_POST["lstbeskrivelse"]),
$tilkobling->real_escape_string($_POST["txtbeløp"])
);
$tilkobling->query($sql);
header("Location: budok.php");
}
?>
这是我的表格:
<main>
<h1> Gi bud</h1>
<br/>
<form method="post">
<label for="lstnavn">Budgiver:</label>
<select name="lstnavn" id="lstnavn">
<?php while($rad=mysqli_fetch_array($datasett)) { ?>
<option value="<?php echo $rad["idkjoper"]; ?>">
<?php echo $rad["navn"], ($rad['etternavn']); ?>
</option>}
<br><br>
<?php } ?> <br><br>
</select>
<br>
<form method="post">
<div>
<label for="lstbeskrivelse">gjenstand:</label>
<select name="lstbeskrivelse" id="lstbeskrivelse">
<?php while($rad=mysqli_fetch_array($datasett1)) { ?>
<option value="<?php echo $rad["idgjenstand"]; ?>"> <?php echo
$rad["beskrivelse"]; ?>
</option>}
<br><br>
<?php } ?> <br><br>
</select>
<br>
<label for="txtbeløp">beløp:</label>
<input type="text" name="txtbeløp" id="txtbeløp"
placeholder="beløp" /> <br/><br>
<br/>
<button type="submit" name="submit">Publiser</button>
</form>
</main>