Insert form data into database glitch [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Alright so I am currently trying to make a system to take applications and it was working until I added the rest of the questions :
<?php
include_once('db.php');
$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']
if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('$user','$job','$active','$why','$le','$skype')"))
echo"successfully inserted";
else
echo "failed";
?>
But when I have it like that I get this error
Parse error: syntax error, unexpected '$le' (T_VARIABLE) in C:\xampp\htdocs\app_insert.php on line 8
Keep in mind I am using xampp with Apache and Mysql, anyone know whats happening?

You missed out the semi-colon, ; for:
$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']
It should be:
$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype'];

You are missing the semi-colon and the insert SQL statement seems incorrect. You are passing the string to SQL statements instead of the value
<?php
include_once('db.php');
$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype']
if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('{$user}','{$job}','{$active}','{$why}','{$le}','{$skype}')"))
echo"successfully inserted";
else
echo "failed";
?>

Related

Parse error: syntax error, unexpected '$query' (T_VARIABLE) in c [duplicate]

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...

Something going wrong in mysqli_query [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I am newbie and learning php yet. I am trying to run some mysqli_query but its giving me some errors. My code is like below.
<?php
ob_start();
include("db.php");
$result = mysqli_query($conn,"SELECT * FROM contest");
while($row = $result->fetch_assoc()){
if($row['automated'] ==1){
echo 'Atomatic is enabled';
$result1 = mysqli_query($conn,"UPDATE `contest` SET automated =0"
$new = mysqli_query($conn,$result1);
echo 'Atomatic is Disabled';
}
else{
echo 'Atomatic is Disabled';
}
}
can somebody check and please suggest me whats wrong in this query ? its giving me error like Parse error: syntax error, unexpected '$new' and similar if I change it. Thanks
Close patenthesis.()..
$result1 = mysqli_query($conn,"UPDATE `contest` SET automated =0");//error was here

mysqli_query doesnt seem to execute correctly [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
This one has had me stumped for a couple of days. I have a basic PHP script to submit a user registration form. I just cant see what I am doing wrong in this instance the web server is running PHP 7.0 and there are no errors in the logs.
<?php
require_once('connect.php');
if(isset($_POST) && !empty($_POST)){
$username = mysqli_real_escape_string($connection, $_POST['username']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$password =md5($_POST['password']);
$sql = "INSERT INTO 'login' (username, email, password) VALUES ('$username', '$email', '$password')";
$result = mysqli_query($connection, $sql);
if($result){
echo "User Rego Secusseflllgk";
}else{
echo "User rego faile";
}
}
?>
I saw a couple of these already but they seemed to be to do with using both myslq and mysqli and others appeared to not be first connection to the DB. Any help would be much appreciated. I am recieving the User Rego Failed echo
You probably want use the backtick ` instead of a single quote ' to wrap your table name.
INSERT INTO `login`
When a query fail, it's useful to print the error message. You can do it with mysqli_error:
echo mysqli_error($connection);
Use table name without single quote and try to check mysqli error with mysqli_error($connection) just after $result.

Android post values to MySQL with PHP [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I work on an Android project, in which I use AsyncTask to send nameValuePairs to webservice.
I use PHP code below to send data from application to database:
<?php
require_once('dbConnect.php');
$studentid = $_POST['name'];
$classid = $_POST['classid']
$studentid = $_POST['studentid'];
$start = $_POST['start'];
$end = $_POST['end'];
$startsig = $_POST['startsig'];
$endsig = $_POST['endsig'];
$sql = "insert into signature (studentid,classid,start,end,startsig,endsig) values ('$studentid','$classid','$start','$end','$startsig','$endsig')";
if(mysqli_query($con,$sql)){
echo 'success';
}
else{
echo 'failure';
}
mysqli_close($con);
?>
Values in dbConnect.php file are correct. Database schema looks like this.
I checked, application sends out data successfully, but when I try to access PHP file above from browser I get a HTTP 500 error.
What else should I check in this case?
There are two problems I noticed in your code you didn't put a semicolon after
$classid = $_POST['classid']
And also why are you assigning two different post values to same phpvariable $studentid = $_POST['name']; and $studentid = $_POST['studentid'];.Anyways $studentid will have the last assigned value $_POST['studentid']
Try debugging for more errors

Can't execute PHP Mysql query, doesn't even open the page [duplicate]

This question already has answers here:
How do I get PHP errors to display?
(27 answers)
Closed 6 years ago.
So, I have some bug in this code that will not execute the query, it just says The localhost page isn’t working - localhost is currently unable to handle this request. And that error shows only when there's some bug in the code, so it won't execute it. I don't know what's the problem here, as I tried to connect to database and that's all ok. Problem lies in lines underneath the connect.php.
if($_POST) {
include('connection.php');
$id_broj = $_POST['id_num'];
$password = $_POST['password'];
$query=mysqli_query("SELECT id,id_broj,ime,prezime FROM zaposleni");
$result=mysqli_query($conn,$query);
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
echo 'Passed';
}
Need to write only query in $query Variable as:
if($_POST) {
include('connection.php');
$id_broj = $_POST['id_num'];
$password = $_POST['password'];
$query="SELECT id,id_broj,ime,prezime FROM zaposleni";
$result=mysqli_query($conn,$query);
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
echo 'Passed';
}

Categories