hi, i'm new to php5 and mysql.
I'm doing this Login page everything work till i include the
"mysql_connect("localhost","root@localhost", "") or die("Failure to communicate with database!!!");"
as far as i can see. this is the area where the error happen. but i'm not sure whats the error is about.
Please help this confuse newbie...
<?php
$noform_var=0;
if ($_POST[ 'submit' ] == 'Submit') {
if (!$_POST['UserName'] || $_POST['UserName'] == "" || strlen($_POST['UserName'] > 30 )){
$message= '<p>There is a problem. Did you enter an user name?</p>';
$noform_var = 1;
}
else{
//open connection to the database
$noform_var = 1;
mysql_connect("localhost","root@localhost", "") or die("Failure to communicate with database!!!");
mysql_select_db("user");
$as_UserName = addslashes($_POST['UserName']);
$as_UserPassword = addslashes($_POST['UserPassword']);
$as_UserEmail = addslashes($_POST['UserEmail']);
$tr_UserName = trim($as_UserName);
$tr_UserPassword = trim($as_UserPassword);
$tr_UserEmail = trim($as_UserEmail);
$query ="INSERT INTO USER_INFORMATION (USER_ID, USER_NAME, USER_PASSWORD, USER_EMAIL) VALUES (NULL, '$tr_UserName', '$tr_UserPassword', '$tr_UserEmail')";
$result = mysql_query($query);
if (mysql_affected_rows()==1){
$message = "<p>Your information has been recorded. Please login and enjoy the game</p>";
$noform_var = 1;
} else {
error_log(sql_error());
$message = "<p>Something went wrong with your signup attempt. Please email the admin for more information.</p>";
$noform_var = 1;
}
}
}
//show the form in every case except successful submission
if(!$noform_var) {
$thisfile = $_SERVER['PHP_SELF'];
$message = <<< EOMSG
<FORM METHOD="post" ACTION="$thisfile">
<B>Your Name:<INPUT TYPE="TEXT" SIZE=25 NAME="UserName">
<BR><BR>
<B> Your PassWord:<INPUT TYPE="TEXT" SIZE=25 NAME="UserPassword">
<BR><BR>
<B> Your Email:<INPUT TYPE="TEXT" SIZE=25 NAME="UserEmail">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</form>
EOMSG;
}
?>
<html>
<head>
<STYLE type ="text/css">
<!--
BODY, p {color:black; font-family: verdana;font-size: 10 pt}
H! {color:n;acl; fpmt-family: arial; font-size:12 pt}
-->
</style>
<title>Login Page</title>
</head>
<body>
<table border=0 cellpadding=10 witdth=100%>
<tr>
<td bgcolor="#F0F8FF" align=center valign=top width=17%>
</td>
<TD bgcolor="#FFFFFF" align=left valign=top width=83%>
<h1> Newsletter sign-up form</h1>
<?php echo $message; ?>
</td>
</tr>
</table>
</body>
</html>