This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I am getting this message
Parse error: syntax error, unexpected '$username' (T_VARIABLE) in
C:\wamp64\www\tutorial\register_parse.php on line 9
when trying my own register for forum. I can figure out what ive done wrong.
here is the code:
<?php
include("connect.php");
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "INSERT INTO forum.users(username,password)
VALUES("$username","$password"); ";
$res = mysql_query($sql);
if($res){
echo "Successfully registered as: ".$username;
}
else{
echo "failed to register, please try again </br>";
echo "ERROR: ".mysql_error();
}
?>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I want to display the table categories with PHP code, but displays the error:
Parse error: syntax error, unexpected end of file in
W:\domains\test.ru\index.php on line 15.
What to do?
CODE:
<?php
$connection = mysqli_connect('127.0.0.1', 'root', '19912005', 'test_bd');
if($connection = false){
echo 'Не удалось подключится к БД!';
exit();
$result = msqli_qery($connection, "SELECT * FROM `categories`");
$r1 = mysqli_fetch_assoc($result);
print_r($r1);
?>
put the code below inside your codes, it is going to work
if($connection = false){
echo 'Не удалось подключится к БД!';
exit();
}
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
<?php
include("con.php");
$username=$_POST["username"];
$password=$_POST["password"];
$query = "select * from login where username='$username' and password='$password'";
$data = mysqli_query($con,$query) or die ("Couldn't execute query");
$result = mysqli_fetch_assoc($data);
if ($username=="" and $password=="")
{
echo '<script language="JavaScript">alert("Blank Username or Password");
document.location="login.html"</script>';
}
else
{
if ($username=="$result[]" and $password=="$result[]")
{
session_start();
$_SESSION['namauser'] = $username;
$sql = mysqli_query($con,$query) or die ("Couldn't execute query");
header("Location:hal1.php");
}
else
{
echo '<script language="JavaScript">alert("Wrong Username or Password");
document.location="login.html"</script>';
}
}
?>
Please fix this... I've tried my best to fix this but I failed.
if ($username==$result['username'] and $password==$result['password'])
But you are doing it very dangerous.
Solutions :
Sanitize and validate input coming from user. Sanitize and validate username and password.
It is not true way ($username=="" and $password=="") you have to do i($username=="" || $password=="")
and your code logic very bad. search it on web ( login form best practice )
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Can I mix MySQL APIs in PHP?
(4 answers)
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I am trying to upload information to a database. The page I created is a registration page where users can type in their email username and password. The below code is the database connection and upload code I have written. But I keep getting the above error. Can someone tell me what I am missing, please?
<?php
$db_host=
$db_username=
$db_pass=
$db_name=
$connectToServer =mysqli_query($host,$db_username,$db_pass) or die("server problem");
$selectDb =mysqli_select_db($connectToServer,$db_name) or die("database not found");
if(isset($_POST['submit'])) {
$username=$_POST['username'];
$email=$_POST['eml'];
$password =$_POST['password'];
if(!empty($username)&&!empty($email)&&!empty($password)) {
$username = striplashes($username);
$email=striplashes($email);
$password=striplashes($password);
$username = mysql_real_escape_string($connectToServer,$username);
$selectTable = "SELECT * FROM user_info WHERE username='$username'"
$query = mysqli_query($connectToServer,$selectTable);
$insert = "INSERT INTO user_info (username, email, password) VALUES ($username, $eml, $password)"
$mquery = mysqli_query($connectToServer,,$insert);
if ($mquery) {
session_start();
$_SESSION['login_user'] =$username ;
header("Location ; profile.php");
}
}
else {
echo <script>('please enter details')</script>;
header("Location: register.html");
}
}
?>
You are missing a semi-colon on line 22:
$selectTable = "SELECT * FROM user_info WHERE username='$username'"; // <- here
Same for line 24.
You have an extra comma on line 25...
And you are missing double-quotes on line 34...
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
include('Connect.php')
$sql = "insert into medicaments values ('$_REQUEST[code_med]','$_REQUEST[name_med]', '$_REQUEST[exp_date]','$_REQUEST[qte_med] ')";
mysqli_query( $sql , $con);
echo " Record Inserted Successfully = " . mysqli_affected_rows($con);
mysqli_close($con)
after include('Connect.php') add ; like this include('Connect.php');
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Can anybody tell me what is wrong with my code? I cant seem to solve this error:
Parse error: syntax error, unexpected 'mytable' (T_STRING) in E:\XAMP server\htdocs\fyp\login.php on line 11
<?php
$user = ‘minzhe’;
$pswd = ‘2818327’;
$db = ‘trial’;
$conn = mysql_connect(‘localhost’, $user, $pswd);
mysql_select_db($db, $conn);
$un = $_POST['username'];
$pw = $_POST['password'];
$query = “SELECT * FROM mytable WHERE username = ‘$un’ AND password = ‘$pw’”;
$result = mysql_query($query);
if(mysql_num_rows($result) >0)
echo 1;
else
echo 0;
?>
Don't use a word processor to edit your code:
$user = ‘minzhe’;
^------^
You've got "smart quotes" everywhere, and they are NOT valid quotes in PHP. They have to be ' or ".
You are also vulnerable to sql injection attacks.
your computer is defaulting to curvy quotation marks. which PHP cannot read;
“ should be replaced with "
and ‘ should be replaced with '