Error executing query PHP [duplicate] - php

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')");

Related

What could be the problem with inserting the query from localhost database? [duplicate]

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']."')");

I got a mistake when I run the this code: [duplicate]

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')";

Submitting form to database error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm trying to add a simple form data to a mysql databse and it seems to not work.
It gives me this error
Parse error: syntax error, unexpected ';' in portfolio-add-website.php on line 7
and portfolio-add-website.php looks like this:
<?php
include 'connect_db.php';
$connect = mysqli_connect(HOST,USERNAME,PASSWORD,DB);
mysqli_query($connect,"INSERT INTO portfolio_websites
(name, link, description, profile_img_name,
cover_img_name, client_name, donedate)
VALUES ('$_POST[name]', '$_POST[link]',
'$_POST[description]',
'$_POST[profile_img_name]',
'$_POST[cover_img_name]', '$_POST[client_name]',
'$_POST[donedate]')";
?>
I don't see any unexpected ";". Can anyone help me? I'm sure it's something small.
You missed a closing brace
mysqli_query($connect,"INSERT INTO portfolio_websites (name, link, description, profile_img_name, cover_img_name, client_name, donedate)
VALUES ('$_POST[name]', '$_POST[link]', '$_POST[description]', '$_POST[profile_img_name]', '$_POST[cover_img_name]', '$_POST[client_name]', '$_POST[donedate]')");

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:/... on line 10 [duplicate]

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?

Parse error: syntax error, unexpected 'md5' (T_STRING) [duplicate]

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'])."

Categories