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')");
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)
Closed 5 years ago.
I'm having problems with insert details to mysql server.
This is the code (a simple one):
<?php
//Input posted data.
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$Date = $_POST["Date"];
$Mail = $_POST["Mail"];
$Pass = $_POST["Pass"];
// Create connection
$conn = mysqli_connect('localhost','root',"");
//Check if the connection was opened, if not prompt the error to the page.
if ($conn)
{
die('Could not connect: ' . mysql_error());
}
//Select the data base.
mysqli_select_db("club",$conn);
//Set the character set to utf-8 to allow hebrew.
mysqli_query("SET NAMES 'utf8'");
//SQL query - user Details
$sql = "INSERT INTO 'customers' (Fname, Lname, Mail, Date, Pass)
VALUES('$Fname','$Lname','$Mail','$Date','$Pass');
//Run SQL query
$results = mysqli_query($query) or die (mysql_error());
//Close the SQL connection.
mysqli_close($conn);
?>
I'm getting this error:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\Contact.php on line 36 <--- The last line
Can really use your help.
thanks in advance,
Jason.
$results=mysqli_query($sql);
you have given $query instead of $sql
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:
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();
?>