gpt4 book ai didi

php - 无法将数据选择插入数据库 php mysql?

转载 作者:搜寻专家 更新时间:2023-10-30 23:02:17 26 4
gpt4 key购买 nike

CREATE TABLE IF NOT EXISTS `penyakitt` (
`id_penyakitt` int(11) NOT NULL,
`namapenyakit` varchar(200) NOT NULL,
PRIMARY KEY (`namapenyakit`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS `cfs` (
`id_cfs` int(11) NOT NULL AUTO_INCREMENT,
`namapenyakit` varchar(200) NOT NULL,
`namagejalaa` varchar(200) NOT NULL,
`mb` varchar(200) NOT NULL,
`md` varchar(200) NOT NULL,
PRIMARY KEY (`id_cfs`),
KEY `namapenyakit` (`namapenyakit`),
KEY `namagejalaa` (`namagejalaa`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;


CREATE TABLE IF NOT EXISTS `gejalaa` (
`id_gejala` int(11) NOT NULL,
`namagejalaa` varchar(200) NOT NULL,
PRIMARY KEY (`namagejalaa`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Form_input.php

    <form  action="/tugasakhir/nilaicf/simpan_nilaicf.php"  method="post" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td width="24%">Jenis Penyakit</td>
<td width="5%">:</td>
<td width="71%"><label for="namapenyakit"></label>
<select id="penyakit" name="penyakit">
<option value="">-Pilih penyakit-</option>
<?php
$sql = "SELECT * FROM penyakitt";
$hasil_query=mysql_query($sql);

while($baris = mysql_fetch_object($hasil_query)){
echo "<option value=$baris->id_penyakitt->$baris->namapenyakit</option>";
}
?>
</select>

</td>
</tr>
<tr>
<td>Nama gejala</td>
<td>:</td>
<td>
<label for="namagejala"></label>
<select id="gejala" name="gejala">
<option value="">-Pilih gejala-</option>
<?php
$sql = mysql_query("SELECT * FROM gejalaa ORDER BY namagejalaa ASC");

while($data = mysql_fetch_assoc($sql)){
echo "<option value='$data[id_gejala]'>$data[namagejalaa]</option>";
}
?>
</select>
</tr>

<tr>
<td>Nilai MB</td>
<td>:</td>
<td><label for="MB"></label>
<input type="text" name="MB" id="MB" /></td>
</tr>
<tr>
<td>Nilai MD</td>
<td>:</td>
<td><label for="MD"></label>
<input type="MD" name="MD" id="MD" /></td>
</tr>
<tr>
<td height="41">&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="tambah" value="Tambah" /></td>
</tr>
</table>
</form>

simpan_nilaicf.php

<?php
include_once "config.php";

$namapenyakit=$_POST['namapenyakit'];
$namagejalaa=$_POST['namagejalaa'];
$mb=$_POST['mb'];
$md=$_POST['md'];

$sql="INSERT INTO cfs ('namapenyakit', 'namagejalaa', 'mb', 'md') VALUES ('', '$namapenyakit', '$namagejalaa', '$mb', '$md')";

$eksekusi_query=mysql_query($sql);

if(!$eksekusi_query){
die("Query kamu salah dikarenakan:".mysql_error());
}
?>

当我在 mysql phpmyadmin 中运行我的插入代码时.. 出现这样的错误:

#1064 - You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near ''id_cfs', 'namapenyakit', 'namagejalaa', 'mb', 'md') VALUES ('', '$namapenyakit'' at line 1

我应该更改什么,以便我在 form_input.php 中输入的数据可以插入到我的数据库中? :(

最佳答案

在您的插入查询中,您传递了与您提到的 4 列对应的 5 个值,并且对于您使用了错误引号的列。

尝试以下操作:

$sql="INSERT INTO cfs (`namapenyakit`, `namagejalaa`, `mb`, `md`) VALUES ('$namapenyakit', '$namagejalaa', '$mb', '$md')";

关于php - 无法将数据选择插入数据库 php mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30751098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com