lalonde4 Posted May 29, 2012 Share Posted May 29, 2012 Ok so I cant get the register page to insert the information into my database the config file is linked it works but just inserting the info just doesnt work. <?php $title = "Productions - Register";?> <?php require("styles/top.php"); ?> <div id='full'> <?php $form = "<form action='register.php' method='post'> <table> <tr> <td>First Name:</td> <td><input type='text' name='firstname'><font color='red'>*</font></td> </tr> <tr> <td>Last Name:</td> <td><input type='text' name='lastname'><font color='red'>*</font></td> </tr> <tr> <td>Username:</td> <td><input type='text' name='username'><font color='red'>*</font></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='email'><font color='red'>*</font></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'><font color='red'>*</font></td> </tr> <tr> <td>Confirm Password:</td> <td><input type='password' name='repassword'><font color='red'>*</font></td> </tr> <tr> <td>Avatar:</td> <td><input type='file' name='avatar'></td> </tr> <tr> <td>Bio/About Me:</td> <td><textarea name='bio' cols='35' rows='5'></textarea></td> </tr> <tr> <td>Website:</td> <td><input type='text' name='website'></td> </tr> <tr> <td>Youtube:</td> <td><input type='text' name='youtube'></td> </tr> <tr> <td>Facebook:</td> <td><input type='text' name='facebook'></td> </tr> <tr> <td>Twitter:</td> <td><input type='text' name='twitter'></td> </tr> <tr> <td></td> <td><input type='submit' name='submitbtn' value='Register'></td> </tr> <tr> <td></td> <td><font color='red'>*</font> = Required</td> </tr> </table> </form>"; if ($_POST['submitbtn']){ $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strip_tags($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repassword = strip_tags($_POST['repassword']); $bio = strip_tags($_POST['bio']); $website = strip_tags($_POST['webite']); $youtube = strip_tags($_POST['youtube']); $facebook = strip_tags($_POST['facebook']); $twitter = strip_tags($_POST['twitter']); $name = $_FILES['avatar']['name']; $type = $_FILES['avatar']['type']; $size = $_FILES['avatar']['size']; $tmpname = $_FILES['avatar']['tmp_name']; $ext = substr($name, strrpos($name, '.')); if ($firstname && $lastname && $username && $email && $password){ if ($password == $repassword){ if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >=6)){ require("scripts/config.php"); $query = mysql_query("SELECT * FROM user WHERE username='$username'");$numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM users WHERE email='$email'");$numrows = mysql_num_rows($query); if ($numrows == 0){ $pass = md5($password); $date = date("F d, Y"); if ($name){ move_uploaded_file($tmpname, "avatars/$username.$ext"); } else $avatar = "defav.png"; $code = substr(md5(rand(111111111111, 999999999999)), 2,25); mysql_query("INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')"); $webmaster = "[email protected]"; $subject = "Activation Email"; $headers = "From: AAG GoD<$webmaster>"; $message = "Hello $username! Thank you for registering! Below is your activation link.\n\n You must click this link in order to log in. http://www.aagaming.net/productions/activate.php?code=$code"; mail($email, $subject, $message, $headers); echo "Your activation email has been sent to <b>$email</b>. There you will follow a link in order to login. You must complete the activation proccess in order to login. If you run into any problems please email the site administrators. Send an email to <a href='mailto:[email protected]'>[email protected]</a>"; } else echo"That email is already in use. $form"; } else echo"That username is already in use. $form"; } else echo "You did not enter a valid email. $form"; } else echo "Your passwords did not match. $form"; } else echo "You did not fill out all the required fields. $form"; } else echo "$form"; ?> </div> <?php require("styles/bottom.php"); ?> Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/ Share on other sites More sharing options...
smoseley Posted May 29, 2012 Share Posted May 29, 2012 mysql_query("INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349385 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 See like i have tried all the ways you can but i cant seem to get them to insert. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349399 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 i do have an activate page to activate it and when i do that it gets a 404 error and then i look into my tables and its like nothing is connecting. I cant figure out the problem no syntax errors or database errors come up. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349400 Share on other sites More sharing options...
Psycho Posted May 29, 2012 Share Posted May 29, 2012 And what error is displayed when you add the error handling that smoseley suggested? Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349401 Share on other sites More sharing options...
smoseley Posted May 29, 2012 Share Posted May 29, 2012 What do you see when you post the form? Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349402 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 here go to the site and register then activate your account and you will see it. http://www.aagaming.net/productions/register.php Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349404 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 Otherwise this is the error I get. http://www.aagaming.net/productions/activate.php%20method=?code=0c54f098e4aa85a51cd64c778&username=aag+god&password=morgan2011&submitbtn=activate Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349405 Share on other sites More sharing options...
smoseley Posted May 29, 2012 Share Posted May 29, 2012 Did you add the "or die" code I posted above? Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349406 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 yeah didnt really do anything. still wont insert into my database does anyone have teamviewer? Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349407 Share on other sites More sharing options...
Pikachu2000 Posted May 29, 2012 Share Posted May 29, 2012 If you want help, copy and paste the error here. It's unreasonable to expect people to go spend their time to create an account on your site in order to provide you with free help. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349408 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 But thats the thing there is no error displayed I can show you if you have team viewer or something. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349410 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 It will send an email for your activation but wont insert that info that is being submitted to the users table. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349411 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 New code but still wont post into database <?php $title = "Productions - Register";?> <?php require("styles/top.php"); ?> <div id='full'> <?php $form = "<form action='register.php' method='post'> <table> <tr> <td>First Name:</td> <td><input type='text' name='firstname'><font color='red'>*</font></td> </tr> <tr> <td>Last Name:</td> <td><input type='text' name='lastname'><font color='red'>*</font></td> </tr> <tr> <td>Username:</td> <td><input type='text' name='username'><font color='red'>*</font></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='email'><font color='red'>*</font></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'><font color='red'>*</font></td> </tr> <tr> <td>Confirm Password:</td> <td><input type='password' name='repassword'><font color='red'>*</font></td> </tr> <tr> <td>Avatar:</td> <td><input type='file' name='avatar'></td> </tr> <tr> <td>Bio/About Me:</td> <td><textarea name='bio' cols='35' rows='5'></textarea></td> </tr> <tr> <td>Website:</td> <td><input type='text' name='website'></td> </tr> <tr> <td>Youtube:</td> <td><input type='text' name='youtube'></td> </tr> <tr> <td>Facebook:</td> <td><input type='text' name='facebook'></td> </tr> <tr> <td>Twitter:</td> <td><input type='text' name='twitter'></td> </tr> <tr> <td></td> <td><input type='submit' name='submitbtn' value='Register'></td> </tr> <tr> <td></td> <td><font color='red'>*</font> = Required</td> </tr> </table> </form>"; if ($_POST['submitbtn']){ $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strip_tags($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repassword = strip_tags($_POST['repassword']); $bio = strip_tags($_POST['bio']); $website = strip_tags($_POST['webite']); $youtube = strip_tags($_POST['youtube']); $facebook = strip_tags($_POST['facebook']); $twitter = strip_tags($_POST['twitter']); $name = $_FILES['avatar']['name']; $type = $_FILES['avatar']['type']; $size = $_FILES['avatar']['size']; $tmpname = $_FILES['avatar']['tmp_name']; $ext = substr($name, strrpos($name, '.')); if ($firstname && $lastname && $username && $email && $password){ if ($password == $repassword){ if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >=6)){ require("scripts/config.php"); $query = mysql_query("SELECT * FROM user WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM users WHERE email='$email'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $pass = md5($password); $date = date("F d, Y"); if ($name){ move_uploaded_file($tmpname, "avatars/$username.$ext"); } else $avatar = "defav.png"; $code = substr(md5(rand(111111111111, 999999999999)), 2,25); mysql_query("INSERT INTO users VALUES('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')") or die(mysql_error()); $webmaster = "[email protected]"; $subject = "Activation Email"; $headers = "From: AAG GoD<$webmaster>"; $message = "Hello $username! Thank you for registering! Below is your activation link.\n\n You must click this link in order to log in. http://www.aagaming.net/productions/activate.php?code=$code"; mail($email, $subject, $message, $headers); echo "Your activation email has been sent to <b>$email</b>. There you will follow a link in order to login. You must complete the activation proccess in order to login. If you run into any problems please email the site administrators. Send an email to <a href='mailto:[email protected]'>[email protected]</a>"; } else echo"That email is already in use. $form"; } else echo"That username is already in use. $form"; } else echo "You did not enter a valid email. $form"; } else echo "Your passwords did not match. $form"; } else echo "You did not fill out all the required fields. $form"; } else echo "$form"; ?> </div> <?php require("styles/bottom.php"); ?> Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349414 Share on other sites More sharing options...
Pikachu2000 Posted May 29, 2012 Share Posted May 29, 2012 I don't see where you connect to or select the database with mysql_connect() and mysql_select_db() in that code. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349415 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 I have require in there and this is the error i get. mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/aagaming/public_html/productions/register.php on line 94 Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349416 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 require("scripts/config.php"); is where is my connect file. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349417 Share on other sites More sharing options...
Psycho Posted May 29, 2012 Share Posted May 29, 2012 Your queries are failing. You need to check that the queries succeed - if not, check what the error is. On all your queries you should define the query as a string variable and then run that in mysql_query. That way, if the query fails, you can eche the que5ry and the error to the page. $query = "SELECT * FROM user WHERE username='$username'"; $result = mysql_query($query) or die("Query: $query<br>Error: " . mysql_error()); Do that on all the queries you run. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349418 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 ok i will try that. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349419 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 Nope that didnt work its still failing. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349420 Share on other sites More sharing options...
Psycho Posted May 29, 2012 Share Posted May 29, 2012 Nope that didnt work its still failing. Of course it is still failing! That code will not fix the error, but it will show you what the error IS. We can't help you because we don't know what the problem is. If you cannot implement simple debugging steps and ascertain the results for us to review then there isn't much we can do to help you. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349421 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 I mean like that doesnt display any errors either thats my problem I am doing simple debugging strategies but its showing nothing. Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349422 Share on other sites More sharing options...
smoseley Posted May 29, 2012 Share Posted May 29, 2012 try this: $sql = "INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')"; echo $sql; mysql_query($sql) or die(mysql_error()); Then take the query that prints to your screen and try running it in phpmyadmin directly to see the error you get there. My guess is your columns don't match up. You should never do an insert without specifying the columns.... if you ever add columns to your table, you'll break the query. It should be like this: INSERT INTO table_name (col1, col2) VALUES ('data1', 'data2'); Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349466 Share on other sites More sharing options...
Psycho Posted May 29, 2012 Share Posted May 29, 2012 I mean like that doesnt display any errors either thats my problem I am doing simple debugging strategies but its showing nothing. Then start at the beginning. Have you even verified that the page you *think* is running is the one that is actually running? At teh very start of the page do something like this echo "Start debugging<br>"; Then at the very first control you could do something like this if ($_POST['submitbtn']){ echo "POST[submitbtn] = TRUE<br>"; Also, add a debug statement for the false condition. By the way, you should rethink how you set up your IF/THEN logic. When you do something such as this if(NOT ERROR CONDITION 1) { if(NOT ERROR CONDITION 2) { //perform success condition } else { //perform error condition 2 } } else { //perform error condition 1 } It makes it very difficult to manage the conditions with their errors. It is much better to follow a pattern such as this if(ERROR CONDITION 1) { //perform error condition 1 } else if(ERROR CONDITION 2) { //perform error condition 2 } else { //perform success scenario } Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349510 Share on other sites More sharing options...
lalonde4 Posted May 29, 2012 Author Share Posted May 29, 2012 try this: $sql = "INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')"; echo $sql; mysql_query($sql) or die(mysql_error()); Then take the query that prints to your screen and try running it in phpmyadmin directly to see the error you get there. My guess is your columns don't match up. You should never do an insert without specifying the columns.... if you ever add columns to your table, you'll break the query. It should be like this: INSERT INTO table_name (col1, col2) VALUES ('data1', 'data2'); This is the error i get with this try INSERT INTO users VALUES ('', 'Matt', 'Lalonde', '[email protected]', 'b8955b3dda83d2aa5c07c00e86229f85', 'defav.png', '', '', '', '', '', '', '0', 'c6f1a668129cbeb2a52f2edfc', '0', 'May 29, 2012')Column count doesn't match value count at row 1 Link to comment https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/#findComment-1349574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.