PHP error with registration [duplicate] - php

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

Related

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.

How do I fix this parse error in my php 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 getting the follow error in the code below: (Parse error: syntax error, unexpected end of file, expecting '`' in).
<?php
include_once 'connect.php';
include_once 'functions.php';
sec_session_start(); // Our custom secure way of starting a PHP session.
if (isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p']; // The hashed password.
if (login($email, $password, $mysqli) == true) {
// Login success
header('Location: ../protected_page.php');
` //echo 'Login Successful';
}
else {
// Login failed
header('Location: ../loginpage.php?error=1');
//echo "Login Unsuccessful";
}
}
else {
// The correct POST variables were not sent to this page.
echo "Invalid Request";
} ?>
You missing closing curly brace for
if (login($email, $password, $mysqli) == true) {
also missing closing curly brace for parent if condition
if (isset($_POST['email'], $_POST['p'])) {
Maybe 'connect.php' or 'functions.php' file will be include '`' character.
Please investigate these files.

php 7 session not working [duplicate]

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

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

Warning: Cannot modify header information - headers already sent by [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 9 years ago.
<?php session_start();
include_once("include/Connection.php");
$userid=$_POST['userid'];
$password=$_POST['password'];
$loginSql = "SELECT * FROM admin2 WHERE admin_name='$userid' and admin_psw='$password'";
$loginQuery=mysql_query($loginSql);
$num_row = mysql_num_rows($loginQuery);
$login = mysql_fetch_array($loginQuery);
$user = $login['admin_name'];
$password = $login['admin_psw'];
echo $user;
echo $password;
if($num_row >0)
{
if($user == $userid)
{
$_SESSION['id_gosi'] = $login['id'];
$_SESSION['userid_gosi'] = $login['admin_name'];
header("Location: CustomerMaster.php");
}
else{
header("Location: index.php?msg=2");
exit();}}
else{
header("Location: index.php?msg=1");
}?>
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\php_mahavirbhadra\Admin\validate_login.php:17) in C:\wamp\www\php_mahavirbhadra\Admin\validate_login.php on line 26
Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0
when i write above code for admin login in php than connection successfully done but give me above error what can i do for this error ...Please give me solution....
print/echo before HEADER is WRONG !!!
/* echo $user;
echo $password;*/
if($num_row >0)
{
if($user == $userid)
{
....
header("Location: CustomerMaster.php");
}
else
{
header("Location: index.php?msg=2");
exit();
}
}
else
header("Location: index.php?msg=1");
?>
never echo ANYTHING before HEADER, so remove those ECHO $USER, $PASSWORD
Tip 1-> Use mysqli instead of mysql
Tip 2-> Use prepared statement
Tip 3-> Use mysql_real_escape_string()

Categories