First of all thank you for taking the time to answer. I am quite new at php and I am trying to save data to a database using php. I have written the bulk but keep getting an error: Parse error: syntax error, unexpected ''.$fname'' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\savedata.php on line 33
I have tried several variations with and without the . at the start. and with only one set of quotation marks however I still receive the error.
here is the line of code:
VALUES (
NULL , ''.$fname'', ''.$lname'', ''.$email'', ''.$pass'')');
here is the rest of the code:
<?php
// Define database credentials
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'mydb_records';
// Create db connection
$conn = mysql_connect($localhost,$root,$password) or die('Error: Could not connect to database - '.mysql_error());
// Once connected, we can select a database
mysql_select_db($database,$conn) or die('Error in selecting the database: '.mysql_error());
// Grab user input and sanitize
$fname = mysql_real_escape_string(filter_var(trim($_POST['fname']), FILTER_SANITIZE_STRING));
$lname = mysql_real_escape_string(filter_var(trim($_POST['lname']), FILTER_SANITIZE_STRING));
$pass = mysql_real_escape_string(filter_var(trim($_POST['pass']), FILTER_SANITIZE_STRING));
// Validate the user email
if(! $email = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
{
echo 'Please insert a valid email.';
die();
}
$sql = 'INSERT INTO `$database`.`records` (
`users_id` ,
`users_fname` ,
`users_lname` ,
`users_email`,
`users_pass`
)
VALUES (
NULL , ''.$fname'', ''.$lname'', ''.$email'', ''.$pass'')');
if(mysql_query($sql))
{
echo 'User information saved successfully.';
}else
{
echo 'Error: We encountered an error while inserting the new record.';
}
mysql_close($conn);
?>
if anyone could point me in the right direction of how to get rid of the error, that would be much apprectiated.