This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
$result = "Insert into insert_data (namapelajar1, namapelajar2,
namapelajar3, nopendaftaran1,nopendaftaran2,nopendaftaran3)
values
('$namapelajar1','$namapelajar2','$namapelajar3',
'$nopendaftaran1', '$nopendaftaran2','$nopendaftaran3',
'$kelas', '$tajukprojek');";
It always prompt
Parse error: Parse error: syntax error, unexpected '$result'
(T_VARIABLE) in C:\xampp\htdocs\sistem\insert_data.php on line 20
Any one can keep me some advise?? Many thanks!!
There are two extra column inside values only 6 field are specified but you enter 8 values. Try this
$result = " Insert into insert_data(namapelajar1,namapelajar2,namapelajar3,nopendaftaran1,nopendaftaran2,nopendaftaran3) values ('$namapelajar1','$namapelajar2','$namapelajar3','$nopendaftaran1','$nopendaftaran2','$nopendaftaran3')";
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I am working on getting active users on a localhost server. While I came up with an error. I am providing the portion which is not working in PHP MySQL:
I changed $REMOTE_ADDR, $PHP_SELF to $_SERVER['$REMOTE_ADDR'], $_SERVER['PHP_SELF'] as those are old version of PHP. Still not getting expected result.
$timestamp = time();
//insert the values
$insert = mysql_db_query($database, " INSERT INTO mytable VALUES('$timestamp', $_SERVER['$REMOTE_ADDR'], $_SERVER['PHP_SELF'] )" );
the error goes like this:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING) in G:\xampp\htdocs\jencyphp\liveonline\online.php on
line 21
Can you please check by doing this. You are missing database table fields name in query so you must need to add that fields.
$timestamp = time();
$insert = mysql_db_query($database, "INSERT INTO mytable (`field1`,`field2`,`field3`) VALUES('".$timestamp."','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')");
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 insert the Name and Surname into an User table I created using mysql. The process.php file that has to insert the data throws a syntax error on line 10 (the " just before the INSERT):
Parse error: syntax error, unexpected ' " ', expecting ' , ' or ' )'
What is the problem? Here is my code:
<?php include 'database.php';
// create a variable
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
//Execute the query
mysqli_query ($connect"INSERT INTO User(Name, Pass)
VALUES('$first_name','$last_name')");
?>
Use this
mysqli_query ($connect,"INSERT INTO User(Name, Pass)
VALUES('$first_name','$last_name')");
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
So I am having the $sql variable which is supposed to be a string containing an sql insert statement.Here's the piece of code:
$fields = array('Nume_dep' => $params['Nume_dep'],
'Id_manager' => $params['Id_manager']);
$id = $params['Id_manager'];
$sql = "insert into departament(Nume_dep,Id_manager) values('$params['Nume_dep']', CONVERT($id, UNSIGNED))";
This is the error message that I get:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
The syntax error is in the insert statement, but I don't know how to fix it.
$id = $params['Id_manager'];
$nume_dep=$params['Nume_dep'];
$sql = "INSERT INTO departament(Nume_dep,Id_manager) values('$nume_dep', CONVERT($id, UNSIGNED))";
In strings PHP will only do rather basic automatic variable expansion. The Issue is with the index operator here: $params['Nume_dep']
Consider to use prepared statements in order to prevent SQL injection. If an attacker can make sure, that your function is called with something like "', 43); drop table department; --" as value for $params['Nume_dep'], you're going to be in big trouble.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
<?php
$name=$_POST['name'];
$telephone=$_POST['telephone'];
$comment=$_POST['comment'];
$conn= mysql_connect("localhost","root","");
mysql_select_db("comments",$conn);
$sql= "INSERT INTO inside VALUES{($_POST['name']),($_POST['telephone']),($_POST['comment'])}";
if(mysql_query($sql,$conn))
{
echo 'record added';
}
else
{
echo 'error';
}
?>
I don't know what is the error in line 10, line 10 is:
$sql= "INSERT INTO inside VALUES{($_POST['name']),($_POST['telephone']),($_POST['comment'])}";
My database name is comments and table name is inside, and also sometimes when I finished this I got the result as 'error' I think it comes from the line 18. can you please tell me how to solve this, I'am fed of this!
You have syntax errors in your query. You need to have the curley brackets around every $_POST in your query, and your query should be ... VALUE (....)
change -
$sql= "INSERT INTO inside VALUES{($_POST['name']),($_POST['telephone']),($_POST['comment'])}";
to
$sql= "INSERT INTO inside VALUES ( {$_POST['name']}, {$_POST['telephone']},{$_POST['comment']})";
see
http://dev.mysql.com/doc/refman/5.6/en/insert.html
and
http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
also, you should not be inserting user data directly into your database. take a look at
How can I prevent SQL injection in PHP?
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Here is my PHP code :
$query = "INSERT INTO `user` (`email`, `password`) VALUES('".mysqli_real_escape_string($link, $_POST['email'])."', '"md5(md5($_POST['email']).$_POST['password'])"')";
I cann't avoid these lines error report like this:
Parse error: syntax error, unexpected 'md5' (T_STRING) in G:\Private
files\xampp\phpMyAdmin\abc\projects\diary.php on line 32
Help from anyone is expected...
Create a variable, then assign value to that variable, pass that variable to query. This will give better readability and less errors
Code shown below..
$value = md5(md5($_POST['email']).$_POST['password']);
$query = "INSERT INTO user (email, password) VALUES('".mysqli_real_escape_string($link, $_POST['email'])."', '$value')";
It's simple a Syntax error:
you forget the dots on "md5(md5($_POST['email']).$_POST['password'])"
Change this part to
".md5(md5($_POST['email']).$_POST['password'])."