Jump to content

Archived

This topic is now archived and is closed to further replies.

onthespot

please help

Recommended Posts

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 5



CAN U HELP PLEASE, IM NOT GREAT WITH PHP AND DONT UNDERSTAND THE PROBLEM!
THANKYOU!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
No worries, we all learn somehow...
The password field : password for database
the username filed: username for database
the 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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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@email.com.\)' at line 1

any ideas?

Share this post


Link to post
Share on other sites
try this

[code=php:0]$sql = "INSERT INTO login_tbl (loginid, password and email) VALUES ('$loginid', '$password', '$email')";[/code]

Good luck,
Tom

Share this post


Link to post
Share on other sites
i did that mate and it changed to this

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@email.com')' at line 1

the 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?

Share this post


Link to post
Share on other sites
$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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
CAN ANYBODY HELP?? I NEED A LINE TO ADD IN SO WHEN PEOPLE HAVE SIGNED UP IT SAYS THAT THEY ARE SUCCESSFULLY REGISTERED!

Share this post


Link to post
Share on other sites
relax,  I am writing you a better register script

Share this post


Link to post
Share on other sites
thankyou mate, ive now got it registering users on the database! just nothing on the screen to say it!

Share this post


Link to post
Share on other sites
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]<?php
include('db.php');//your database connection file
array_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 entered
if ((!$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

Share this post


Link to post
Share on other sites
Parse error: parse error, unexpected $ in register.php on line 73

i used the script u wrote me, and i got that error?

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.