Well currently I've founded very many codes, and i found one i liked... but when i tried it this came: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'tenk'@'localhost' (using password: NO) in C:\wamp\www\blimedlem.php on line 2
Could not connect: Access denied for user 'tenk'@'localhost' (using password: NO)
This is how i filled in:
<?php
$con = mysql_connect("localhost","tenk","");
I also have another code, but that don't work... this comes up:
Parse error: syntax error, unexpected ';' in C:\wamp\www\blimedlem.php on line 7
<?php
// First we take care of the variables, there is no need to even open a database connection if they are not ok
// One way to keep track if everything is ok is to use a variable to check that. I use a variable called $ok.
$ok = true; // We set it to true to start with, then change it if something not as it should be.
if (isset($_POST['firstname'])) // First we check if the variable exists
{
////THIS IS line 7 FOR my code, if it helps: --> $firstname = trim($_POST['firstname']; // Removes spaces in the beginning and end
if (empty($firstname)) // Check if the variable is empty or not.
{
$ok = false; // Set the ok variable to false if everything is not ok.
}
}
if (isset($_POST['lastname']) || !$ok) // Add the check if it is ok to the rest of the variables. Everything else is the same
{
$firstname = trim($_POST['firstname'];
if (empty($firstname))
{
$ok = false;
}
}
// And the same with the other variables. When you have learned a bit more PHP you should use a function for this and call it for each variable instead of writing all in the code.
// When all variables is checked we want to know if we should add it in the database or not.
if ($ok)
{
$con = mysql_connect("xxx","xxx","xxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("regist",$con);
$sql= sprintf ("INSERT INTO person (name, lastname, username, password, email, gender, notes)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname),
mysql_real_escape_string($username),
mysql_real_escape_string($password),
mysql_real_escape_string($email),
mysql_real_escape_string($gender),
mysql_real_escape_string($notes));
if (!mysql_query($sql,$con))
die ('Error: '. mysql_error());
mysql_close($con)
echo "You have registered successfully";
}
else
{
echo "Not all required fields are filled.";
}
?>
I've done many researched and I've gotten very far, but it seems like none other than me got this problem! 🙁