SQL/PHP help requested

dancingmongoose

International Coach
Joined
Dec 15, 2009
Online Cricket Games Owned
  1. Don Bradman Cricket 14 - Steam PC
Not sure if this is the right forum or if there are the right people looking here but I'd very much appreciate some help. Whenever I go onto a proper site for this kinda thing I just get people who tell me how much better they are and fail to address the issue properly.

I have a cricket database, and I'm attempting to get a dynamic records page similar to FTP have, though much more in depth. I can't see anything glaringly obviously wrong but I get the following error no matter what I try:
Warning: Invalid argument supplied for foreach() on line 40

index file (where all the backend stuff is): https://www.dropbox.com/s/ut9lahx48491d7q/index.php
form file (where all the frontend stuff is): https://www.dropbox.com/s/bge1n5o0qpsqkj8/form.html.php

Thanks
 
In your form file, on line 40, you're using this code:
PHP:
<?php foreach($record as $row):?>
However, I couldn't find an initialization of $record. This means, you're trying to iterate through an empty variable, hence it is giving you an error.

----------

Edit: Ignore that. I'm barking down a wrong tree.. :p

----------

I require a little heads up, you're using the form file, and it is going to the index file, and that's where you're getting the error?
 
Yeah, the form runs the first half of the index file when you click search. I'll add some comments to make it clearer
 
Have you tried moving the foreach block above or below the others to check if the error follows it?

PHP:
try
    { 
      $result = $pdo->query('SELECT id, name FROM cricket_teams WHERE id>0'); 
    } 
    catch (PDOException $e) 
    { 
      $error = 'Error fetching teams from database!'; 
      include 'form.html.php'; 
      exit(); 
    } 
      
    foreach ($result as $row) 
    { 
      $teams[] = array('id' => $row['id'], 'name' => $row['name']); 
    }

It seems this block is causing you the error, but you need to make sure.
 
No it's not that, it was the block that started with
Code:
<?php if($_GET['record'] == 'hs'){ ... ?>

Thanks for your help but I've decided to start again and very slowly putting it back together. I'll be back if it gets worse
 
Have you checked running the exact same query in mysql directly?
The error that is coming up, indicates that the foreach is being made to iterate an empty variable.

----------

PHP:
   $s = $pdo->prepare($sql);
    $s->execute($placeholders);
Are you running the query? I'm not too aware how pdo works, but looking at the code above and below, I think you might have missed out on
$s=$pdo->query("...
 
Don't worry about it anymore, I started it over and it works perfectly
 

Users who are viewing this thread

Top