0

I know this question had been asked and answered by many, but I don't seem to be able to get this work on my side with the references I had found.

I understand that mysql is phasing out, but I just want to get this work. My idea is to update the selected row with the ID I get from the previous page. Error and code are shown below.

Error:

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\file\doAttendance.php on line 8 doAttendance.php:

<?php 
include "dbFunctions.php";

$id = $_REQUEST['id'];
$presence = 'Yes';

$selectQuery = mysql_query("SELECT * FROM guests WHERE id = '$id'");
$selected = mysql_query($selectQuery, $connect) or die(mysql_error($connect));

if (mysql_num_rows($selected) > 0) {   
} else {
    $sql = mysql_query ("UPDATE guests SET presence='$presence' WHERE id = '$id'");
    $updated = mysql_query($sql, $connect) or die(mysql_error($connect));
}
?>
Penelope
  • 35
  • 11

1 Answers1

1

i don't see the comment of @ThiagoUruray, if i see it before i make an answer, i will not. After i comment i re-check the warning of the question and i see @Paige, make a mistake using mysql_query double time.


Here is the solution: you miss use of mysql_query.

you have to pass the query string into the mysql_query not the resource. i just remove the mysql_query from the $selectQuery and $sql variable.

<?php 
include "dbFunctions.php";

$id = $_REQUEST['id'];
$presence = 'Yes';

$selectQuery = "SELECT * FROM guests WHERE id = '$id'";
$selected = mysql_query($selectQuery, $connect) or die(mysql_error($connect));
//check if any rows found then update the rows.
if (mysql_num_rows($selected) > 0) {
    $sql = "UPDATE guests SET presence='$presence' WHERE id = '$id'";
    $updated = mysql_query($sql, $connect) or die(mysql_error($connect));
}
?>

This is the only mistake you did in this code, so your result says:

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\file\doAttendance.php on line 8 doAttendance.php:

now it will be fine, let me know.

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42