This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I have this code:
include "config.php";
if (isset($connect)) {
echo "connected";
} else {
echo "not connected";
}
And this is the config.php file:
$localhost = "localhost";
$db_username = "*****";
$db_password = "*****";
$db_name = "*****";
If($connect = mysqli_connect("$localhost ","$db_username ","$db_password ","$db_name ")){}or die{}
I dont know why, but when I try to do some queryIi dont get anything
$sql="SELECT * FROM table_name ORDER BY column_name ASC";
$query=($connect,$sql);
While($row = mysqli_fetch_object($query)) {
Echo $row>column;
}
the error is:
Parse error: syntax error, unexpected '}' in /path/index.php on line 6
i see a more than one problem in your codes,
First from config.php
If($connect = mysqli_connect("$localhost ","$db_username ","$db_password ","$db_name ")){}or die{}
This is not right code, error in {}or die{} it must be {} else {die();}
But i recommended you to use this one instead,
$connect = mysqli_connect("$localhost", "$db_username", "$db_password", "$db_name") or die(mysqli_connect_error());
And about the third code have some problems, first
$query=($connect,$sql);
You forgot to use mysqli_query
$query=mysqli_query($connect, $sql);
And in printing the data you must use -> not >
Echo $row->column;
I hope this helps.
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I am writing a code which compares the user passwords using password verify and outputting the result accordingly. Also, I'm printing a hashed password from database before comparing. But, I am getting the error Fatal error: Call to a member function fetch_assoc() on boolean Here is the DbConnect.php file included in main file
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "task_manager";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Here is the main file with an error
<?php
include "DbConnect.php";
$email = "joshiashish191#gmail.com";
$user_password = "123456";
$sql = "SELECT password from users WHERE email = $email";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
echo $row["password"];
}
if(password_verify($user_password, $result)){
echo "password matches!";
}
else
echo "Passwords do not match.";
?>
Whats wrong with this can anyone tell please?
email field expects a string, escaping quotes are missing in your query.
$sql = "SELECT password from users WHERE email = \"$email\"";
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Is it possible to use both MySQLi and PDO?
(2 answers)
Closed 5 years ago.
here is my code which I pass two variables from android studio to php. xampp has both apache and MySQL running on the default ports. my aim is to compare variables got from android studio with ones in the database table; but i get an error that says:
Uncaught Error: Call to a member function bindParam() on boolean in C:\xampp\htdocs\digikala\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\digikala\index.php on line 10.
I should also mention windows 10 pro is running on my system.
could any of you guys could help me get over this problem? thanks in advance.
here is my connect.php code:
<?php
function OpenCon()
{
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$db = "digikala";
$conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);
return $conn;
}
function CloseCon($conn)
{
$conn -> close();
}
?>
and this is my main code which error belong to. if I remove bindParam and put $email and $pass directly in sql code the same error happens for line contains $result->execute():
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include "connect.php";
$email=$_POST["user"];
$pass =$_POST["pass"];
$conn = OpenCon();
$query = 'SELECT * FROM member WHERE email=:email AND pass=:pass';
$result= $conn->prepare($query);
$result->bindParam(':email',$email);
$result->bindParam(':pass',$pass);
$result->execute();
$row = $result->fetch(PDO::FETCH_ASSOC);
if ($row == false ){
echo("not existed!");
}else{
echo("welcome" . $email);
}
CloseCon($conn);
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm working on a PHP based website and have come across an extremely weird issue that I hoping for some type of guidance for.
Whilst creating a sign up page, I've added in all the relevant coding but when adding a test account into the form, I am given this particular error that I seem unable to fix.
"Parse error: syntax error, unexpected end of file in E:\webareas\wo1742o\ucwe_cw\process.php on line 31"
Could anyone possibly provide some clarity as to why this error keeps popping up?
Here's the code used for SQL connection
<?php
if(!empty($_POST['username']) && !empty($_POST['userpassword'])) {
require 'sqlData.php';
// Database Connection
$link = mysqli_connect($host, $username, $password, $dbname) or die('Failed to connect to MySQL server. ' . mysqli_connect_error($link));
$username = stripslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// get values from form in login.php file
$username = $_POST['username'];
$password = $POST['passname'];
$query = "SELECT id, username, passwod FROM users WHERE username =
'$username' AND password = '$password'";
// Query the database for user
$result = mysql_query("select * from users where username = '$username' and password = '$password'") or die('Failed to query database'.mysql_error());
//output data
$row = mysql_query($result);
if ($row['username'] == $username && $row['password'] == $password) {
echo "Login success! Welcome".$row['username'];
} else {
echo "Failed to login";
}
?>
You are missing a closing curly bracket for the if statement at the start of the file. Add a } before the ?> at the end of the file.
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.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
This is a registration page code. I don't know why it is giving me a syntax error. Although everything in the page seems fine. Here is the code:
<?php
// Grab User submitted information
if (isset($_POST["Register"])) {
$name = $_POST["Name"];
$email = $_POST["Email_Address"];
$utdid = $_POST["Utd_ID"];
$uname = $_POST["Email_Address"];
$password = $_POST["Password"];
// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("planner",$con);
$result = mysql_query("INSERT INTO User(Name, UtdId, Username, Password) VALUES ('$name', '$utdid', '$uname', '$password')");
if($result) {
session_start();
$_SESSION['logged_user']= $uname;
header("Location:CS_MS_Plan.php”);
}
else
{ ?>
<script>alert(“error”);</script>
<?php
}
?>
Similar code works like a peach for login. Any ideas?
this if is not closed
if (isset($_POST["Register"])) {