Okay, I'm actually going mad, now.
Can someone tell me why MySQL is returning a resource even though it can't find an entry in my table? I don't even know what sort of information is required.
The idea is that I have a table called 'exclusions' not yet filled. You will go to a screen and select the checkboxes next to the gigs (1 per row) on the gigs table that you would like an exclusion entered for.
The exclusions table just has the 'id' (which will be the gig id) and six flags. I'm trying to set the first one.
Exclusions.php
<?php
// include function files for this application
require_once('listings_fns.php');
ini_set("session.save_handler", "files");
session_start();
$toggle_me = $_POST['toggle_me'];
do_site_header('Toggle Exclusions');
check_valid_user();
$conn = db_connect();
if (!$conn)
return 'Could not connect to database server - please try later.';
echo (count($toggle_me))."\n";
if (count($toggle_me)>0) {
foreach($toggle_me as $tempid) {
$linkRes = mysql_query("select * from exclusions where id=".$tempid);
echo $linkRes."\n";
if ($linkRes) {
$linkResRow = mysql_fetch_array($linkRes);
if ($linkResRow['isd'] == 1) $exclude = 0;
else $exclude = 1;
$query = "update exclusions set isd=".$exclude." where id='".$tempid."'";
}
else {
$query = "insert into exclusions values
(".$tempid.", 1, 0, 0, 0, 0, 0)";
}
echo $query."\n";
$result = mysql_query($query);
if (!$result) {
echo 'ERROR!';
exit;
}
}
}
exclusions();
do_html_footer();
?>
After this is run it runs the function to display the exclusions.
You can see I've got my debugging info in there. The thing is exclusions is empty right now. I don't want it to be filled unless there's an exclusion otherwise it's a waste.
But when I try to add an exclusion that doesn't already exist:
Count: 1
Result from SQL query to check if record exists: Resource id #9
Runs this $query: update exclusions set isd=1 where id='20'
No record exists, yet I get no error coming back.
I can't understand why this isn't working. Can someone enlighten me? It's surely completely arse?
Cheers
Theo