Copy link to clipboard
Copied
I want to display records from a table to show only those with one of 3 values in one field. I'm enclosing the offending code.
$Cycle=$_GET['CycleYear'];
$SQL_rs1 = "SELECT * FROM RCL_selections WHERE RCL_selections.r_Cycle_Year = $Cycle ORDER BY RCL_selections.r_date ASC, RCL_selections.r_seq ASC";
$rs1 = $sainttim->query($SQL_rs1);
$error = $rs1->errorInfo();
if (isset($error[2])) die($error[2]);
$totalRows_rs1 = $rs1->rowCount();
$Cycle contains the desired value. But I get an error at line $error = because $rs1 is not an object, so obviously the query failed. I've tried substituting ? for $Cycle in the. SQL, but then cannot work out how to phrase the query action. I've tried every combination I can think of. Did a prepare, bound variables, used execute, etc. But I need to a return an array of records.
Any help will be appreciated.!
Thanks,
Gail
Have you tried wrapping the $Cycle variable in the SELECT query in quotes:
'$Cycle'
Copy link to clipboard
Copied
Why do you need these 2 lines of code anyway?
$error = $rs1->errorInfo();
if (isset($error[2])) die($error[2]);
Surely the below will do the job assuming $sainttim is your connection variable:
$Cycle=$_GET['CycleYear'];
$SQL_rs1 = "SELECT * FROM RCL_selections WHERE RCL_selections.r_Cycle_Year = $Cycle ORDER BY RCL_selections.r_date ASC, RCL_selections.r_seq ASC";
$rs1 = $sainttim->query($SQL_rs1);
$totalRows_rs1 = $rs1->rowCount();
But I would use some kind of sanitization as you're getting $Cycle from a url parameter?
Try that to see if at least you can get some information returned and then go back to the error handing if you really require it.
Copy link to clipboard
Copied
But my problem is that the query aas defined is not working! I removed the 2 lines of code as you suggested, and then get the following:
Fatal error: Uncaught Error: Call to a member function rowCount() on bool in /home1/sainttim/public_html/DisplayRCL.php:37 Stack trace: #0 {main} thrown in /home1/sainttim/public_html/DisplayRCL.php on line 37
Before removing the 2 lines, the error was on the call to $error - $rs1->errorInfo(). The problem is in the query. Apparently using the variable $Cycle is not working. I know the value and it is correct.
Thanks for the response.
Copy link to clipboard
Copied
Have you tried wrapping the $Cycle variable in the SELECT query in quotes:
'$Cycle'
Copy link to clipboard
Copied
That did it! Thank you!!!