Any idea why my code keeps producing syntax error? [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I can't seem to find where either a semi colon or a "}" is needed
for ($period=1; $period<6; $period++)
{
echo "<tr><td>".$period."</td>";
for ($room=0; $room<sizeof($rooms_array); $room++)
{
$sql = "SELECT Username FROM Booking WHERE RoomID ='".$rooms_array[$room]."' AND Period = '".$period."' AND Date = '".$sentdate."'";
$result= sqlite_query($con,$sql);
$row = sqlite_fetch_array($result);
if($row['Username']==$_SESSION['Username'])
{
echo "<td>Booked By ".$row['Username']."</td>"
}
}
}
?>

You need a semicolon after your echo statement:
{echo "<td>Booked By ".$row['Username']."</td>";}
Errors like this might be easier to find if you adopted a clearer block/indent style. Your code is pretty hard to read.
For example:
for ($period=1; $period<6; $period++)
{
echo "<tr><td>".$period."</td>";
for ($room=0; $room<sizeof($rooms_array); $room++)
{
$sql = "SELECT Username FROM Booking WHERE RoomID ='".$rooms_array[$room]."' AND Period = '".$period."' AND Date = '".$sentdate."'";
$result= sqlite_query($con,$sql);
$row = sqlite_fetch_array($result);
if($row['Username']==$_SESSION['Username'])
{
echo "<td>Booked By ".$row['Username']."</td>";
}
}
}

Missing ; here:
{echo "<td>Booked By ".$row['Username']."</td>"}
^

echo "<td>Booked By ".$row['Username']."</td>" is missing a semicolon

Related

Uncaught PDOException: SQLSTATE[HY093] [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I get this erro: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\PHP\tennis\ronde2-wijziging.php:59
// code van het knop wijzigen
if(isset($_POST['wijzig'])){
$id = $_POST['id'];
$speler1 = $_POST['speler1'];
$speler2 = $_POST['speler2'];
$uitslag1 = $_POST['uitslag1'];
$uitslag2 = $_POST['uitslag2'];
$datum = $_POST['datum'];
$veld = $_POST['veld'];
//UPDATE: gegevens in de form wijzigen.
$sql = "UPDATE ronde1 SET speler1 = :speler1, speler2 = :speler2, uitslag1 = :uitslag1,
uitslag2= :uitslag2, datum= :datum, veld= :veld WHERE id=:id";
$stmt = $pdoConnect->prepare($sql); //stuur naar mysql.
$stmt->bindParam(":id", $id );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":uitslag1", $uitslag1 );
$stmt->bindParam(":uitslag2", $uitslag2 );
$stmt->bindParam(":datum", $datum );
$stmt->bindParam(":veld", $veld );
$stmt->execute();
// $_SESSION['message'] = "Speler is gewijzigd";
// $_SESSION['msg_type'] = "warning";
header("location: #.php");
exit;
}
I want to update my data.strong text
My solution worked but didn't explain why it did go wrong in the first place. The user dpant explains in the comments why your code snippet was not working.
Credits go to him
dpant:
Most probably the problem with your original code was that you were binding the :speler1 parameter twice (the :speler2 parameter was never bound). This was just a typo in your code. Take a close look at it.

bracket is lost in PHP code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Parse error: syntax error, unexpected '{'
Plz, I wonder Can you help me, I can't find it.
if( isPost() ) {
extract($_POST);
if( validation_required([$name , $family ,$username , $email , $password]) ) {
$conn = connectToDB();
if (!userGet($username,$conn){
saveUsers($_POST) ? redirect("index.php") : $status = 'you are failed';
} else {
$status = "This username is exist";
}
} else {
$status = 'your information is not valid';
}
}
It's line 5:
if (!userGet($username,$conn){
Should have 2 closing brackets
if (!userGet($username,$conn)){

Error in mysqli_num_rows [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What's wrong with this code:
<?php
session_start();
if(!isset($_SESSION['username']) && isset($_COOKIE['username'], $_COOKIE['password']))
{
$checkQuery = "SELECT password, id FROM accounts WHERE username='".$db->real_escape_string($_COOKIE['username'])."'";
$checkResult = mysqli_query($db, $checkQuery);
$check = mysqli_fetch_array($checkResult);
if($check['password'] == $_COOKIE['password'] && mysqli_num_rows($checkQuery)>0)
{
$_SESSION['username'] = $_COOKIE['username'];
$_SESSION['userid'] = $check['id'];
}
}
?>
It shows this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
string given...
Looks like you should change
mysqli_num_rows($checkQuery)
to
mysqli_num_rows($checkResult)

Unexepected T_VARIABLE [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Unexecpected T_VARIABLE in SQL Query on Line 5
How to fix this?
<?php
include "system.php";
$usersystem = $_SESSION['username'];
$passw = $_SESSION['password'];
$query= "SELECT * FROM users WHERE username = "$usersystem" AND password = "$passw";
$autoexec= $mysqli->query($query);
$earnings = $autoexec['earnings'];
$completed = $autoexec['completed'];
if ($_SESSION['loggedin'] !=1){
header ('Location: index.php);
}
?>
The syntax highlighter makes your issue obvious: quotes. You need to use single quotes for your strings in your query:
$query= "SELECT * FROM users WHERE username = '$usersystem' AND password = '$passw'";
Basic PHP syntax:
$query= "SELECT * FROM users WHERE username = "$usersystem" AND pas
^-- ^---
You cannot use the same type of quotes that you've used to delimit the string. Try
$query= "SELECT * FROM users WHERE username = \"$usersystem\" AND pas
^--- ^--- note the escapes
And since this is a simple typo-type problem, voting to close the question...

Count rows with two values mysql (PHP Error) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have the following code, but for some reason I am getting an unexpected T_Variable. I can't seem to figure out where I am getting the error at. Any assistance will be greatly appreciated. Thanks
<? php
$status = mysql_query('SELECT count(*) FROM AHG WHERE `Survey Tech Initials` = 'Jeff' AND completed = 'yes');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>
See below
<? php
$status = mysql_query("SELECT count(*) FROM AHG WHERE `Survey Tech Initials` = 'Jeff' AND completed = 'yes'");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>

Categories