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

时间:2022-09-25 19:19:03
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_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

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());
}
?>

When i run my insert code in mysql phpmyadmin.. its appear error like this :

当我在mysql phpadmin中运行插入代码时。其出现的错误如下:

#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

What should I change , so the data that I input in form_input.php can insert into my database? :(

我应该改变什么,我在form_input中输入的数据。php可以插入我的数据库吗?:(

3 个解决方案

#1


2  

In your insert query you are passing 5 values corresponding to the 4 columns mentioned by you and for columns you are using wrong quotes.

在您的插入查询中,您将传递与您所提到的4列相对应的5个值,以及您使用错误引用的列。

Try the following:

试试以下:

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

#2


0  

You insert one empty value:

插入一个空值:

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

This is not safe way. Use prepared statements.

这不是安全的方法。使用预处理语句。

#3


0  

fyi:

仅供参考:

when i was input manually the data in mysql with this :

当我手工输入mysql数据时:

INSERT INTO cfs ( id_cfs , namapenyakit , namagejalaa , mb , md ) VALUES ( 3, 'asma', 'muntah disertai riak', '5', '4' )

插入cfs (id_cfs, namapenyakit, namagejalaa, mb, md)值(3,'asma', 'muntah disertai riak', '5', '4')

it can added.. but i still dont know how to make the data that I input in form_input.php can insert into my database...

它可以添加. .但是我仍然不知道如何将输入的数据输入form_input。php可以插入到我的数据库中…

#1


2  

In your insert query you are passing 5 values corresponding to the 4 columns mentioned by you and for columns you are using wrong quotes.

在您的插入查询中,您将传递与您所提到的4列相对应的5个值,以及您使用错误引用的列。

Try the following:

试试以下:

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

#2


0  

You insert one empty value:

插入一个空值:

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

This is not safe way. Use prepared statements.

这不是安全的方法。使用预处理语句。

#3


0  

fyi:

仅供参考:

when i was input manually the data in mysql with this :

当我手工输入mysql数据时:

INSERT INTO cfs ( id_cfs , namapenyakit , namagejalaa , mb , md ) VALUES ( 3, 'asma', 'muntah disertai riak', '5', '4' )

插入cfs (id_cfs, namapenyakit, namagejalaa, mb, md)值(3,'asma', 'muntah disertai riak', '5', '4')

it can added.. but i still dont know how to make the data that I input in form_input.php can insert into my database...

它可以添加. .但是我仍然不知道如何将输入的数据输入form_input。php可以插入到我的数据库中…