komal deep singh chahal
komal deep singh chahal

Reputation: 1259

insertion is not happening in php and mysql form

My database fields are: id,name,email_id,address,phone_no,username,password,category,date

<?php
     include_once('connect_to_mysql.php');

     if(isset($_POST["submit"])){
        $a=mysql_real_escape_string($_POST["name"]);
        $b=mysql_real_escape_string($_POST["email"]);
        $c=mysql_real_escape_string($_POST["address"]);
        $d=mysql_real_escape_string($_POST["phoneno"]);
        $e=mysql_real_escape_string($_POST["user"]);
        $f=mysql_real_escape_string($_POST["pass"]);
        $g=mysql_real_escape_string($_POST["category"]);

        $res=mysql_query("insert into reg(name, email_id, address, phone_no, username, password, category, date ) values ( '$a', '$b', '$c', '$d', '$e', 'md5[$f]', '$g', now() )")  or die (mysql_error() );
        $id = mysql_insert_id();
    }
?>

There's no error reported when using the submit button, but found data is not inserted into database. I don't know what causes this.

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title> Register </title>

  </head>

   <body>

       <div id="heading12"><?php //include_once("header.html") ?></div>
           <br /><br /><br /><br /><br /><br /><br />
       <div id="mainWrapper" style="background-color:#ECEEFB">

       <div align="center" id="pageContent" style="background-image:url(back3.png); width:1000px;"><br /><br /><br />
       <div align="center" style="color:#000000;">
       <h2 style="font-size:36px">Please Fill Your all Details to Register</h2>
       <br /><br />
       <form id="form" name="form" method="post" action="register.php">
         <h2 style="padding-right:200px;"> Name:</h2>
         <input name="name" type="text" id="name" size="40" style="height:30px; font-size:20px " required placeholder="Enter NAME"/>
           <br /><br />

        <h2 style="padding-right:200px;">Email Address:</h2>
        <input name="email" type="text" id="email" size="40" style="height:30px; font-size:20px " required placeholder="Enter Email Address"/>
           <br /><br />

        <h2 style="padding-right:200px;">Address</h2>
        <textarea name="address" id="address" cols="44" rows="6" style="font-size:19px " required placeholder="Enter Address"></textarea>
   <br /><br />

        <h2 style="padding-right:200px;">Phone No.</h2>
        <input name="phoneno" type="text" id="phoneno" size="40" style="height:30px; font-size:20px" required placeholder="Enter Phone No."/>
        <br /><br />

        <h2 style="padding-right:200px;">User Name:</h2>
        <input name="user" type="text" id="user" size="40" style="height:30px; font-size:20px" required placeholder="Enter UserName"/>
        <br /><br />

        <h2 style="padding-right:210px;">Password:</h2>
        <input name="pass" type="password" id="pass" size="40" style="height:30px; font-size:20px" required placeholder="Enter Password"/>
        <br /> <br />

        <h2 style="padding-right:250px;">Category:</h2> 
        <select name="category" id="category" style="height:30px; font-size:20px; padding-right:290px;" required placeholder="Enter The Value" >
           <option value="none">Choose Any</option>
           <option value="product buyer">Product Buyer</option>
           <option value="product seller">Product Seller</option>
       </select>
       <br /> <br />

       <img style="padding-right:280px;" src="generate.php"><br /><br />
       <input type="text" name="secure" size="10" required placeholder="Enter The Value" style="padding-right:290px; height:30px; font-size:20px">
       <br />  <br /> <br />
       <input type="submit" name="log" id="log" value="Register"  style="padding-right:40px; font-size:20px" />

    </form>
    <p>&nbsp; </p>
 </div>
   <br />
  <br />
   <br />
    </div>

    </div>
      </body>
    </html>

Upvotes: 0

Views: 82

Answers (3)

Indrasis Datta
Indrasis Datta

Reputation: 8618

Please look at the HTML for the submit button -> input type="submit"

In your php code, you're checking if a submit button with a name "submit" exists, but actually, the name of the submit button is "log"

if(isset($_POST["submit"])) needs to be changed to if(isset($_POST["log"]))

That's all! :)

Upvotes: 1

Faraz Ali
Faraz Ali

Reputation: 28

your condition is looking for $_POST['submit']

$_POST['submit'] is not present

replace $_POST['submit'] by $_POST and it gets your all data

one more thing Php eliminate mysql for some reason, use mysqli for database connections and query's

Upvotes: 1

Tyler Collins
Tyler Collins

Reputation: 127

you have nothing with a name of "submit". $_POST['submit'] is never set, and your if function never runs.

Upvotes: 2

Related Questions