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();
}
?>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am trying to link my MySQL database to my PHP code. My friend has the same code as me and is able to connect their database to their PHP code. I end up getting a error code and do not know where I am going wrong.
This is the code that I am using
<?php
$username="root";
$password="password";
$database="account";
$connect = mysql_connect('localhost', $username, $password);
//$db-select = mysql_select_db($database,$connect) or die("Unable to select database");
$user = $_GET['user'];
$pass = $_GET['pass'];
if(!$connect) {
die('eror');
}
$db = my_sql_select_db("account", $connect)
mysql_query($db, "INSERT INTO 'account', 'tbl_account' (Username, Password) VALUES ('$user', '$pass')";);
mysql_close($connect);
?>
This is the outcome:
Parse error: syntax error, unexpected 'mysql_query' (T_STRING) in C:\Apache24\htdocs\PHP\index.php on line 11
add semicolon at the end of first line and remove the extra semicolon in second line
$db = my_sql_select_db("account", $connect);
mysql_query($db,"INSERT INTO 'account','tbl_account' (Username,Password) VALUES ('$user','$pass')");
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);
?>
This question already has answers here:
Syntax error unexpected T_CONSTANT_ENCAPSED_STRING [closed]
(3 answers)
Closed 6 years ago.
<?php
$con = mysqli_connect("localhost" "root" "") or die("Unable to connect");
mysqli_select_db("logindb", $con);
?>
This is the configuration of the connecting.
<?php
require 'config.php';
?>
This is where is connect the database to a registration page.
Can you see something wrong? This is the error i get:
Parse error: syntax error, unexpected '"root"' (T_CONSTANT_ENCAPSED_STRING)
Thanks,
Realcookie
You are missing the commas bro. Here is the corrected one
<?php
$con = mysqli_connect("localhost", "root", "") or die("Unable to connect");
mysqli_select_db($con, 'logindb');
?>
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.
I wrote my code like this
<?php
$dbCon = mysqli_connect("localhost" "XXXXXXXX" "XXXXXXXXX" );
if(mysqli_errno()){
echo "Cannot connect:" .mysqli_connect_error();
}
?>
but this is my error
Parse error: syntax error, unexpected '"XXXXXXXX"' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\Project\connection.php on line 2
You need commas to separate the parts in your connection:
$dbCon = mysqli_connect("localhost", "XXXXXXXX", "XXXXXXXXX" );