taking 2 values with one query?
Moderator: General Moderators
fixed it
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');
$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 )
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'] ?
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'] ?
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.
$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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
(
k i've done what it says in the post and i still get query failed for some reason with this code now:
can't see the problem with the query line
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");try
Code: Select all
$result = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());Volka's a gal?twigletmac wrote:viewtopic.php?t=8726
k
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
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
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
try
Code: Select all
$query = "INSERT into `user` (username, passwd, charname, email) values ('$username', '$passwd', '$charname', '$email')";connect twice?
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?
<?
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?