Jump to content

Why Won't This Script Add The Data to MySQL? >.<


Vermillion

Recommended Posts

Hey guys, I'm having quite a weird problem with PHP not adding the information to the database upon submitting a form. This script works with two queries to add information: One to add information to the members table, and one to add the information to the user_prefs table. However for some reason, only the information to user_prefs is being added.

 

 

Here is a picture of the members table.

 

And here is the code I use to add the data to the database (I have added many #'s at the end and beginning of the part that adds the data):

 

<?php

require "../forum/config/config.php";
awings_connect();
session_start();

?>

<!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" />
<meta name="description" content="The open project for everyone learning how to program, or compose music, or more!" />
<meta name="keywords" content="project, awings, forums, forum, action, replay, ds, subscription, psp, consoles, homebrew, register" />
<title>Project Awings</title>
<link rel="stylesheet" href="../forum/style/css.css" />
<link rel="shortcut icon" href="../forum/graphics/favicon.ico"  />
</head>

<body id="noforum">


<?php
include "../includes/nonforumh.php";
?><br />

<table>
<tr>

<td valign="top"><?php include "../includes/mainmenu.php"; ?></td>
<td width="95%" valign="top" align="center"><?php

  include "../forum/classes/class.registervalidator.php";

  $member = new member;

  $register[0] = $member -> checkChars($_POST['username']);
  $register[1] = $member -> checkUserLength($_POST['username']);
  $register[2] = $member -> checkExistence($_POST['username']);
  $register[3] = $member -> valPassword($_POST['password'], $_POST['password1']);
  $register[4] = $member -> checkPassChars($_POST['password']);
  $register[5] = $member -> validateEmail($_POST['email']);
  $register[6] = $member -> checkMailExistence($_POST['email']);
  $register[7] = $member -> validateQuestion($_POST['sequ']);
  $register[8] = $member -> validateAnswer($_POST['seans']);
  $register[9] = $member -> validateFName($_POST['fname']);
  $register[10] = $member -> validateLName($_POST['lname']);

  $register_error_message[0] = "<li>Your username contains invalid characters. Please make sure your username only contains alphanumeric characters, underscores, and spaces.</li>";
  $register_error_message[1] = "<li>Your username must contain at least 3 characters.</li>";
  $register_error_message[2] = "<li>The username you chose is already in use. Please choose another one.</li>";
  $register_error_message[3] = "<li>The passwords you put did not match.</li>";
  $register_error_message[4] = "<li>Your password must include at least 6 characters.</li>";
  $register_error_message[5] = "<li>The Email you input is invalid. Did you include an \"@\" and the respective dots?</li>";
  $register_error_message[6] = "<li>The Email you input is already in use. Please use another one.</li>";
  $register_error_message[7] = "<li>The secret question must have 10 or more characters.</li>";
  $register_error_message[8] = "<li>Your secret answer must have 4 or more characters</li>";
  $register_error_message[9] = "<li>The First Name field has invalid characters.</li>";
  $register_error_message[10] = "<li>The Last Name field has invalid characters.</li>";


  #print_r($register); //Confirm if the array works. Uncomment in case of debugging.

  $errors = array_keys($register, 1);

  if(count($errors) > 0){

     echo "<div class=\"boxcontainer\" style=\"width:70%; padding-top:0px; margin:0px;\"><div class=\"title_boxcontainer\" align=\"center\">Errors Detected:</div>";
     echo "<ul id=\"errormessages\">";
   
      foreach($register as $key => $value){
      
         if($value == 1){
         
            echo $register_error_message[$key];
         
         }
      
      }

   echo "</ul>";
   echo "</div><br />";
   include "../includes/registerform.php";

} else {

########################
########################
########################

   $user = trim($_POST['username']);
   $password = md5($_POST['password']);
   $email = mysql_real_escape_string($_POST['email']);
   $question = mysql_real_escape_string($_POST['sequ']);
   $answer = mysql_real_escape_string($_POST['seans']);
   $fname = mysql_real_escape_string($_POST['fname']);
   $lname = mysql_real_escape_string($_POST['lname']);
   $bdate = $_POST['year']."-".$_POST['month']."-".$_POST['date'];
   $gender = $_POST['gender'];
   $date = date("Y-m-d");
   $time = date("g:i A");
   $initialip = $_SERVER['REMOTE_ADDR'];

   echo "<div class=\"boxcontainer\" align=\"center\" style=\"width:70%; margin-top:25%; margin-left:20%;\"><div class=\"title_boxcontainer\" align=\"center\">Registration Succesfull:</div>";   
   echo "You have registered succesfully, <strong>$user</strong>! <br />You may start using your account now.";
   echo "</div>";

   $id_ = mysql_fetch_array(mysql_query("SELECT * FROM members ORDER BY id DESC LIMIT 1"));
   $id = $id_['id'] + 1;
   
   mysql_query("INSERT INTO members (username, password, email, question, answer, name, lname, birthday, gender, date, time, ip) VALUES ('$user', '$password', '$email', '$question', '$answer', '$fname', '$lname', '$bdate', '$gender', '$date', '$time', '$initialip')");
   
  mysql_query("INSERT INTO user_prefs(user_id) VALUES('$id')");

}

########################
########################
########################

?>

</td>
<td valign="top"><?php include "../includes/siteusernav.php"; ?></td>

</tr>
</table>

</body>
</html>

 

Any help will be highly appreciated =(.

Are you receiving an error of any kind? Or is it just not outputting anything? You can try modifying all your mysql_query statements to look like this:

 

mysql_query('your statment') or die(mysql_error())

 

And if it outputs an error, just let us know what the error is.

Fixed it by basically recreating the database and rewriting the script >>;.

Thanks for the help anyways.

 

And I would have tested if there is any errors, but my host (07x) does not support PHP error messages. Beautiful, huh?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.