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"])) {
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:
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 4 years ago.
<?php
session_start();
include('head1.php');
if(isset($_SESSION['user_id'])!="") {
header("Location: index.php");
exit();
}
//check if form is submitted
$con=mysqli_connect('localhost','root','','rating_system');
if (isset($_POST['login'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$query="select * from tbl_users where email ='$email' and
password='$password'";
$result=mysqli_query($con,$query);
if ($row = mysqli_fetch_array($result)) {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
header("Location:afterlogin.php");
} else {
$errormsg = "Incorrect Email or Password!!!";
}
}
This code works well at localhost but not on the hosting website where the site is live..
i have to manually enter the afterlogin.php in browser to get to that page
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.
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 6 years ago.
I am working with PHP version 7.0.4..I wrote the code to store users' sessions.but it shows the below error:
Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\PCzone\login.php on line 136
The code is:
<?php
$user_name = $_SESSION['user_name'] = $_POST['user_name'];
$user_pass = $_POST['user_pass']
if(isset($_POST['login'])){
$query = "SELECT * FROM `login` WHERE user_name='$user_name' AND user_pass='$user_pass'";
$run = mysqli_query($con,$query);
if(mysqli_num_rows($run)>0){
header("location:view_posts.php");
}
else{
echo "<center><div style='margin-top:8px; width:350px; height:60px; line-height:60px; border:3px solid red; background:rgb(255,145,138); font-family:calibri;'>Login failed, user name or password is incorrect</div></center>";
exit();
}
}
?>
You didn't end your line after you set user pass:
$user_pass = $_POST['user_pass'];
if(isset($_POST['login'])){