This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I'm trying to run this code
<?php
$mysqli = new mysqli("localhost", "root", "", "localhost");
$res = $mysqli->query("SELECT id, email FROM users WHERE id = 1");
$row = $res->fetch_assoc();
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
printf("email = %s (%s)\n", $row['email'], gettype($row['email']));
?>
But it's returning parse error
Parse error: syntax error, unexpected '$mysqli' (T_VARIABLE) in
D:\xampp\htdocs\index.php on line 4
Anyone know what it could be?
please try your code in this way,
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT id, email FROM users WHERE id = 1";
$result=mysqli_query($con,$sql);
// Associative array
$row=mysqli_fetch_assoc($result);
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
printf("email = %s (%s)\n", $row['email'], gettype($row['email']));
// Free result set
mysqli_free_result($result);
mysqli_close($con);
?>
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:
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 5 years ago.
I feel like I am beating a dead horse. I have tried many of the suggestion here including ; and "" and ; etc. and I keep getting the same error. Could someone give me a hand please? TIA
This is my code:
// Connect to the database
$cn = mysqli_connect($db_host, $db_user, $db_pass) or die("Cannot connect to DB");
mysqli_select_db($conn $db_name) or die("Error accessing DB");
this is my result:
Parse error: syntax error, unexpected '$db_name' (T_VARIABLE) in
G:\Apache24\htdocs\poster\config.inc.php on line 314
I think you lack comma:
mysqli_select_db($conn,$db_name) or die("Error accessing DB");
PHP mysqli_connect() Function
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
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'];