This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Sorry to bother you,
So i mixed APIs in my code in my first post, i figured it out and i checked my code, now everything is in MYSQL (not with MYSQLI and MYSQL as it was in my first post).
I've got another problem with my code, i've got the following error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in your code on line 8.
So here's my code, if someone could help me what to do, i would be thankful :)
<?php
session_start();
ob_start();
error_reporting(E_ALL);
require_once 'dbconnect.php';
include_once("apitest/Functions/GTServerInfo.php");
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
// output data of each row
while($row = mysql_fetch_assoc($result)) {
$ip=$row["server"];
}
} else {
echo "0 results";
}
mysql_close($con);
if( !isset($_SESSION['user']) ) {
header("Location: index.php");
exit;
}
?>
Line 8:
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
It should be $_SESSION and not $_SESSiON, I corrected it below;
$sql = "SELECT server FROM users WHERE userId = $_SESSION['userId']";
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
<?php
include("con.php");
$username=$_POST["username"];
$password=$_POST["password"];
$query = "select * from login where username='$username' and password='$password'";
$data = mysqli_query($con,$query) or die ("Couldn't execute query");
$result = mysqli_fetch_assoc($data);
if ($username=="" and $password=="")
{
echo '<script language="JavaScript">alert("Blank Username or Password");
document.location="login.html"</script>';
}
else
{
if ($username=="$result[]" and $password=="$result[]")
{
session_start();
$_SESSION['namauser'] = $username;
$sql = mysqli_query($con,$query) or die ("Couldn't execute query");
header("Location:hal1.php");
}
else
{
echo '<script language="JavaScript">alert("Wrong Username or Password");
document.location="login.html"</script>';
}
}
?>
Please fix this... I've tried my best to fix this but I failed.
if ($username==$result['username'] and $password==$result['password'])
But you are doing it very dangerous.
Solutions :
Sanitize and validate input coming from user. Sanitize and validate username and password.
It is not true way ($username=="" and $password=="") you have to do i($username=="" || $password=="")
and your code logic very bad. search it on web ( login form best practice )
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
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Can anyone help me take a look? I want to fetch a number out but i get this error
Parse error: syntax error, unexpected ';', expecting ']' in E:\Software\Xampp\htdocs\pme\main\user_online.php on line 12
here is my code
<?php
include '../config.php';
$sql= mysqli_query($connection,' select * from session');
$row = mysqli_num_rows($sql);
while($extract = mysqli_fetch_array($sql)){
echo
"<div class='left-total-user-online' id='left-total-user-online'>
total user online : " .$extract[$row = mysqli_num_rows($sql);]. "</div>";
}
?>
You are making life much more complicated than is necessary. All you need to code is
<?php
include '../config.php';
$sql= mysqli_query($connection,' select * from session');
$row = mysqli_num_rows($sql);
echo "<div class='left-total-user-online' id='left-total-user-online'>
total user online : $row</div>";
}
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm pretty new to PHP, and after typing up a few lines and testing I ran into an error that I have no idea on how to fix:
Parse error: syntax error, unexpected T_VARIABLE in /home/nil/public_html/php/getuids.php on line 10
<?php
$connection = mysql_connect("localhost", "root", "") or die("connection unsuccessful");
mysql_select_db("nil_chatModerators")
$query = "SELECT * FROM moderators";
$result = mysql_query($query);
echo $result;
mysql_close();
?>
Here's a screenshot of everything from phpMyAdmin:
(can't post images yet..) http://i.imgur.com/LG4Km33.png
Thanks for any help in advance!
Semicolon missing in line 4. See my updated code
<?php
$connection = mysql_connect("localhost", "root", "") or die("connection unsuccessful");
mysql_select_db("nil_chatModerators");
$query = "SELECT * FROM moderators";
$result = mysql_query($query);
echo $result;
mysql_close();
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Can anybody tell me what is wrong with my code? I cant seem to solve this error:
Parse error: syntax error, unexpected 'mytable' (T_STRING) in E:\XAMP server\htdocs\fyp\login.php on line 11
<?php
$user = ‘minzhe’;
$pswd = ‘2818327’;
$db = ‘trial’;
$conn = mysql_connect(‘localhost’, $user, $pswd);
mysql_select_db($db, $conn);
$un = $_POST['username'];
$pw = $_POST['password'];
$query = “SELECT * FROM mytable WHERE username = ‘$un’ AND password = ‘$pw’”;
$result = mysql_query($query);
if(mysql_num_rows($result) >0)
echo 1;
else
echo 0;
?>
Don't use a word processor to edit your code:
$user = ‘minzhe’;
^------^
You've got "smart quotes" everywhere, and they are NOT valid quotes in PHP. They have to be ' or ".
You are also vulnerable to sql injection attacks.
your computer is defaulting to curvy quotation marks. which PHP cannot read;
“ should be replaced with "
and ‘ should be replaced with '