Jump to content

Recommended Posts

I'm probably going blind due to looking at this script all day long! The script was previously working fine and adding users to the database. I have added a few die clauses in and suddenly it does not add users to the database (although the script runs fine without any errors) Could someone spot what I have missed?

 






<?php
include "page.class";

$Sample = new Page;

$Content = "
<HTML>
<BODY>

</BODY>
</HTML>";

$Sample->Title = "Please Join Our Site!";
$Sample->Keywords = "PHP, Classes";
$Sample->SetContent( $Content );

$Sample->Display( );

?>


<?php
// Connects to my Database "db0607197"
mysql_connect("localhost", "0607197", "12345") or die(mysql_error());
mysql_select_db("db0607197") or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {



// 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 Users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('<div class="clean">Sorry, the username '.$_POST['username'].' is already in use.Pick Another One</a>');
}

// Check if passwords match
if ($_POST['pass'] != $_POST['pass2']) {
die('<div class="clean">Your passwords did not match. ');
}

// encrypt the password
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

include "email.class";


$class1 = &New Class1;
$class1->Email = $_POST['email'];
$check_email = $class1->check_email();
if(!$check_email){die
    ('The email address is not valid! ');
} 

include "username.class";

$username = &New Username;
$username->Check = $_POST['username'];
$check_username = $username->check_username();
if(!$check_username){die
    ('Please enter a username ');
} 

include "password.class";

$password = &New Password;
$password->Check4 = $_POST['firstname'];
$check_password = $password->check_password();
if(!$check_password){die
    ('Please enter a password ');
} 

include "firstname.class";

$firstname = &New Firstname;
$firstname->Check5 = $_POST['lastname'];
$check_firstname = $firstname->check_firstname();
if(!$check_firstname){die
    ('Please enter a firstname ');
} 



// Insert the new users info into the database
$insert = "INSERT INTO Users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')";
$add_member = mysql_query($insert);
?>


<div class="clean"><h1>Successfully Registered</h1></div>






<!-- Form to capture Register Information -->


</div>








<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

	<table width="200" border="0" class="centeredtable" >

	<tr><td colspan=2><h1>Register</h1></td></tr>
	<tr><td>First Name:</td><td>
	<input type="text" name="lastname" maxlength="60">
	</td></tr>
        <tr><td>Last Name:</td><td>
	<input type="text" name="firstname" maxlength="60">
	</td></tr>
        
        <tr><td>Email:</td><td>
	<input type="text" name="email" maxlength="60">
	</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="10">
	</td></tr>
	<tr><td>Confirm Password:</td><td>
	<input type="password" name="pass2" maxlength="10">
	</td></tr>
	<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
	</form>









	 Already Registered?



	<a href="login.php">Log In</a>



 

 

Thanks in advance

 

 

Dan

Link to comment
https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/
Share on other sites

I'd be glad to help, but you ripped some code out, and I have no idea if my code flow is remotely accurate to how it is supposed to work. I don't like putting closing brackets in unless I know that's where they are supposed to go. Please post all the code (removing any sensitive data and replacing it with ******** or something).

Your problem lies here:

 

// Insert the new users info into the database

$insert = "INSERT INTO Users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')";
$add_member = mysql_query($insert);

 

 

you need to be sure you have all the fields

for example:

// Insert the new users info into the database

$insert = "INSERT INTO Users (username, password, firstname, lastname, email)   <--- here
VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')";
$add_member = mysql_query($insert);

 

 

you could also add this:

$add_member = mysql_query($insert) or DIE("Error Occured :" . mysql_error());

 

this will tell you if the query has failed.

 

 

Edit:

 

the $end error is due to a miss }  you need to add one at the bottom

 

if (isset($_POST['submit'])) {

 

this block is not closed, add it here:

 

$add_member = mysql_query($insert);
} <--
?>

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.