php - Cannot insert values into database from HTML Forms

351

I'm having trouble inserting values to the database from the HTML form. Here is my code:

http://pastebin.com/HhynqRnF

Can someone help me out? Thanks!

949

Answer

Solution:

first you need to create mysql connection .and change your code into this code.

  <?php 
    $con = mysqli_connect("localhost", "root", "", "my_db"); //create connection
    if(isset($_POST['submit']))
    {    

     $name = $_POST['fullname'];
     $username = $_POST['username'];
     $email = $_POST['email'];
     $password = $_POST['password'];
     $sql = "INSERT INTO users (name, username, email, password) VALUES ('$name', '$username', '$email', '$password')";
     $result = mysqli_query($con, $sql);
    }
   ?>

<form action="" method="post">


      <div >
       <label>
        Name<span >*</span>
       </label>
       <input name="fullname" type="text" required autocomplete="off" />
      </div>

      <div >
       <label>
        Username<span >*</span>
       </label>
       <input name="username" type="text" required autocomplete="off" />
      </div>


     <div >
      <label>
       Email Address<span >*</span>
      </label>
      <input name="email" type="text" required autocomplete="off"/>
     </div>

     <div >
      <label>
       Set A Password<span >*</span>
      </label>
      <input name="password" type="password" required autocomplete="off"/>
     </div>

     <button type="submit" />Create Account</button>



     </form>
404

Answer

Solution:

Try Using This

$sql = "INSERT INTO `users` (`name`, `username`, `email`, `password`) VALUES ('$name', '$username', '$email', '$password')";

People are also looking for solutions to the problem: javascript - Embeding web page with changing content

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.