0

My Sign Up fields are not inserting into the database, just rows are incremented.

HTML markup:

    <body><h1 class="headingStyle">Sign Up</h1>
        <form action="SignUp.php" method="post">
        <table width="284" border="1" align="center">
      <tr>
        <td width="128" class="style1">User Name</td>
        <td width="144"><input type="text" name="u_name" id="u_name"></td>
      </tr>
      <tr>
        <td class="style1">Email</td>
        <td><input type="text" name="email" id="email"></td>
      </tr>
      <tr>
        <td class="style1">Password</td>
        <td><input type="password" name="pass" id="pass"></td>
      </tr>
      <tr>
        <td colspan="2" class="buttonStyle"><input type="submit" name="submit" value="Sign Up"></td>
      </tr>
    </table>
    </form>
    </body>

This is the php code, it is not inserting anything to my table just incrementing the rows. I have given the snapshot of my table as well.

<?php
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());

$db = mysql_select_db('aartycrafty_db', $conn) or die(mysql_error());

if (isset($_POST['submit'])) /*if sign up button is pressed than */
{
    $name = $_POST['u_name'];
    $email = $_POST['email'];
    $pass = $_POST['pass'];

    if($name == '')
    {
        echo "<script>alert('Please Enter Your Name')</script>";
        exit();
    }
    if($email == '')
    {
        echo "<script>alert('Please Enter Your Email')</script>";
        exit();
    }
    if($pass == '')
    {
        echo "<script>alert('Please Enter Your Password')</script>";
        exit();
    }
}
else {
    $query = "insert into signup_tb (u_name, u_email, u_pass) values ('$name', '$email', '$pass')";

    if(mysql_query($query)){
        echo "<script>window.open('home.php')</script>";
    }
}

?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Student
  • 1
  • 3
  • any errors ? use `mysqli` – Madhawa Priyashantha May 01 '16 at 06:43
  • no, there isn't any error – Student May 01 '16 at 06:45
  • do you want to insert when user submits the form? Then you should move the insertion code into `if (isset($_POST['submit']) {}` block – Ruslan Osmanov May 01 '16 at 06:55
  • Warning: The `mysql_*` functions are [no longer supported or maintained](http://stackoverflow.com/questions/12859942). They were [deprecated in PHP 5.5.0](https://wiki.php.net/rfc/mysql_deprecation) and [removed in PHP 7.0.0](http://php.net/manual/en/function.mysql-connect.php#function.mysql-connect-refsynopsisdiv). You are strongly encouraged to migrate to either [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO_MySQL](http://php.net/manual/en/ref.pdo-mysql.php). – Pang May 01 '16 at 07:03
  • Warning: Your code is vulnerable to [SQL injection attacks](https://en.wikipedia.org/wiki/SQL_injection). Please read [this post](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) to learn more on how to prevent it. – Pang May 01 '16 at 07:04

0 Answers0