HardCoreMore Posted February 25, 2008 Share Posted February 25, 2008 Hi all, this is my first post to phpfreaks.com. I am new to php programming so i am watching some video tutorial but its some old one and guy use like php 3 version and i am using php 5,2,5 vers and mysql 4.1.22. So i am trying to make user registraion page and i just can't make it. With the exact code from the video tutorial php gives me error and i don't know what to do so if somebody know it its must be people here on phpfreaks. This is how my registration html form looks like: <html> <body> <title>Register</title> </head> <body> <h1>Register</h1> <form method="post" action="register.php"> Please enter a username: <input name="user" type="text" maxlength="20" size="20" /> <br /> <br /> Please enter a password: <input name="pass" type="password" maxlength="10" size="10" /> <br /> <br /> <input type="submit" value="Register" /> </form> </body> </html> And this is php code: <?php session_start(); ?> <?php $user = $_POST["user"]; $pass = $_POST["pass"]; if ($user && $pass) { $db = mysql_connect("localhost","root","chaky"); mysql_select_db("userlist",$db); $select = mysql_query("SELECT * FROM users where name = $user"); if ($select = !$user) { mysql_query ("insert into users set user = '$user', pass = 'password($pass)'"); if ($select) { $logged_in_user = $user; session_register("logged_in_user"); echo "You details have been added to the database, $user<br /><br />"; echo "<a href='main.php'>Click here to go to proceed to the main page.</a><br /><br />"; echo "<a href = 'logout.php'>Click here to logout.</a><br />"; echo $select; exit; }else{ echo "Sorry, there has been a technical hitch. We cannot enter your details"; exit; } } } ?> So please help what should i do what should i change to get this work. Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/ Share on other sites More sharing options...
Lamez Posted February 25, 2008 Share Posted February 25, 2008 are you getting any errors? Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476328 Share on other sites More sharing options...
HardCoreMore Posted February 25, 2008 Author Share Posted February 25, 2008 I do not get any errors but he don't want to write it to mysql. When i fill some data and click register he echo You details have been added to the database, $user but he don't write it to database. Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476332 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 You aren't even checking for errors in the query or the connection, so how would you see them? Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476335 Share on other sites More sharing options...
HardCoreMore Posted February 25, 2008 Author Share Posted February 25, 2008 How can i check for errors in mysql_query? I am sorry if i bug you too much but i am all new to this and your help would be appriciated. Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476341 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 mysql_query ("insert into users set user = '$user', pass = 'password($pass)'")or die (.mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476345 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 There is a problem here $select = mysql_query("SELECT * FROM users where name = $user"); if ($select = !$user) { $select will not = $user here, it will be a Resource ID. You need to use a mysql_fetch command to grab the row of info from your SELECT statement. You also want to put single quotes around $user in your SELECT statement. Once you get this working, you need to learn about SQL injections as well. Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476346 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 $select.= mysql_real_escape_string($select); Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476350 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 the entire script is pretty much flawed i tried to re~write it a little bit I don't know how well it'll work: <?php session_start(); $user = $_POST["user"]; $pass = $_POST["pass"]; if ($user && $pass) { $db = mysql_connect("localhost","root","chaky"); mysql_select_db("userlist",$db); $select = mysql_query("SELECT * FROM users where name = $user"); if (!mysql_num_rows($select)) { $adduser = mysql_query ("insert into users set user = '$user', pass = 'password($pass)'"); if ($adduser) { $logged_in_user = $user; session_register("logged_in_user"); echo "You details have been added to the database, ".$user."\n\n\n"; echo "<a href='main.php'>Click here to go to proceed to the main page.</a>\n\n\n"; echo "<a href = 'logout.php'>Click here to logout.</a>"; echo $select; exit; }else{ echo "Sorry, there has been a technical hitch. We cannot enter your details"; exit; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476354 Share on other sites More sharing options...
HardCoreMore Posted February 25, 2008 Author Share Posted February 25, 2008 Thank you for your answers. I used code that darkangel write and i get error Warning:mysql_num_rows():supplied argument is not valid Mtsql result resource in C:\webroot\......... on line 10 Sorry, there has been a technical hitch. we cannot enter your details. But when i put single quotes around $user in $select = mysql_query line he don't give me mysql_num_rows error but just echo Sorry there has been a technical hitch...... and still don't write it to database. When i change this line => $select = mysql_query("SELECT * FROM users where name = $user"); to this like darkfraks told me => mysql_query ("insert into users set user = '$user', pass = 'password($pass)'")or die (.mysql_error()); i get error Parse error:syntax error, unespected '.' When i remove dot before mysql_error()); It again just echo Sorry, there has been a technical hitch... Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476370 Share on other sites More sharing options...
HardCoreMore Posted February 25, 2008 Author Share Posted February 25, 2008 How can i use a mysql_fetch command to grab the row of info from my SELECT statement revraz. Quote Link to comment https://forums.phpfreaks.com/topic/92970-user-registration-problem/#findComment-476373 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.