CyDrive Posted August 5, 2006 Share Posted August 5, 2006 Ok im making a user managment system. Now this is only a test one to see if i can make it work before i make one for my real website. Though i keep getting an error on line 18 in my register2.php file. Here is the code.[code]<?php$username = $_POST['username'];$password = $_POST['password'];$email = $_POST['email'];$picture = $_POST["picture"];$ip = $REMOTE_ADDR;$username = strip_tags($username);$email = strip_tags($email);$picture = strip_tags($picture);$password = md5($password);if ( !$username || !$password || !$email || !$picture) { die( "All fields are required!" );}$connect = mysql_connect( "x", "x", "x" );if ( ! $connect ) { die( "Could not connect to SQL server" );}$insertstatement = "INSERT INTO Users VALUES ('$username', '$password', '$email')";mysql_select_db( "cydrive_test", $connect )or die ("Could not open database:" .mysql_error() );$selectresult = mysql_query( "SELECT * FROM Users WHERE username=’$username’", $connect );$numrows = mysql_num_rows( $result );if ( $numrows > 0 ) {print "The username you have chosen is in use. Please choose another one.";} else {mysql_query($insertstatment, $connect )or die( "Couldn't add data to table" );print "Registration successful! Login <a href="login.php">here</a>";}?>[/code]Heres the code for register.php is it helps any.[code]<HTML><TITLE>Index Page</title><BODY bgcolor="#ffffff"><html><body bgcolor = "black"><?session_start();if($_SESSION["username"] = null) {?><form action="register2.php" method="post">Username: <input type="text" name="username" size="15"><br>Password: <input type="password" name="password" size="32"><br>Email: <input type="text" name="email" size="50";><br>Picture: <input type="text" name="pictures" size="1000";><br><center><input type="submit"><input type="reset"></center></form><?}else{print"You are already logged in";?></body></html></BODY></HTML>[/code]Heres a link to register.php[url=http://h1.ripway.com/cydrive/]http://h1.ripway.com/cydrive/[/url][b]edit(shoz): removed login details[/b] Quote Link to comment https://forums.phpfreaks.com/topic/16616-need-help/ Share on other sites More sharing options...
paul2463 Posted August 5, 2006 Share Posted August 5, 2006 Not being that experienced in mySql, I have had a quick look for you and I think I may have spotted your problemlines 14 - 17 connect to your database serveryour line 18 is trying to insert into the database, but you are not yet connected to the database untill line 19try this[code]<?php$username = $_POST['username'];$password = $_POST['password'];$email = $_POST['email'];$picture = $_POST["picture"];$ip = $REMOTE_ADDR;$username = strip_tags($username);$email = strip_tags($email);$picture = strip_tags($picture);$password = md5($password);if ( !$username || !$password || !$email || !$picture) { die( "All fields are required!" );}$connect = mysql_connect( "x", "x", "x" );if ( ! $connect ) { die( "Could not connect to SQL server" );}mysql_select_db( "cydrive_test", $connect ) or die ("Could not open database:" .mysql_error() );$insertstatement = "INSERT INTO Users VALUES ('$username', '$password', '$email')";$selectresult = mysql_query( "SELECT * FROM Users WHERE username=’$username’", $connect );$numrows = mysql_num_rows( $result );if ( $numrows > 0 ) {print "The username you have chosen is in use. Please choose another one.";} else {mysql_query($insertstatment, $connect )or die( "Couldn't add data to table" );print "Registration successful! Login <a href="login.php">here</a>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16616-need-help/#findComment-69715 Share on other sites More sharing options...
CyDrive Posted August 5, 2006 Author Share Posted August 5, 2006 Thanks alot it worked. Quote Link to comment https://forums.phpfreaks.com/topic/16616-need-help/#findComment-69737 Share on other sites More sharing options...
fenway Posted August 5, 2006 Share Posted August 5, 2006 Incidentally, you can put the DB name into your connection line as well, AFAIK. Quote Link to comment https://forums.phpfreaks.com/topic/16616-need-help/#findComment-69823 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.