Jump to content

please help


onthespot

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!
Link to comment
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
Link to comment
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 :)
Link to comment
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
Link to comment
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
Link to comment
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?
Link to comment
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?
Link to comment
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?
Link to comment
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
Link to comment
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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.