onthespot Posted July 24, 2006 Share Posted July 24, 2006 hello there, im creating a login for my website, the html for the login page is below<form name="register" method="post" action="register.php"> <input name="login id" type="text" value="loginid" size="20"/><br> <input name="password" type="text" value="password" size="20"/><br> <input name="email" type="text" value="email" size="50"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/>this is the register.php file:<?php@mysql_connect("localhost", "usuallymyrealuser", "usuallymypassword") or die("Cannot connect to DB!");@mysql_select_db("tbl_login") or die("Cannot select DB!");$sql="INSERT INTO login_tbl (loginid, password and email) VALUES (".$loginid.”,”.$password.”,”.$email.”)”;$r = mysql_query($sql);if(!$r) { $err=mysql_error(); print $err; exit();}?>AFTER DOING THIS, AND SUBMITTING THE INFORMATION ON THE HTML PAGE, I GET THE FOLLOWING ERROR:Parse error: parse error, unexpected ',' in myaddress/register.php on line 5CAN U HELP PLEASE, IM NOT GREAT WITH PHP AND DONT UNDERSTAND THE PROBLEM!THANKYOU! Link to comment https://forums.phpfreaks.com/topic/15442-please-help/ Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 Check your quoting. Make sure that if you use " with in " quotes that you Excape them like this:[code]$sql="INSERT INTO login_tbl (loginid, password and email) VALUES (\".$loginid.\",\".$password.\",\".$email.\")";[/code]Try replacing line 5 with that Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62616 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 well thankyou very much, that has obviously fixed it, my only other problem is, it now says cannot connect to DATABSE lol, any ideas? wot do i put the three parts, "localhost" "username" "password"??in the username, the username for the database??password, password for database?wot about localhost? cheers m8 Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62617 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 No worries, we all learn somehow...The password field : password for databasethe username filed: username for databasethe other field(not called Localhost field): that is the location of the database, "localhost" refers to the computer the webserver is running on. so if the database is on the same box as the webserver use "localhost" if not then the IP address of the computer running the SQL server.also in the above line. you may want to remove all those "."'s because i presume where ever you got that code from they were trying to concatinate the strins, and it will insert LITERLAY ".VARIABLEVALUE." (With out quotes)"Anything else u need help with, just drop a line :) Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62621 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 i still havent got it mate, ive entered the databse which is ots_users and the password which is the password lol, so that is, "ots_users" "password" for them two. i think it is the other one i am having problems with, my sql database is online on my webspace so what do i put for that? thanx Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62625 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 If the SQL server is running on the same copmuter as the webserver, you can enter localhost(try that). but if it is running on a seperate computer then enter the IP address of that computer.Is this a server you have setup or something you have hired? (eg with a Hosting company)Cheers,Nathan Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62627 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 its with a hosting company, ive now got past that point, but now cant select DB lol, any ideas mate, really sorry to keep asking, i am tryin trial and error though! Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62629 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 What is the error your getting?Cheers,nathan Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62630 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 Cannot select DB!cheers Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62631 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 Make sure that database is in the Server, have you connected to it before?spaces rewin things,Cheers,Nathan Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62632 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 ok my database is ots_users, and the table i have created with loginid password and email is called tbl_login. is this all correct? and how do i test it to see if its working ok? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62633 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Share Posted July 24, 2006 in the line where you say "@mysql_select_db("tbl_login") or die("Cannot select DB!");" put "ots_users" instead of "tbl_login".tbl_login is a table within the database ots_users. Try that :)Cheers,[code]@mysql_select_db("ots_users") or die("Cannot select DB!");[/code] Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62635 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 after doing that, i now get the following error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and email) VALUES (\..\,\.psw.\,\[email protected].\)' at line 1any ideas? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62772 Share on other sites More sharing options...
tomfmason Posted July 24, 2006 Share Posted July 24, 2006 try this[code=php:0]$sql = "INSERT INTO login_tbl (loginid, password and email) VALUES ('$loginid', '$password', '$email')";[/code]Good luck,Tom Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62775 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 i did that mate and it changed to thisYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and email) VALUES ('', 'psw', '[email protected]')' at line 1the login_tbl in the line you specified, is the table with the ots_users database right? if so the actual table is called tbl_login?? does this make a difference? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62776 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 $sql = "INSERT INTO login_tbl (loginid, password [b]and email[/b]) VALUES ('$loginid', '$password', '$email')";that line there, i have changed the bold to$sql = "INSERT INTO login_tbl (loginid, password, email) VALUES ('$loginid', '$password', '$email')";and the insert into login_tbl to tbl_login because that is the table, i click and ive got a blank screen, maybe a sign that its working? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62777 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 where do i add a line to say u have successfully registered?? do i add this to the html or the php? and what line do i add? can u please help? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62781 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 CAN ANYBODY HELP?? I NEED A LINE TO ADD IN SO WHEN PEOPLE HAVE SIGNED UP IT SAYS THAT THEY ARE SUCCESSFULLY REGISTERED! Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62799 Share on other sites More sharing options...
tomfmason Posted July 24, 2006 Share Posted July 24, 2006 relax, I am writing you a better register script Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62804 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 thankyou mate, ive now got it registering users on the database! just nothing on the screen to say it! Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62810 Share on other sites More sharing options...
tomfmason Posted July 24, 2006 Share Posted July 24, 2006 well that can fixed by doing this[code=php:0]$sql = "INSERT INTO login_tbl (loginid, password, email) VALUES ('$loginid', '$password', '$email')";if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; }else{ echo " Your account has now been created. You may login with the following information:<br> <b>Login Id :</b> $loginid <br> <b>Password</b> $password <br>"; } ?>[/code]or you can use this scipt that I just wrote for you[code=php:0]<?phpinclude('db.php');//your database connection filearray_pop($_POST);if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST);}$loginid = mysql_real_escape_string(trim($_POST['loginid']));$email = mysql_real_escape_string(trim($_POST['email']));$password = mysql_real_escape_string(trim($_POST['password']));//lets check to see if all of the information was enteredif ((!$loginid) || (!$email) || (!$password)) { echo "You did not submit the following information<br>"; if (!$loginid) { echo "<b><i>Login Id is a required field!</i></b><br>"; } if (!$email) { echo "<b><i>Email is a required field</i></b><br>"; } if (!password) { echo "<b><i>Password is a required field</i></b><br>"; } include('register.html'); exit();}//check to see if the login id or email is already being used$loginid_sql = sprintf("SELECT COUNT(*) AS loginid_match FROM `login_tbl ` WHERE `loginid` = '%s'", $login_id);$email_sql = sprintf("SELECT COUNT(*) AS email_match FROM `login_tbl ` WHERE `email` = '%s'", $email);$loginid_result= mysql_query($loginid_sql) or die(mysql_error());$email_result= mysql_query($email_sql) or die(mysql_error());$loginid_match= mysql_result($loginid_result, 0, 'loginid_match');$email_match= mysql_result($email_result, 0, 'email_match');if ( $loginid_match > 0 ) { //if there are any login ids that match echo "This login id is already taken. Please try again"; include('register.html');//your register form unset($loginid); exit();}if ( $email_match > 0 ) { //if there are any email addresses that match echo "This email has already been used"; include('register.html');//your register form unset($email); exit();}$mdpwd = md5($password);$sql = mysql_query("INSERT INTO login_tbl (loginid, password, email) VALUES ('$loginid', '$mdpwd', '$email')");if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; }else{ echo " Your account has now been created. You may login with the following information:<br> <b>Login Id :</b> $loginid <br> <b>Password</b> $password <br>"; } ?>[/code]Good luck,Tom Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62819 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 omg mate, u r a legend! thankyou very much i will try both! Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62825 Share on other sites More sharing options...
onthespot Posted July 24, 2006 Author Share Posted July 24, 2006 Parse error: parse error, unexpected $ in register.php on line 73i used the script u wrote me, and i got that error? Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-62879 Share on other sites More sharing options...
simcoweb Posted July 24, 2006 Share Posted July 24, 2006 Check this. I just copied and pasted the script into both a text editor and into a coding program. When copying and pasting it the last few lines are broken. Like this:[code]<b>Login Id :</b> $loginid <br> d</b> $password <br>"; <b>Passwor[/code]When it should look like this:[code] echo " Your account has now been created. You may login with the following information:<br>"; echo "<b>Login Id :</b> $loginid <br>"; echo "<b>Password</b> $password <br>";[/code][color=red]tomfmason[/color], I don't mean to change your code. I'm just a noob. But what I'm pointing out is that the last echo statement you wrote that displays the username/password for some reason wouldn't copy and paste properly and was producing broken syntax errors 'as is' because of that. So, I changed it to 3 separate echo statements just to make sure it worked. I'm thinking that perhaps that's what happened to onthespot in his attempt to copy/paste and execute the code. Just a guess :) Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-63042 Share on other sites More sharing options...
onthespot Posted July 25, 2006 Author Share Posted July 25, 2006 cheers mate, ill try this now Link to comment https://forums.phpfreaks.com/topic/15442-please-help/#findComment-63349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.