Page 2 of 3
Posted: Thu May 15, 2003 8:24 am
by Gleeb
I ran into this problem myself recently.
When you're addressing an associative array as part of a string (such as you are doing) you need to use $var[index] instead of $var['index']
Stupid, eh?
fixed it
Posted: Thu May 15, 2003 8:27 am
by irealms
managed to get round that by changing it to:
$email = $row['email'];
$pass = $row['passwd'];
$from = "from:
crimson@irealms.co.uk \r\n";
$mesg = "your password is $pass \r\n";
echo "<fieldset><legend>Mail sent to</legend> $email</fieldset>";
mail($email, $from, $mesg) or die('mail not sent');
ok got it )
Posted: Thu May 15, 2003 8:33 am
by irealms
i did as you suggested and made the access fields inside the already existing user table. I want them to be set at 0 initially and later an admin interface will be set to change them. I made the fields CHAR length 1 default 0
When inserting do i leave out the value for id as it auto increments?
ie.
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die("unable to connect to the database");
mysql_select_db("crimson", $db_conn) or die("unable to select the database");
$query = "insert into user(username,passwd,charname,email) values ($_POST['username'],$_POST['passwd'],$_POST['charname'],$_POST['email'])";
$result = mysql_query($query, $db_conn) or die("query failed");
atm i tried that and i'm getting
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/httpd/vhosts/irealms.co.uk/httpdocs/crimson/register.php on line 24
again, does this mean i need to do $_POST[username] instead of $_POST['username'] ?
Posted: Thu May 15, 2003 8:37 am
by Gleeb
You're on the ball today

Yeah, coz you're putting the variables inside a string, and the ' is playing with it's mind.
Be kind to PHP

Posted: Thu May 15, 2003 8:40 am
by irealms
atm i have
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die("unable to connect to the database");
mysql_select_db("crimson", $db_conn) or die("unable to select the database");
$query = "insert into user(username,passwd,charname,email) values ($_POST[username],$_POST[passwd],$_POST[charname],$_POST[email])";
$result = mysql_query($query, $db_conn) or die("query failed");
and i've got a query failed error , though i'm not sure why
btw your help is really appreciated sorry for the noob questions.
Posted: Thu May 15, 2003 8:45 am
by twigletmac
(
Posted: Thu May 15, 2003 9:02 am
by irealms
k i've done what it says in the post and i still get query failed for some reason with this code now:
Code: Select all
$username = $_POSTї'username'];
$passwd = $_POSTї'passwd'];
$charname = $_POSTї'charname'];
$email = $_POSTї'email'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die("unable to connect to the database");
mysql_select_db("crimson", $db_conn) or die("unable to select the database");
$query = "INSERT into user(username, passwd, charname, email) values ('$username', '$passwd', '$charname', '$email')";
$result = mysql_query($query, $db_conn) or die("query failed");
can't see the problem with the query line
Posted: Thu May 15, 2003 10:29 am
by volka
try
Code: Select all
$result = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
Posted: Thu May 15, 2003 10:41 am
by Gleeb
Volka's a gal?

Posted: Thu May 15, 2003 11:11 am
by volka
nope, but maybe twigletmac is

k
Posted: Fri May 16, 2003 3:47 am
by irealms
i inserted some test info and got this error
query [INSERT into user(username, passwd, charname, email) VALUES ('user1', 'user1', 'user', 'user')] failed: You have an error in your SQL syntax near 'user(username, passwd, charname, email) VALUES ('user1', 'user1', 'user', 'user'' at line 1
Posted: Fri May 16, 2003 3:54 am
by volka
ah, right
user is a reservered word for mysql (in fact it's a function,
http://www.mysql.com/doc/en/Miscellaneous_functions.html#IDX1337)
try
Code: Select all
$query = "INSERT into `user` (username, passwd, charname, email) values ('$username', '$passwd', '$charname', '$email')";
connect twice?
Posted: Fri May 16, 2003 3:56 am
by irealms
also do i need to give connect info twice in the page or will just the once work?
<?
if (!$_POST['username'] || !$_POST['passwd'] || !$_POST['charname'] || !$_POST['email'])
echo "Please complete all fields before submitting your registration.";
elseif (strlen($_POST['username'])<4 || strlen($_POST['passwd'])<4)
echo "<div class=\"log\">Your username and password must be greater than 4 characters.";
elseif (strlen($_POST['username'])>16 || strlen($_POST['passwd'])>16)
echo "<div class=\"log\">Your username and password must be less than 16 characters.";
elseif ($_POST['username'])
{
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die("unable to connect to the database");
mysql_select_db("crimson", $db_conn) or die("unable to select the database");
$checkname = $_POST['username'];
$name_check = mysql_query("SELECT username FROM user WHERE username='$checkname'") or die(mysql_error());
if (mysql_num_rows($name_check) == 1)
echo "user already exists, please choose a different username.";
else
{
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$charname = $_POST['charname'];
$email = $_POST['email'];
$db_conn = mysql_connect("localhost", "cadmin", "cpass") or die("unable to connect to the database");
mysql_select_db("crimson", $db_conn) or die("unable to select the database");
$query = "INSERT into user(username, passwd, charname, email) VALUES ('$username', '$passwd', '$charname', '$email')";
$result = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
}
}
?>
i removed the 2 connect areas and placed it in a a config file, seems to work but will this cause problems or is it ok to do this?
(
Posted: Fri May 16, 2003 4:14 am
by irealms
still got an error the same one in fact, should i just rename the table?
i have used querys to this table bfore like
$query = "update user
set passwd = '$new_passwd'
where username = '$valid_user'";
Posted: Fri May 16, 2003 4:55 am
by []InTeR[]
You can use `'s to get rid of that problem.
$query = "update `user`
set `passwd` = '$new_passwd'
where `username` = '$valid_user'";