0

I'm trying to insert data from a html form into a sql database. when I click submit it should put the data the form into a table named jin but it is failing to do so. I am terribly new to php and sql so it may have been a stupid mistake.

<form action="insertform.php" method="post">
   Jin Number:<input type="text" name="jin_n"><br>
   Jin Name:<input type="text" name="jin_name"><br>
   Jin Alt(No Kanji):<input type="text" name="jin_alt"><br>
   Number of pages:<input type="text" name="jin_p"><br>
   Summary:<input type="text" name="jin_s"><br>
   <input type="submit" name="Enter">
</form>
<?php
   include "dbconnect.php";
   if(isset($_POST['Enter'])){
//
    $sqli_code="INSERT INTO jin (JIN_NUM, JIN_NAME, JIN_ALT`, JIN_PGS, JIN_SUM) VALUES(
    NUL,
   '$_POST[jin_name]',
   '$_POST[jin_alt]',
   '$_POST[jin_p]',
   '$_POST[jin_s]')";   
    echo "<br><br><br> SQLI_CODE: ", $sqli_code;    
    mysqli_query($dbconnect,$sqli_code);    
   };
?>

//dbconnect.php
<?php
   $dbconnect = mysqli_connect("localhost","root","","nururu");
    if(mysqli_connect_errno())
       {
        echo 'Connection Error' .msqli_connect_error();
        exit;
        }
 ?>
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Chanヨネ
  • 809
  • 1
  • 8
  • 11
  • verify your DB connection was working, and just execute your "insert into..." query in mysqli server. – dinesh Dec 28 '15 at 07:45
  • 1
    `NUL,` thats the problem it would be `NULL` – Saty Dec 28 '15 at 07:46
  • 1
    you should be using like `'{$_POST['jin_name']}'` <-- notice the braces and the additional quotes. Note: Your code is prone to SQL injection. Try using [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – bansi Dec 28 '15 at 07:47
  • Also check [this post](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) never start to learn bad habits. – bansi Dec 28 '15 at 07:50
  • Changing the NULL didnt do it and the db is connected.Im able to add stuff via phpmyadmin no problems – Chanヨネ Dec 28 '15 at 07:52
  • are you sure in phpmyadmin execute the query after you have echo in 'SQLI_CODE:'? – dinesh Dec 28 '15 at 08:01

2 Answers2

1

change

(JIN_NUM, JIN_NAME, JIN_ALT`, JIN_PGS, JIN_SUM)

to

(JIN_NUM, JIN_NAME, JIN_ALT, JIN_PGS, JIN_SUM)

You can see a ' extra in this.

and NUL? I hope you meant NULL

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0

Some silly mistake in code. this code help you.

<?php
    include "dbconnect.php";
    if(isset($_POST['Enter'])){

    $sqli_code="INSERT INTO jin (JIN_NUM, JIN_NAME, JIN_ALT, JIN_PGS, JIN_SUM) VALUES(
    '',
   '$_POST[jin_name]',
   '$_POST[jin_alt]',
   '$_POST[jin_p]',
   '$_POST[jin_s]')";   
    echo "<br><br><br> SQLI_CODE: ", $sqli_code;    
    mysqli_query($dbconnect,$sqli_code);    
   };
 ?>
Mukesh Singh Thakur
  • 1,335
  • 2
  • 10
  • 23