0

being long since i wrote in php, am presently trying to do a simple insert, but its not working and no errors shown, seen some previous complaints concerning this issue but non of their solutions have helped me, the table contains this columns user_id,username,password,permission. The code is below.

 <?php
 include('connect.php');
 //Start session
 session_start();
 ?>



<div id="wrapper">

    <!-- Navigation -->
    <?php include('header.php'); ?>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Create User</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        Fill in all details 
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-12">
                                <form role="form">
                                    <div class="col-lg-4">
                                    <div class="form-group">

                                        <input class="form-control" name="usernamei" id="inputUsername" placeholder="Username">
                                    </div>
                                  </div>

                                  <div class="col-lg-4">
                                    <div class="form-group">

                                        <input class="form-control" name="passwordi" id="inputPassword" placeholder="Password">
                                    </div>
                                  </div>



                            <div class="col-lg-4">
                                   <div class="form-group">

                                        <select class="form-control" name="permissioni" id="inputPermission">
                                            <option>1</option>
                                            <option>2</option>
                                            <option>3</option>
                                            <option>4</option>
                                            <option>5</option>
                                        </select>
                                    </div>
                                  </div>


                                    <button type="submit" class="btn btn-primary">Submit Button</button>
                                    <button type="reset" class="btn btn-primary">Reset Button</button>
                                </form>
                            </div>

                        </div>
                        <!-- /.row (nested) -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->

</div>



 <?php
        if($_SERVER['REQUEST_METHOD']=='POST'){

            $myusername = mysqli_real_escape_string($conn,$_POST['usernamei']);
            $mypassword = mysqli_real_escape_string($conn,$_POST['passwordi']);
            $mypermission = mysqli_real_escape_string($conn,$_POST['permissioni']);

            $sql =  "INSERT INTO user(username, password, permission)
                    VALUES('$myusername', '$mypassword', '$mypermission')";
            $r = mysqli_query ($conn, $sql);
                    if ($r) {
                echo "success";
            }else{
                echo mysqli_error($conn);
            }

        mysqli_close($conn);

        }

?>

henry
  • 81
  • 2
  • 9
  • Aren't you missing a space after the table name? INSERT INTO user (username instead of INSERT INTO user(username – PalDev Oct 09 '16 at 09:09
  • And a space too many with `mysqli_query` , also is `$conn` defined correctly? – RST Oct 09 '16 at 09:12
  • just added the space, it still gives me the same result @PalDev – henry Oct 09 '16 at 09:12
  • $conn is from is my connect.php that i use to connect to my database. used this same process for my login @RST – henry Oct 09 '16 at 09:15
  • 1
    You have missed to define `method="POST"` in the `Form`. Because it is default by taking GET request. That mean `
    ` replace with `
    `
    – AHJeebon Oct 09 '16 at 09:16
  • lool, very silly mistake, it just worked, missed post. thanks a lot – henry Oct 09 '16 at 09:20

1 Answers1

0

I can assure you that it is generating an error. It is just not displaying it. In order to get it to display the error, you have to follow these steps.

1) Open your php.ini file

2) Find the line marked

display_errors = Off

3) Change the line to say on

display_errors = On

4) Save the file

5) restart your server

Then the error will display and this will make it much easier to deal with the situation. If you are on a production server remember to turn the display errors back off after you are done trouble shooting the issue.

kayleighsdaddy
  • 670
  • 5
  • 15