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 '
Related
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)
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();
}
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Sorry to bother you,
So i mixed APIs in my code in my first post, i figured it out and i checked my code, now everything is in MYSQL (not with MYSQLI and MYSQL as it was in my first post).
I've got another problem with my code, i've got the following error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in your code on line 8.
So here's my code, if someone could help me what to do, i would be thankful :)
<?php
session_start();
ob_start();
error_reporting(E_ALL);
require_once 'dbconnect.php';
include_once("apitest/Functions/GTServerInfo.php");
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
// output data of each row
while($row = mysql_fetch_assoc($result)) {
$ip=$row["server"];
}
} else {
echo "0 results";
}
mysql_close($con);
if( !isset($_SESSION['user']) ) {
header("Location: index.php");
exit;
}
?>
Line 8:
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
It should be $_SESSION and not $_SESSiON, I corrected it below;
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm pretty new to PHP, and after typing up a few lines and testing I ran into an error that I have no idea on how to fix:
Parse error: syntax error, unexpected T_VARIABLE in /home/nil/public_html/php/getuids.php on line 10
<?php
$connection = mysql_connect("localhost", "root", "") or die("connection unsuccessful");
mysql_select_db("nil_chatModerators")
$query = "SELECT * FROM moderators";
$result = mysql_query($query);
echo $result;
mysql_close();
?>
Here's a screenshot of everything from phpMyAdmin:
(can't post images yet..) http://i.imgur.com/LG4Km33.png
Thanks for any help in advance!
Semicolon missing in line 4. See my updated code
<?php
$connection = mysql_connect("localhost", "root", "") or die("connection unsuccessful");
mysql_select_db("nil_chatModerators");
$query = "SELECT * FROM moderators";
$result = mysql_query($query);
echo $result;
mysql_close();
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
When I run this code:
<?php
$reuser = $_GET['ruser'];
$mail = $_GET['msg'];
$sender = $_GET['senderr']
$connection = mysql_connect("localhost","root");
mysql_select_db("final");
if(!$connection){
die('could not connect:'.mysql_error());
}
$sql = "INSERT INTO mails (sender,to,message,)
VALUES ('$sender','$reuser','$mail')";
mysql_query($sql) or die("error".mysql_error());
mysql_close($connection);
?>
I get this error:
Parse error: syntax error, unexpected '$connection' (T_VARIABLE) in C:\xampp\htdocs\final\newmail.php on line 7
I don't know what the problem is – can anyone help me please?
You're missing a semi-colon at the end of this line:
$sender = $_GET['senderr']
It should be:
$sender = $_GET['senderr'];