0

I am trying to insert data into the mysql table using php... but whenever i fill the form and insert data, it updates it but no exact data is present in my table, there is only 1's present in the records rather than actual data which i have inserted. Kindly help me out in this...

I have the following code:

<!DOCTYPE html>
<?php

$hostname = "localhost";
$username = "root";
$password = "";

$db_connect = mysql_connect($hostname, $username, $password);

if (!$db_connect){
    die("Database Connection Failed: " . mysql_error());
    }

$db_select = mysql_select_db("hamdard_attendance", $db_connect);
if (!$db_select){
    die("Database Selection Failed: " . mysql_error());
    }

?>
<html>
<head>
<title>Demo Beautiful Registration Form with HTML5 and CSS3</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="style.css" media="all" />
    <link rel="stylesheet" type="text/css" href="demo.css" media="all" />
</head>
<body>

<?php

$name = isset($_POST['name']);
$user_name = isset($_POST['username']);
$user_password = isset($_POST['password']);
$mail = isset($_POST['email']);
$phone_no = isset($_POST['phone']);

$db_query = mysql_query("INSERT INTO users(name, email, user_name, user_pass, contact_number)VALUES('{$name}','{$mail}','{$user_name}','{$user_password}','{$phone_no}')", $db_connect);

echo "Data Added";

if(!$db_query){
    die("Database Query Failed: " . mysql_error());
    }
?>

<div class="container">
            <!-- freshdesignweb top bar -->
            <div class="freshdesignweb-top">
                <a href="http://www.freshdesignweb.com" target="_blank">Home</a>
                <span class="right">
                    <a href="http://www.freshdesignweb.com/beautiful-registration-form-with-html5-and-css3.html">
                        <strong>Back to Login Page</strong>
                    </a>
                </span>
                <div class="clr"></div>
            </div><!--/ freshdesignweb top bar -->
            <header>
                <h1><span>Hamdard Institute of Information Technology</span> Quality Management Cell Registration</h1>
            </header>       
      <div  class="form">
            <form id="contactform" method="post" action="index.php"> 
                <p class="contact"><label for="name">Name</label></p> 
                <input id="name" name="name" value="name" placeholder="First and last name" required tabindex="1" type="text"> 

                <p class="contact"><label for="email">Email</label></p> 
                <input id="email" name="email" placeholder="example@domain.com" required type="email"> 

                <p class="contact"><label for="username">Create a username</label></p> 
                <input id="username" name="username" placeholder="username" required tabindex="2" type="text"> 

                <p class="contact"><label for="password">Create a password</label></p> 
                <input type="password" id="password" name="password" required> 
                <p class="contact"><label for="repassword">Confirm your password</label></p> 
                <input type="password" id="repassword" name="repassword" required> 

               <fieldset>
                 <label>Birthday</label>
                  <label class="month"> 
                  <select class="select-style" name="BirthMonth">
                  <option value="">Month</option>
                  <option  value="01">January</option>
                  <option value="02">February</option>
                  <option value="03" >March</option>
                  <option value="04">April</option>
                  <option value="05">May</option>
                  <option value="06">June</option>
                  <option value="07">July</option>
                  <option value="08">August</option>
                  <option value="09">September</option>
                  <option value="10">October</option>
                  <option value="11">November</option>
                  <option value="12" >December</option>
                  </label>
                 </select>    
                <label>Day<input class="birthday" maxlength="2" name="BirthDay"  placeholder="Day" required></label>
                <label>Year <input class="birthyear" maxlength="4" name="BirthYear" placeholder="Year" required></label>
              </fieldset>

            <select class="select-style gender" name="gender">
            <option value="select">i am..</option>
            <option value="m">Male</option>
            <option value="f">Female</option>
            <option value="others">Other</option>
            </select><br><br>

            <p class="contact"><label for="phone">Mobile phone</label></p> 
            <input id="phone" name="phone" placeholder="phone number" required type="text"> <br>
            <input class="buttom" name="submit" id="submit" tabindex="5" value="Register" type="submit">      
   </form> 
</div>      
</div>

</body>
</html>
<?php
mysql_close($db_connect);
?>
3
Contributors
4
Replies
18
Views
3 Years
Discussion Span
Last Post by gabrielcastillo
1

Change

$name = isset($_POST['name']);
$user_name = isset($_POST['username']);
$user_password = isset($_POST['password']);
$mail = isset($_POST['email']);
$phone_no = isset($_POST['phone']);

To:

$name = mysql_real_escape_string($_POST['name']);
$user_name = mysql_real_escape_string($_POST['username']);
$user_password = mysql_real_escape_string($_POST['password']);
$mail = mysql_real_escape_string($_POST['email']);
$phone_no = mysql_real_escape_string($_POST['phone']);

For the want of anything better. Use mysqli or PDO - mysql_* functions have been deprecated.

0

I tried both of the approaches of yours, but it doesn't work. No matter whatever data i'm inserting, it only inserts one in my database record. What kind of problem is this?

0

hey i solved the problems, it was my mistake i wasn't checking my fields into if statments as:

if(isset....

Thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.