Jump to content

my data is not going to the database


dark k58

Recommended Posts

I got this code for a register page, it worked in my other website but when i copied it and edited the fields on my new website, it shows no errors but no data it being inserted in the database

 

it does say that the registration is successful, please help

 

thanks

 

this is the code:

 


  <?php
     
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ?>
     
    <?php

     
    // Connect to the MySQL database
    include "../storescripts/connect_to_mysql.php";
     
     
    //This code runs if the form has been submitted
     
    if (isset($_POST['submit'])) {
     
     
     
    //This makes sure they did not leave any fields blank
     
    if (!$_POST['firstname'] | !$_POST['surname'] | !$_POST['business_name'] | !$_POST['address1'] | !$_POST['city'] | !$_POST['postcode'] | !$_POST['telephone_number'] | !$_POST['mobile_number'] | !$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['email'] ) {
     
   header("location: register_user_fail.php");
exit(); 
     
    }
     
     
     
    // checks if the username is in use
     
    if (!get_magic_quotes_gpc()) {
     
    $_POST['username'] = addslashes($_POST['username']);
     
    }
     
    $usercheck = $_POST['username'];
     
    $check = mysql_query("SELECT username FROM user WHERE username = '$usercheck'")
     
    or die(mysql_error());
     
    $check2 = mysql_num_rows($check);
     
     
     
    //if the name exists it gives an error
     
    if ($check2 != 0) {
     
     header("location: username_is_used.php");
exit(); 
     
     
    } 
     
     
    // this makes sure both passwords entered match
     
    if ($_POST['pass'] != $_POST['pass2']) {
     
   header("location: password_don't_match.php");
exit(); 
     
    }
     
     
     
     
     
    // now we insert it into the database
     
    $insert = "INSERT INTO user (firstname, surname, business_name, address1, address2, address3, postcode, city, telephone_number, mobile_number, username, password, email)
     
    VALUES ('".$_POST['firstname']."', '".$_POST['surname']."', '".$_POST['business_name']."', '".$_POST['address1']."', '".$_POST['address2']."', '".$_POST['address3']."', '".$_POST['postcode']."', '".$_POST['telephone_number']."', '".$_POST['mobile_number']."', '".$_POST['username']."', '".$_POST['pass']."', '".$_POST['email']."')";
     
    $add_member = mysql_query($insert);
     
    ?>
     
     <?php
      header("location: register_success.php");
exit(); ?>

     
    
    <?php
    }
     
    else
    {
    ?>
     
    <!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>User Register</title>
    <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
    </head>
    <body>
    <div align="center" id="wrapper">
    <?php include_once("user_login_template_header.php");?>
    <div id="content">
    <table width="100%" border="0" cellspacing="0" cellpadding="10">
    <tr>
    <td width="32%" valign="top">
    </td>
    <td width="35%" valign="top">
     
     
     
     
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
     
    <table border="0">
     
<tr><td>First Name:</td><td>
     
    <input type="text" name="firstname" maxlength="60">
     
    </td></tr>

<tr><td>Surname:</td><td>
     
    <input type="text" name="surname" maxlength="60">
     
    </td></tr>

<tr><td>Business Name:</td><td>
     
    <input type="text" name="business_name" maxlength="60">
     
    </td></tr>

<tr><td>Address 1:</td><td>
     
    <input type="text" name="address1" maxlength="60">
     
    </td></tr>

<tr><td>Address 2:</td><td>
     
    <input type="text" name="address2" maxlength="60">
     
    </td></tr>
    
    
    <tr><td>Address 3:</td><td>
     
    <input type="text" name="address3" maxlength="60">
     
    </td></tr>
    

<tr><td>Postcode:</td><td>
     
    <input type="text" name="postcode" maxlength="9">
     
    </td></tr>
    
    
      <tr><td>City:</td><td>
     
    <input type="text" name="city" maxlength="60">
     
    </td></tr>
    

<tr><td>Telephone Number:</td><td>
     
    <input type="text" name="telephone_number" maxlength="12">
     
    </td></tr>
    
    <tr><td>Mobile Number:</td><td>
     
    <input type="text" name="mobile_number" maxlength="12">
     
    </td></tr>

    <tr><td>Username:</td><td>
     
    <input type="text" name="username" maxlength="60">
     
    </td></tr>
     
    <tr><td>Password:</td><td>
     
    <input type="password" name="pass" maxlength="25">
     
    </td></tr>
     
    <tr><td>Confirm Password:</td><td>
     
    <input type="password" name="pass2" maxlength="25">
     
    </td></tr>
     
  <tr><td>Email:</td><td>
     
    <input type="email" name="email" maxlength="60">
     
    </td></tr>
    <tr><th colspan=2><input type="submit" name="submit"
    value="Register"></th></tr> </table>
     
    </form>
     
     
     
    <br />
    </p>
    <p><br />
    </p></td>
    <td width="33%" valign="top">
    </td>
    </tr>
    </table>
     
    </div>
    <?php include_once("../footer.php");?>
    </div>
    </body>
    </html>
    <?php
     
    }
    ?>

Link to comment
Share on other sites

This line that I addedfor you should have given an error:

if (!$add_member) echo "$insert<br/>".mysql_error();

 

You have 13 fields and 12 values ( city is missing a value)

 

yah I've already added that before,

 

I don't know why but i got no errors

Link to comment
Share on other sites

You are probably not seeing any error message from the echo .... mysql_error() statement, because your page is redirecting and you likely have output_buffering turned on in your php.ini. Is the URL in your browser for the page where your INSERT query is on or is it for the register_success.php page?

 

For debugging purposes, temporarily add an exit;/die; statement (or put the msyql_error statement inside of a die() statement) so that you know what execution path your code is actually taking.

 

Also, you should not redirect to the register_success.php unless you have tested that the INSERT query actually executed without any errors and that it inserted the row into the table. See: mysql_affected_rows

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.