Something going wrong in mysqli_query [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 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

Related

When you try to output a row from a mySQL table using PHP, it returns an error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I want to display the table categories with PHP code, but displays the error:
Parse error: syntax error, unexpected end of file in
W:\domains\test.ru\index.php on line 15.
What to do?
CODE:
<?php
$connection = mysqli_connect('127.0.0.1', 'root', '19912005', 'test_bd');
if($connection = false){
echo 'Не удалось подключится к БД!';
exit();
$result = msqli_qery($connection, "SELECT * FROM `categories`");
$r1 = mysqli_fetch_assoc($result);
print_r($r1);
?>
put the code below inside your codes, it is going to work
if($connection = false){
echo 'Не удалось подключится к БД!';
exit();
}

Getting parse error, syntax error in PHP code [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I am getting this message
Parse error: syntax error, unexpected '$username' (T_VARIABLE) in
C:\wamp64\www\tutorial\register_parse.php on line 9
when trying my own register for forum. I can figure out what ive done wrong.
here is the code:
<?php
include("connect.php");
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "INSERT INTO forum.users(username,password)
VALUES("$username","$password"); ";
$res = mysql_query($sql);
if($res){
echo "Successfully registered as: ".$username;
}
else{
echo "failed to register, please try again </br>";
echo "ERROR: ".mysql_error();
}
?>

T_Variable error thrown in simple PHP code [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I keep getting a T_Variable exception when running this PHP code hosted on an online database. Am not really the expert at PHP, but maybe one of you can spot the error.
thanks,
Here is the code:
$wind = "deep34"; //error thrown here. When I delete this variable. //Error jumps to $name
$name = "6";
$sql = "select *from students where deviceid = '$name' and alpha = '$wind';";
Dont use semicolon at the end of the statement
$sql = "select * from students where deviceid = '$name' and alpha = '$wind'";

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate]

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']";

got an error with while loop in php [duplicate]

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>";
}
?>

Categories