0

I have HTML registration form when I submit the form the PHP code appears and data not insert to database i made my database using phpMyAdmin, what should I do?

Here my PHP code:

     <?php
        $con=mysqli_connect('localhost','root','');
        $db=mysqli_select_db($con,'research_sys');
    if ($con) {
        echo "good";
        }else {
        die('error');
        }
        if(isset($_POST['submit'])){
$Fname = mysqli_real_escape_string($con,$_POST["Fname"]);
$Lname = mysqli_real_escape_string($con,$_POST["Lname"]);
$email = mysqli_real_escape_string($con,$_POST['email']);
$password = mysqli_real_escape_string($con,$_POST['password']);
    $sql =  mysqli_query($con,"INSERT INTO `research_sys`.`researcher` (Re_fname,Re_lname,Re_mobile,Re_password) values ('$Fname','$Lname','$email','$password ')");

            if (mysqli_query($sql)){
            echo "insert";
            } else {
                echo "error" .$sql ."<br>". mysqli_error($con);
                }           
}
?>

here my registration HTML code

            <form method="post" action="connect.php">
                <legend class="center">Register </legend>
                <br>
                <div>

                    <input type="text" name="Fname" placeholder="First Name"/>
                </div>
                <div>

                    <input type="text" name="Lname" placeholder="Last Name"/>
                </div>

                <div>
                    <input type="text" name="email" placeholder="Email"/>
                </div>

                <div>
                    <input type="password" name="password" placeholder="Password"/>
                </div>

                <div>
                    <input type="password" name="con_password" placeholder="Password confirm"/>
                </div>
                <input type="submit" name="submit" value="submit"/>
            </form>

1 Answer 1

1

Look at the following:

$sql =  mysqli_query($con,"INSERT INTO `research_sys`.`researcher` 
        ^^^^^^^^^^^^ function

        (Re_fname,Re_lname,Re_mobile,Re_password) 
        values ('$Fname','$Lname','$email','$password ')");
                                                     ^ space

    if (mysqli_query($sql)){
        ^^^^^^^^^^^^ function

You're using that mysqli_query() function twice, remove one and just do:

if ($sql){...}

and mysqli_error($con) should have thrown you an error about it.

If it didn't throw an error, then that may suggest you're using this as file:/// as opposed to http://localhost.

Edit:

"i have html registration form whin i submit the form the php code apears"

That's because of what I wrote above before quoting you. You need to run this off a webserver with php/mysql installed and running properly and as http://localhost.

Also, remove the space in this '$password '. That space counts as a character.

  • Double-check your column names also. There seems to be something that doesn't match (Re_fname,Re_lname,Re_mobile,Re_password) the Re_mobile and you're referencing an email '$email' in VALUES.

You also seem to store plain text passwords; don't, it's not safe if you intend on going live with this. Use password_hash() and a prepared statement.


Footnotes:

    $con=mysqli_connect('localhost','root','');
    $db=mysqli_select_db($con,'research_sys');

You can shorten that to using all 4 arguments in mysqli_connect():

    $con=mysqli_connect('localhost','root', '', 'research_sys');
Sign up to request clarification or add additional context in comments.

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.