php 7 session not working [duplicate] - php

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'])){

Related

Unable to redirect after submitting login credentials on hosting site but able to do it on localhost [duplicate]

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

Can not fetch data from database, when the connect is right [duplicate]

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.

Login Page - Parse error: syntax error, unexpected end of file [duplicate]

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.

PHP error with registration [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Hey guys getting an error with this code :
<?php //start php tag
//include connect.php page for database connection
include('connect.php')
//if submit is not blanked i.e. it is clicked.
if(isset($_REQUEST['submit'])!='')
{
if($_REQUEST['name']==''||$_REQUEST['email']==''||$_REQUEST['password']=='')
{
echo "please fill the empty field.";
}
else
{
$sql="insert into FunReads(user_name,user_email,user_password) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."')";
$res=mysql_query($sql);
if($res)
{
echo "Record successfully inserted";
}
else
{
echo "There is some problem in inserting record";
}
}
}
?>
The error is
Parse error: syntax error, unexpected 'if' (T_IF) in /home/ubuntu/workspace/registration.php on line 5
So it's on this line:
if(isset($_REQUEST['submit'])!='')
The syntax error is a missing semicolon after include('connect.php')
include('connect.php');
// ^ missing

syntax error, unexpected end of file in PHP [duplicate]

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"])) {

Categories