jamesjmann Posted February 3, 2011 Share Posted February 3, 2011 I'm trying to build a login system and alot of the code is similar to what i used to make my news cms. basically all i wanna accomplish right now is to get the user input inserted into my database. I've already tested it out, and I get no errors, but like with the cms, the database isn't getting queryed. Here's the code: (process.php) <?php $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $age=$_POST['age']; $city=$_POST['city']; $state=$_POST['state']; $country=$_POST['country']; $zip=$_POST['zip']; $birthdate=$_POST['birthdate']; $gender=$_POST['gender']; $sexuality=$_POST['sexuality']; $race=$_POST['race']; $religion=$_POST['religion']; $status=$_POST['status']; $about=$_POST['about']; $website=$_POST['website']; $user_name=$_POST['user_name']; $password=$_POST['password']; $email=$_POST['email']; mysql_connect("your hostname", "your database name", "your password") or die(mysql_error()); mysql_select_db("your database name") or die(mysql_error()); $sql = sprintf("INSERT INTO Users (first_name, last_name, age, city, state, country, zip, birthdate, gender, sexuality, race, religion, status, about, website, user_name, password, email) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($first_name), mysql_real_escape_string($last_name), mysql_real_escape_string($age), mysql_real_escape_string($city), mysql_real_escape_string($state), mysql_real_escape_string($country), mysql_real_escape_string($zip), mysql_real_escape_string($birthdate), mysql_real_escape_string($gender), mysql_real_escape_string($sexuality), mysql_real_escape_string($race), mysql_real_escape_string($religion), mysql_real_escape_string($status), mysql_real_escape_string($about), mysql_real_escape_string($website), mysql_real_escape_string($user_name), mysql_real_escape_string($password), mysql_real_escape_string($email)); $result = mysql_query($sql); Print "Congratulations! You are now a registered member on yourwebsite.com!"; ?> (register/index.php) <script language = "Javascript"> function Validate() { if (document.register.first_name.value == '') { alert('You have not specified your first name!'); return false; } if (document.register.last_name.value == '') { alert('You have not specified your last name!'); return false; } if (document.register.age.value == '') { alert('You have not specified your age!'); return false; } if (document.register.country.value == '') { alert('You have not entered a country!'); return false; } if (document.register.birthdate.value == '') { alert('You have not entered your date of birth!'); return false; } if (document.register.gender.value == '') { alert('You have not specified your gender!'); return false; } if (document.register.user_name.value == '') { alert('You have not entered a username!'); return false; } if (document.register.email.value == '') { alert('You have not entered an email!'); return false; } if (document.register.password.value == '') { alert('You have not entered a password!'); return false; } return true; } </script> <form name="register" method="post" action="http://www.djsmiley.net/register/process.php" onsubmit="return Validate();"> <table width="100%" border="0"> <tr> <td>First Name:</td> <td><label> <input type="text" name="first_name" id="first_name" /> </label></td> </tr> <tr> <td>Last Name:</td> <td><input type="text" name="last_name" id="last_name" /></td> </tr> <tr> <td>Age:</td> <td><input type="text" name="age" id="age" /></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city" id="city" /></td> </tr> <tr> <td>State:</td> <td><input type="text" name="state" id="state" /></td> </tr> <tr> <td>Country:</td> <td><input type="text" name="country" id="country" /></td> </tr> <tr> <td>Zip:</td> <td><input type="text" name="zip" id="zip" /></td> </tr> <tr> <td>Birthdate:</td> <td><input type="text" name="birthdate" id="birthdate" /></td> </tr> <tr> <td>Gender:</td> <td><input type="text" name="gender" id="gender" /></td> </tr> <tr> <td>Sexuality:</td> <td><input type="text" name="sexuality" id="sexuality" /></td> </tr> <tr> <td>Race:</td> <td><input type="text" name="race" id="race" /></td> </tr> <tr> <td>Religion:</td> <td><input type="text" name="religion" id="religion" /></td> </tr> <tr> <td>Marital Status:</td> <td><input type="text" name="status" id="status" /></td> </tr> <tr> <td>About You:</td> <td><label> <textarea name="about" id="about" cols="45" rows="5"></textarea> </label></td> </tr> <tr> <td>Website:</td> <td><input type="text" name="website" id="website" /></td> </tr> <tr> <td width="13%">Username: </td> <td width="87%"><input type="text" name="user_name" id="user_name" /></td> </tr> <tr> <td>Email: </td> <td><input type="text" name="email" id="email" /></td> </tr> <tr> <td>Password: </td> <td><input type="password" name="password" id="password" /></td> </tr> <tr> <td> </td> <td><input name="Register Button" type="submit" class="Button1" id="Register Button" value="Register" /> <input name="Reset Button" type="reset" class="Button1" id="Reset Button" value="Clear" /></td> </tr> </table> <label></label> </form> Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/ Share on other sites More sharing options...
trq Posted February 3, 2011 Share Posted February 3, 2011 Instead of simply assuming the query worked.... $result = mysql_query($sql); Print "Congratulations! You are now a registered member on yourwebsite.com!"; You should check and see.... if (mysql_query($sql)) { if (mysql_affected_rows()) { print "Congratulations! You are now a registered member on yourwebsite.com!"; } else { trigger_error('Query failed <br />' . mysql_error() . '<br />' . $sql); } } Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169177 Share on other sites More sharing options...
jamesjmann Posted February 3, 2011 Author Share Posted February 3, 2011 I added that bit of code and tested it again. It just showed a blank page... Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169181 Share on other sites More sharing options...
cssfreakie Posted February 3, 2011 Share Posted February 3, 2011 sounds like a typo Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169182 Share on other sites More sharing options...
jamesjmann Posted February 3, 2011 Author Share Posted February 3, 2011 hey i just got it to work. i didn't have the primary key in my table set to autoincrement so every time i tried to create a new user it wouldn't let me unless the first user was 1, but it was 0. anyway, i was wondering how i could have "process.php" redirect to the home page, after inserting the new user into the database. for example: user registers with site. hits submit button. new page comes up that displays message "thank you for registering! you are about to be redirected to the home page" page redirects to home page I tried the header (): function in place of where the print (); function is currently at, and instead of it querying the database then redirecting, it just redirects. I also tried putting the header (); function at the very top of "process.php" but that didn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169422 Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 you can't use header() AND output content to the browser. It's one or the other. you should provide a link to "continue" or use javascript or meta tag to redirect after a set amount of time. Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169434 Share on other sites More sharing options...
jamesjmann Posted February 3, 2011 Author Share Posted February 3, 2011 you can't use header() AND output content to the browser. It's one or the other. you should provide a link to "continue" or use javascript or meta tag to redirect after a set amount of time. Ok, I'll just use a link, because I don't know much about javascript and that sounds too complicated. Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169435 Share on other sites More sharing options...
ZulfadlyAshBurn Posted February 3, 2011 Share Posted February 3, 2011 redirect after some time isnt that hard. add this to the "if user added" header('Refresh: 3; url=index.php'); Quote Link to comment https://forums.phpfreaks.com/topic/226523-login-system/#findComment-1169448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.