PDA

View Full Version : My I need PHP help Thread. :)



Dirt_Diver
08-15-2008, 03:54 AM
Can someone help me with my registration page. I installed PHPBB and I am using that database to hold all my user information. Because it is just about all there I thought I could add some other fields and that way if a user logs into my index.php they would already be logged into the forums as well.

so... I changed all my pages and tested it. It's not erroring out but it's not posting new users to the database either. Can someone look this over and tell me where I messed this code up?

table=<phpbb_users>
username and user_password are inside <phpbb_users>

SEE NEW CODE BELOW

Dirt_Diver
08-15-2008, 01:51 PM
Morning Bump

thetestingsite
08-15-2008, 03:10 PM
Remove the highlighted on the following line:



// now we insert it into the database
$insert = "INSERT INTO phpbb_users (user_FirstName, user_LastName, user_email, user_gender, user_city, user_state, user_country, username, password)
VALUES ('".$_POST['user_FirstName']."', '".$_POST['user_LastName']."', '".$_POST['user_email']."', '".$_POST['user_address']."', '".$_POST['user_city']."', '".$_POST['user_state']."', '".$_POST['user_zip']."', '".$_POST['user_country']."', '".$_POST['user_gender']."', '".$_POST['user_website']."', '".$_POST['username']."', '".$_POST['user_password']."')" or die(mysql_error());


Hope this helps.

Dirt_Diver
08-16-2008, 02:41 AM
Nope still didn't work...

And I actually changed the code around to try and make it easier. Can anyone tell me why after I fill in my form I get a blank page and not the success page??? It's not posting to my site, someone?????


<?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['first_name'] ||
!$_POST['last_name'] ||
!$_POST['email'] ||
!$_POST['city'] ||
!$_POST['state'] ||
!$_POST['zip'] ||
!$_POST['gender'] ||
!$_POST['username'] ||
!$_POST['pass'] ||
!$_POST['pass2']) {
die('Whoops!!! Did you forget to fill in one of the fields? Please go back and try again.');
}

// checks if the username is in use
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check) or die(mysql_error());

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username <strong><u>'.$_POST['username'].'</u></stong> has already been taken. Please choose another username.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Whoops!!! I think you made a mistake. We need your passwords to match. Please go back and try again.');
}

// check e-mail format

if (!preg_match("/.*@.*..*/", $_POST['email']) ||
preg_match("/(<|>)/", $_POST['email'])) {
die('Invalid e-mail address.');
}

// no HTML tags in username, website, address, password

$_POST['username'] = strip_tags($_POST['username']);
$_POST['pass'] = strip_tags($_POST['pass']);
$_POST['website'] = strip_tags($_POST['website']);
$_POST['address'] = strip_tags($_POST['address']);

if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) {
die('Nope');
}

if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {
$_POST['website'] = 'http://'.$_POST['website'];
}

// here we encrypt the password and add slashes if needed
// now we insert it into the database
$_POST['pass'] = md5($_POST['pass']);

if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['email'] = addslashes($_POST['email']);
$_POST['website'] = addslashes($_POST['website']);
$_POST['location'] = addslashes($_POST['location']);
}

$regdate = date('m d, Y');

$insert = "INSERT INTO users (
first_name,
last_name,
email,
address,
city,
state,
zip,
country,
regdate,
gender,
website,
show_email,
username,
password,
last_login)
VALUES (
'".$_POST['first_name']."',
'".$_POST['last_name']."',
'".$_POST['email']."',
'".$_POST['address']."',
'".$_POST['city']."',
'".$_POST['state']."',
'".$_POST['zip']."',
'".$_POST['country']."',
'$regdate',
'".$_POST['gender']."',
'".$_POST['website']."',
'".$_POST['show_email']."',
'".$_POST['username']."',
'".$_POST['pass']."',
'Never')";

$add_member = mysql_query($insert);

?>
<?php

*****************THIS IS WHAT SHOULD COME UP AFTER THE USER CREATES THEIR USERNAME************
SUCCESS Congratulations {USERNAME} your sign up was a success, you may now return to the home page and [login]



<style type="text/css">
<!--
.style3 {font-weight: bold}
.style4 {font-weight: bold}
-->
</style>

<center><h1>SUCCESS</h1></center><br><br><br><br>
<center>Congratulations <u><strong><?php
print $_POST['username'];
?></u></strong> your sign up was a success, you may now return to the home page and <a href="index.php">[login]</a></center>


<?php
}
else
{
?>



<form id="FormName" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="FormName">
<table width="448" border="0" cellspacing="2" cellpadding="0">
<tr><td width = "150"><div align="right" class="style3">
<p>
<label for="user_firstname">*First Name:</label>
</p>
</div></td>
<td><input id="user_FirstName" name="user_FirstName" type="text" size="25" value="" maxlength="50"></td></tr><tr><td width = "150"><div align="right" class="style4">
<p>
<label for="user_lastname">*Last Name:</label>
</p>
</div></td>
<td><input id="user_LastName" name="user_LastName" type="text" size="25" value="" maxlength="50"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_email">*Email Address: </label>
</strong></div></td>
<td><input id="user_email" name="user_email" type="text" size="25" value="" maxlength="50"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_address">Address</label>
</strong></div></td>
<td><input id="user_address" name="user_address" type="text" size="25" value="" maxlength="40"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_city">*City:</label>
</strong></div></td>
<td><input id="user_city" name="user_city" type="text" size="25" value="" maxlength="25"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_state">*State:</label>
</strong></div></td>
<td><input id="user_state" name="user_state" type="text" size="25" value="" maxlength="20"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_zip">Postal Code: </label>
</strong></div></td>
<td><input id="user_zip" name="user_zip" type="text" size="25" value="" maxlength="10"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_country">*Country:</label>
</strong></div></td>
<td><input id="user_country" name="user_country" type="text" size="25" value="" maxlength="25"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_gender">*Gender:</label>
</strong></div></td>
<td> <select name="user_gender" id="user_gender">
<option selected>Please Choose</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_website">*Website Address: </label>
</strong></div></td>
<td><input id="user_website" name="user_website" type="text" size="25" value="http://" maxlength="100"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="username">*Username:</label>
</strong></div></td>
<td><input id="username" name="username" type="text" size="25" value="" maxlength="20"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_password">*New Password:</label>
</strong></div></td>
<td><input id="user_password" name="user_password" type="password" size="25" value="" maxlength="25"></td></tr><tr><td width = "150"><div align="right"><strong>
<label for="user_id">*Confirm Password: </label>
</strong></div></td>
<td><input id="pass2" name="pass2" type="password" size="25" value="" maxlength="20"></td></tr><tr><td width="150"></td><td>
<input name="submit" type="submit" id="submit" value="Sign Up"></td>
</tr></table>
</form>


<?php
}
?>

Dirt_Diver
08-16-2008, 04:22 PM
Afternoon crowd bump.

djr33
08-16-2008, 06:58 PM
Stop needlessly bumping your thread. People read when they arrive, and they don't need your thread to be the top one. It just makes you look very impatient.

And Use DESCRIPTIVE titles! (http://dynamicdrive.com/forums/showthread.php?t=24882)

Your code is complex and it's a lot to go through, so have some patience.

Starting with the basics, you may want to try commenting out ALL of the instances of "or die(mysql_error());"

Also, aside from printing out errors, your "check_empty_fields()" is doing nothing. It returns true/false, but you don't act on that, such as disabling registration.

Beyond that, it looks like the entire structure of your page is a bit off:
If POST is sent, do the check. Else, do the form.
But what if the form is not completely filled out? Shouldn't it go back to the form then, after doing the check?
I think you need to create a new tracking variable called something like "$success" which is set to 1, and set that to 0 if something gets in the way of the process. And then check if $success==0 and if so, display the form.

Aside from that, we'd need some more information about what exactly is displayed in what circumstance.

The other thing you can do, which is what we could do if we could change your script while it was running in order to debug, is to check what variables are at certain points in the script. Basically, if you just watch along as the script does what it does, you can usually find where the mistake comes in.

Dirt_Diver
08-19-2008, 11:45 PM
Thoughts anyone??? I thought I would wait a few days and see if anyone comes up with anything but I guess I'm outta sight outta mind.

djr33
08-20-2008, 12:03 AM
You need to do the work. We've given you enough info, and we can help if you have anything specific, but just asking us to fix it is a bit much. If you really need hands-off help, perhaps the paid work requests forum would be a faster approach for you.

Dirt_Diver
08-21-2008, 07:13 PM
edited to adjust problem

Dirt_Diver
08-22-2008, 12:20 AM
Okay now I am back to my original problem... It's not displaying information or posting info to my DB. **See code above

Dirt_Diver
08-22-2008, 12:55 AM
You need to do the work. We've given you enough info, and we can help if you have anything specific, but just asking us to fix it is a bit much. If you really need hands-off help, perhaps the paid work requests forum would be a faster approach for you.

I don't understand your info. I'm not a coder that's why I am here learning it.

tech_support
08-22-2008, 01:36 PM
Try replacing this
$add_member = mysql_query($insert);
with this
$add_member = mysql_query($insert) or die(mysql_error()); and post whatever it says.

Dirt_Diver
08-22-2008, 01:41 PM
I get the same thing... nothing.

The page is here.
http://www.treasureshackonline.com/add.php
If you fill out the form it's like it goes through but does not post the success text or post the data to the database.

BTW Thank you for helping me.

To see what I am talking about fill out the form. Info can be fake I don't care just looking for a solution to the frustration.

Dirt_Diver
08-25-2008, 12:22 PM
Okay I figured it out...