This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
When I try to insert mysql rows i get this error:
I found this code at: www.w3schools.com/php/php_mysql_insert.asp
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\enviar.php on line 17
This is the code:
<?php
$servername = "localhost";
$username = "*****";
$password = "*****";
$dbname = "*******";
$produto = $_REQUEST['produto'];
$mesa = $_REQUEST['mesa'];
$conc = "fila"
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Send information to mysql
$sql = "INSERT INTO lanchesystem ( Produto, Mesa, conc)
VALUES ('$produto', '$mesa', '$conc')";
if ($conn->multi_query($sql) === TRUE) {
echo "Pedido ConcluĂdo!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close connection
$conn->close();
?>
How to solve this??
Add a semicolon:
$conc = "fila";
I also recommend using a text editor with a linter. It'll save you some time and headache.
Related
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 4 years ago.
$serverName = 'servername';
$uid = 'username';
$pwd = 'password';
$conn = new mysqli($serverName, $uid, $pwd );
if (!$conn) {
echo "Connection failed: " ;
}
else
{
echo "Connected successfully";
}
This is my code. It gets connected to the database. I just want to confirm the code is right, because when i try doing this
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
it throws me connection failed error.
So, is my code connected to the server or not? because when i run a query it does not show me anything.
Code for the query:
$sql = "SELECT max([line_nbr]) FROM [dbo].[so_audit]";
$res = $conn->query($sql);
var_dump($res);
please advise
you are not trying to connect to sql server u should use sqlsrv_connect instead of mysqli
so u need to specify the server name and an array containin connection info for that your code should look like this :
$srv ="servername"
$info=array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $srv, $info);
if (!$conn) {
echo "Connection failed: " ;
}
else
{
echo "Connected successfully";
}
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
<?php
$conn=mysql_connect(`localhost'," root","") or die("Could not connect");
mysql_select_db("bng_nov",$conn) or die("could not connect database");
?>
Parse error: syntax error, unexpected end of file, expecting '`' in C:\xampp\htdocs\display\db.php on line 4
Error in this line replace (`) with (') single quote. also remove space before root
$conn=mysql_connect('localhost',"root","") or die("Could not connect");
and best solution is use double quotes like this
$conn=mysql_connect("localhost","root","") or die("Could not connect");
also i mention that don't use mysql_*. you should used mysqli_*
i have add some DB connectivity codes. used this code
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
error in the below line
$conn=mysql_connect(`localhost'," root","")
please try like below
<?php
if (!$link = mysql_connect('localhost', 'root', '')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('bng_nov', $link)) {
echo 'Could not select database';
exit;
}
?>
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
I just need a simple mysqli-Connection invoked from a php-Script. The following script doesn't respond. Would be way easier if some kind of error-message appears, or even some echo-statements for debugging purposes. But no. Only white screen.
<?php
private $db_config_file = realpath(dirname(__FILE__)) . "config/db.ini";
private $db = NULL;
if (!file_exists($this->db_config_file)) {
$msg = "The config-file <code>"
. $this->db_config_file
. "</code> doesnt't exist.";
show_error_page($msg);
}
$config = parse_ini_file($this->db_config_file);
$host = $config[$host];
$user = $config[$user];
$password = $config[$password];
$dbname = $config[$dbname];
$conn = new mysqli($host, $user, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else echo "Connection established!";
$conn->close();
?>
The db.ini:
host = localhost
dbname = bl
user = mm
password = noadmin
try to change
$host = $config[$host];
$user = $config[$user];
$password = $config[$password];
$dbname = $config[$dbname];
to
$host = $config['host'];
$user = $config['user'];
$password = $config['password'];
$dbname = $config['dbname'];
you are using $host = $config[$host], it need to be $config['host']
hello im trying to follow login code but i always get the error of unexpected die , i saw almost all previous answers for this error but non of it helped me in my code
here is the the php code : heres all the codes i'm following
<?php
$usernameVal=$_REQUEST["username"];
//$passwordVAl=$_REQUEST["password"];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "learn2crack-login-register";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$escapedPW = mysqli_real_escape_string($conn,$_REQUEST['password']);
what am i doing wrong ??
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
solved: i missed ; in echo file
I am new to php, i have succesfully loaded data into sql using input textbox in html but i am unable to load the same into database by reading csv file and i am getting parse error for the fopen function. pls help
upload.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ib";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else
$file=$_FILES["file"]["tmp_name"];
echo $file
fopen($file, 'r');
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
$sql = "INSERT into ib(atmid,location,zone,cash,fault) values('.$emapData[0]','.$emapData[1]','.$emapData[2]','.$emapData[3]','.$emapData[4])";
$conn->query($sql);
}
fclose($test);
echo "CSV File has been successfully Imported.";
?>
You $sql has quotes problem, below is the updated one:
$sql = "INSERT into ib(atmid,location,zone,cash,fault) values('".$emapData[0] ."','".$emapData[1] ."','" . $emapData[2] . "','".$emapData[3] . "','".$emapData[4] . "')";