PDA

View Full Version : mysql error


Tjobbe
November 30th, 2004, 15:19
related to my other post, but i dont want to confuse as it is a seperate problem.

I have made a login script, and below is the code for register.php.

I am getting the following when I open it into my browser. i have no idea why!



Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in C:\xampp\htdocs\php\login\register.php on line 24


code for the page:


<? session_start() ?>
<HTML>
<HEAD>
<TITLE>Register</TITLE>
</HEAD>

<BODY>
<H2>Register</H2>
<?
// check to see if these two variables have been passed from
// the HTML form at the foot of this script (which calls this page again)
if ($user && $pass) {

// connect to database and select the 'userlist' database
$db = mysql_connect("localhost");
mysql_select_db("userlist", $db);

// check to see if username is already on the database
$result = mysql_query ("SELECT * FROM users WHERE name = '".$user."'");
if (mysql_num_rows($result) == 0) {

// if it's not, add the new details to the database
$result = mysql_query ("INSERT INTO users (name, password, firstname, lastname, email, tel, address1, address2, pcode, county) VALUES
('".$user."', PASSWORD('".$pass."'),'".$1name."','".$2name."','".$emailaddy."','".$phonenum."','".$add1."','".$add2."','".$pcode1."','".$county1."')");
if ($result) {

// if successful, log in the user and show a welcome message
// then exit the script
$logged_in_user = $user;
session_register("logged_in_user");
echo "Your details have been added to the database, ".$user."<BR><BR>";
echo "<A HREF='main.php'>Click here to proceed to the main page.</A><BR><BR>";
echo "<A HREF='logout.php'>Click here to log out.</A>";
exit;
} else {

// if the details could not be added for some reason,
// show an error message
echo "Sorry, there has been a technical hitch. We cannot enter your details.";
exit;
}
} else {

// if the details were already on the database, let the user try again
echo "Sorry, that username has been taken. Please try another.<BR>";
}
} else if ($user || $pass) {

// if the user has filled in one field but not the other,
// throw up this error
echo "Please fill in both fields.";
}
// show HTML form as follows
?>
<FORM METHOD=POST ACTION="register.php">
<p>Please enter a username:
<INPUT NAME="user" TYPE=TEXT MAXLENGTH=20 SIZE=20>
<BR>
Please enter a password:
<INPUT NAME="pass" TYPE=PASSWORD MAXLENGTH=10 SIZE=10>
</p>
<p>
First Name:
<input name="1name" type="text" id="1name" size="20">
<br>
Last Name:
<input name="2name" type="text" id="2name" size="20">
<br>
Email address:
<input name="emailaddy" type="text" id="emailaddy" size="20">
<br>
Telephone number (including STD):
<input name="phonenum" type="text" id="phonenum2" size="20">
<br>
Address 1:
<input name="add1" type="text" id="add1" size="20">
<br>
Address 2:
<input name="add2" type="text" id="add2" size="20">
<br>
Postcode
<input name="pcode1" type="text" id="pcode1" size="20">
<br>
County:
<input name="county1" type="text" id="county1" size="20">
<BR>
<INPUT TYPE=SUBMIT VALUE="Register">
</p>
</FORM>
</BODY>
</HTML>




can somebody have a look and see why? ive tried a few things but not sure what i ahve to do to fix it. i cant see any obvious errors. thanks!

sonicgroup
November 30th, 2004, 15:45
Variable names cannot start with a number - only an underscore ( _ ) or a letter. In your SQL query on lines 23-24 you have $1name and $2name. I'd change your form fields to be name1 and name2 so your variables are $name1 and $name2.

Also, on a separate but related note: Good coding practice. 1) Never use short open tags (<?), always use long open tags (<?php). Reason being: you are not always guaranteed that short open tags will be enabled, so your code is more portable this way. 2) Register Globals - this setting is off by default for security reasons. Unless you've not posted some of this page, you are coding under the assumption that they are on (noted by your use of $formFieldName without an obvious way of getting this variable and defining it). You should code assuming that register globals is off. In that case, all your variables form the form would be of the form $_POST['fieldName']. It works the same way for the query string ($_GET['variable']).

Tjobbe
November 30th, 2004, 16:43
Warning: mysql_connect(): Unknown MySQL Server Host ''localhost', 'bagnboxm_login', 'login'' (0) in /home/bagnboxm/public_html/login/register.php on line 15

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/bagnboxm/public_html/login/register.php on line 16

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/bagnboxm/public_html/login/register.php on line 20
Sorry, there has been a technical hitch. We cannot enter your details.

I have just uploaded this to my site now, and have created the neccesary table in phpmyadmin for it to work, I assigned new user (bagboxm_login and password of login). I uploaded the sql file and evrything but I just dont think I have coded the login part correctly:

$db = mysql_connect("'localhost', 'bagnboxm_login', 'login'");
mysql_select_db("bagnboxm_userlist", $db);

If I ahvent, what have I done wrong? I have tried it with and without the single quotes but to same effect.

sonicgroup
November 30th, 2004, 16:44
Remove the double quotes from your mysql_connect line, so it looks like this:

[syntax:eed2cfdf5c="php"]
$db = mysql_connect('localhost', 'bagnboxm_login', 'login');
[/syntax:eed2cfdf5c]

Tjobbe
November 30th, 2004, 16:46
ah i see, thanks again!

Tjobbe
November 30th, 2004, 16:50
conclusion:

Its finished, thanks very much for your help, its up at: http://www.bagnboxman.co.uk/login/entrance.html

and once you've registered, you have access to the members area (main.php for now) and as admin you can see who is registerred via http://www.bagnboxman.co.uk/login/display.php


thanks very very much!