PDA

View Full Version : Whats wrong with this php



mlowery
March 20th, 2004, 14:09
I am having trouble with this script.


<?

$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

INSERT into roster
(screen_name, first_name, country, email_address, age, password)
VALUES ($_POST['Screen_Name'],$_POST['First_Name'],$_POST['Country'],$_POST['Email_Address'],$_POST['Age'],$_POST['Password']);

?>

It gives me the error "error on line 7." That would be "INSERT into roster." I am 100% positive that I have selected the correct database, and that the table name is roster.
I've tried fixing it by:
INSERT into 'roster'
INSERT into `roster`

I still don't know what the problem is.

spec
March 20th, 2004, 14:51
<?
$Screen_name = $_POST['Screen_Name'];
$First_name = $_POST['First_Name'],
$country = $_POST['Country'],
$etc = $_POST['etc'],

$query = "INSERT into roster
(screen_name, first_name, country, email_address, age, password)
VALUES ('$Screen_Name','$First_Name','$Country','$etc')";


?>

kabatak
March 20th, 2004, 15:49
Originally posted by spec


<?
$Screen_name = $_POST['Screen_Name'];
$First_name = $_POST['First_Name'],
$country = $_POST['Country'],
$etc = $_POST['etc'],

$query = "INSERT into roster
(screen_name, first_name, country, email_address, age, password)
VALUES ('$Screen_Name','$First_Name','$Country','$etc')";


?>


that would give you a parse error because of using comma instead of semicolon in the first part of your code, but the query is correct.

you can do this also if you dont want to reassign values to variables:



<?

$query = "INSERT INTO roster (screen_name, first_name, country, email_address, age, password) VALUES ('{$_POST['Screen_Name']}', '{$_POST['First_Name']}', '{$_POST['Country']}', '{$_POST['Email_Address']}', '{$_POST['Age']}','{$_POST['Password']}')";

mysql_query($query) or die(mysql_error());

?>

mlowery
March 20th, 2004, 16:07
Thanks a lot man. It works:



<?

$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

$Screen_Name = $_POST['Screen_Name'];
$First_Name = $_POST['First_Name'];
$Country = $_POST['Country'];
$Email = $_POST['Email_Address'];
$Age = $_POST['Age'];
$Password = $_POST['Password'];
$Encpassword = md5($password);

$query = "INSERT into roster
(screen_name, first_name, country, email_address, age, password)
VALUES ('$Screen_Name','$First_Name','$Country','$Email','$Age','$E ncpassword')";

mysql_query($query) or die(mysql_error());

?>

spec
March 20th, 2004, 17:05
no problem, you might want to do some error checking, remember the user could input anything they want, even dangerous code.

mlowery
March 21st, 2004, 03:21
I will sooner or later. The page that this form is on is fairly secure. Right now, I just want to get everything working.