knifeh Posted February 11, 2010 Share Posted February 11, 2010 Hi guys i'm very new to php and ive been racking my brains for hours. i can't get my registration code, to insert information into my mysql db. can anyone please help? <?php require('function.php'); $sesuser = $_SESSION['username']; $submit = $_POST['submit']; //Form Data $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); //Checking if logged in if($sesuser){ die("You are already logged in! <a href='index.php'>Click here</a> to return to the homepage or <a href='logout.php'>here</a> to logout"); } else { if($submit) { if($username&&$password&&$repeatpassword); { //check if username is already being used $regquery = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($regquery); if($numrows) { echo "User already exists!"; } else { //check if both password match if($password==$repeatpassword) { //register the user $password = md5($password); $date = date("Y-m-d"); $queryreg = mysql_query("INSERT INTO users Values('','$username','$password','$date')"); die("Successfully registered!"); } else { echo "Passwords do not match!"; } } } } else { echo "Please fill in all the fields"; } } ?> <html> <link href="style/main.css" rel="stylesheet" type="text/css" /> <body> <form action="register.php" method='POST'> <table> <tr> <td> Username: </td> <td> <input type="text" name="username" value="<?php echo $username; ?>" /> </td> </tr> <tr> <td> Password: </td> <td> <input type="password" name="password" /> </td> </tr> <tr> <td> Repeat Password: </td> <td> <input type="password" name="repeatpassword" /> </td> </tr> <tr> <td> <input type="submit" name="submit" value="submit" /> </td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/ Share on other sites More sharing options...
jl5501 Posted February 11, 2010 Share Posted February 11, 2010 Are you getting any errors? does code in your function.php file make the connection to the db? Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/#findComment-1010907 Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2010 Share Posted February 11, 2010 And does it contain a session_start() statement? And are you learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php would help you by displaying all the errors it detects? Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/#findComment-1010915 Share on other sites More sharing options...
knifeh Posted February 11, 2010 Author Share Posted February 11, 2010 Hi guys thanks for the quick relpys. Are you getting any errors? does code in your function.php file make the connection to the db? No im not getting any errors on the screen. maybe that would help and as far as im aware the function.php does connect me to the db heres the code for that <?php session_start(); mysql_connect("localhost","root",""); mysql_select_db("main_website"); function loggedin(){ if(isset($_SESSION['username'])||isset($_COOKIE['username'])){ $loggedin = TRUE; return $loggedin; } } ?> PFMaBiSmAd - No there isnt that satement. i will add one tho to see if that helps. and how would i turn the error messages on? as this would help alot to. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/#findComment-1010930 Share on other sites More sharing options...
knifeh Posted February 11, 2010 Author Share Posted February 11, 2010 i've done what you to have said and it still doesnt want to work.... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/#findComment-1010957 Share on other sites More sharing options...
PFMaBiSmAd Posted February 12, 2010 Share Posted February 12, 2010 it still doesn't want to work Yes, but what exactly is it doing? We are not standing right next to you. We only see the information that you post. Are you getting a blank page? One of your error messages from the code? The form just redisplays? A php detected error? Just stating something does not work is useless information, we already know that because you would not be making a post on a help forum if your code was working as expected. The only one here that can actually troubleshoot what your code is doing on your server with your database is YOU. You must show some investigative curiosity and find out what your code is doing. What execution path it is taking, what data values it is testing or using? Quote Link to comment https://forums.phpfreaks.com/topic/191804-help/#findComment-1011361 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.