Error in mysqli_num_rows [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
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)

Related

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

php code is not working,showing Fatal error: Call to undefined function mysq1i_query() [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 7 years ago.
Improve this question
php code is not working,showing
Fatal error: Call to undefined function mysq1i_query()
<?php
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$conn=mysqli_connect($dbhost,$dbuser,$dbpass,"vishal");
$passkey=$_GET['passkey'];
$tblname="data";
$sql="SELECT * FROM $tblname WHERE confirmcode='$passkey'";
$result=mysq1i_query($sql);
if($result)
{
$count=mysqli_num_rows(($result));
if($count==1)
{
$rows=mysqli_fetch_array($result);
$name=$rows['name'];
$emailid=$rows['emailid'];
$password=$rows['password'];
$confirm=$rows['confirm'];
$country=$rows['country'];
$table2="data1";
$sql2="INSERT INTO $table2 (name,emailid,password,confirm,country)VALUES ('$name','$emailid','$password','$confirm','$country')"; $result1=mysqli_query($sql2);
}
else
{
echo"wrong cofirmation code";
}
if($result1)
{
echo"your account has been activated";
$sql3="DELETE FROM $tblname WHERE confirm_code='$passkey'";
$result2=mysqli_query($sql3);
}
}
?>
you have used on line no: 9
$result=mysq1i_query($sql);
instead of
$result=mysqli_query($sql);
You have an error in this line:
$result=mysq1i_query($sql);
Its l not 1 in (mysq1i)
Correct one is:
$result=mysqli_query($sql);
And when you get this error Undefined Function it means you do not define this function in your code.

PDO Variable Update Error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
these are my query codes. Please help me.
PDO Error: Array
PDO Eror Code: 00000
<?php if ($_POST){
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$id = $_GET['id'];
$save = $PDO->prepare("UPDATE `news` SET `title` = :title WHERE `id` = :id");
$save->execute(array(
"title" => $title,
"id" => $id
));
print_r("Error: ".$save->errorInfo());
print $save->errorCode();
}
?>
It the OK status code.
You always print error but you should to print that only when the query failed.
$sql = $save->execute(...)
if ($sql === FALSE) {
print ('Error: ' . $save->errorCode());
}

Problems with mysqli [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
I'm trying to read some data from a form and then use them using php. I use only mysqli in my php file but I get some warnings and i don't understand why. Here is some code:
<?php
// Connects to your Database
$con = mysqli_connect("localhost", "root", "password", "database");
error_reporting(E_ALL);
ini_set('display_errors', 1);
$all_string = $_GET['name'];
if($all_string == NULL) exit("Nothing is written\n");
echo "$all_string"."<br/>";
$tok = strtok($all_string, ",");
$sql = "SELECT * FROM Suggrammata";
/*line 22*/$results = mysqli_query($sql, $con);
/*line 24*/while($is = mysqli_fetch_array($results))
{
.
.
.
?>
Here are the warnings:
Warning:
mysqli_query() expects parameter 1 to be mysqli, string given in
/var/www/php_anazhthshs/euresh_suggrammatwn_aplh.php on line 22
Warning:
mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given
in/var/www/php_anazhthshs/euresh_suggrammatwn_aplh.php on line 24
Can you help? Thanks in advance!
Arguments must be inverted.
mysqli_query($con, $sql);
mysqli_query()

Any idea why my code keeps producing syntax 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 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

Categories