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;
        }
 ?>
6
  • verify your DB connection was working, and just execute your "insert into..." query in mysqli server. Commented Dec 28, 2015 at 7:45
  • 1
    NUL, thats the problem it would be NULL Commented Dec 28, 2015 at 7: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 Commented Dec 28, 2015 at 7:47
  • Also check this post never start to learn bad habits. Commented Dec 28, 2015 at 7:50
  • Changing the NULL didnt do it and the db is connected.Im able to add stuff via phpmyadmin no problems Commented Dec 28, 2015 at 7:52

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.