I am trying to update a table based on the input provided by a user. There are ten fields which a user can choose to input information into. The table I am trying to input too has a following structure.
leagueTrackID | leagueID | trackID
1 1 1
2 1 2
3 1 12
...
15 1 4
I need the code to update the fields where a new track has been added via looping though each inputted track and place it in a new field which has the matching criteria. The criteria which it needs to be match too is the leagueID. How can this be achieved without overwriting the same column row?
The code below is what I have so far but I have an error with trying to assign the php track variables to either a php array or php list.
$data = mysql_query("SELECT COUNT(leagueID) AS totalTracks , min(leagueTrackID) AS minLeagueID , max(leagueTrackID) AS maxLeagueID , leagueID , trackID
FROM leagueTracks
WHERE leagueID = '$vaildLeagueID'");
$info = mysql_fetch_array( $data );
// get posted track id and assign them to the php track varaibles
if ( $_POST['track1'] == '' ) { $track1 = $info['track1']; } else { $track1 = $_POST['track1']; }
if ( $_POST['track2'] == '' ) { $track2 = $info['track2']; } else { $track2 = $_POST['track2']; }
if ( $_POST['track3'] == '' ) { $track3 = $info['track3']; } else { $track3 = $_POST['track3']; }
if ( $_POST['track4'] == '' ) { $track4 = $info['track4']; } else { $track4 = $_POST['track4']; }
if ( $_POST['track5'] == '' ) { $track5 = $info['track5']; } else { $track5 = $_POST['track5']; }
if ( $_POST['track6'] == '' ) { $track6 = $info['track6']; } else { $track6 = $_POST['track6']; }
if ( $_POST['track7'] == '' ) { $track7 = $info['track7']; } else { $track7 = $_POST['track7']; }
if ( $_POST['track8'] == '' ) { $track8 = $info['track8']; } else { $track8 = $_POST['track8']; }
if ( $_POST['track9'] == '' ) { $track9 = $info['track9']; } else { $track9 = $_POST['track9']; }
if ( $_POST['track10'] == '' ) { $track10 = $info['track10']; } else { $track10 = $_POST['track10']; }
// Assign tracks selected to an array
$tracksArray = array($track1 , '$track2' , '$track3', '$track4', '$track5' , '$track6' ,'$track7', '$track8' , '$track9' , '$tack10');
// Counter
$trackNumber = '1';
// Get the lowest leagueTrackID based on the leagueID being updated
$min = $info['minleagueID'];
// Get the highest leagueTrackID based on the leagueID being updated
$max = $info['maxLeagueID'];
while($min != $max) {
$updateLeagueTracks = mysql_query ("UPDATE userLeague SET trackID = $trackArray['$tracknumber'] WHERE leagueID = '$vaildLeagueID'");
$addTracks = mysql_query($updateLeagueTracks);
$trackNumber++;
$min++;
} // closes the for loop
Related
Question
I have to award my members with some bonuses on completion of certain tasks.If they have achieved task1, new the task will be task2
If they have achieved task2, new the task will be task3
If they have achieved task3, new the task will be task4
If they have achieved task4, new the task will be task5
Database
while($row = mysql_fetch_array($sql))
{
$offername[] = $row['name'];
$offertask1[] = $row['task1'];
$offertask2[] = $row['task2'];
$offertask3[] = $row['task3'];
$offertask4[] = $row['task4'];
$offertask5[] = $row['task5'];
$offerprize[] = $row['prize'];
$offercurrent[] = $row['current'];
$offerpercent[] = $row['percent'];
$offertask[] = $row['task'];
}
Values:
$offername[] = (offer1, offer2, offer3 ,offerXX)
$offertask1[] = (100,150,200 ,taskxx)
$offertask2[] = (100,150,200 ,taskxx)
$offertask3[] = (100,150,200 ,taskxx)
$offertask4[] = (100,150,200 ,taskxx)
$offertask5[] = (100,150,200 ,taskxx)
$offerprize[] = (5000,2222,3333 ,taskxx)
$offertask= this will replace it value with $offertask1[]
,$offertask2[] to $offertask5[] , depending upon the condition
My Code
for ($i=0;$i<=count($offername);$i++) {
// Check for existing bonuses first. // Code omitted
//#### If it's the first bonus ########
if ($member['count'] == 0 ) {
if ($offerprize[$i] != 0) {
$offertask = array_replace($offertask, $offertask1);
$per = $offercurrent[$i]/$offertask[$i] * 100;
$offerpercent[$i] == round($per);
}
}
//### If he has claimed one bonus and this is the second bonus #####
if ($member['count'] == 1 ) {
if ($offercurrent[$i] >= $offertask1[$i] AND $offercurrent[$i] < $offertask2[$i]) {
if ($offerprize[$i] != 0) {
$offertask = array_replace($offertask, $offertask2);
$per = $offercurrent[$i]/$offertask[$i] * 100;
$offerpercent[$i] == round($per);
}
}
}
}
I have already claimed the first bonus for offer1 == offername[0]. I have tested for $offercurrent[0]. It does not work for ($member['count'] == 1) and so on.
Problem
All the values remain same for ($member['count'] == 0 ) and do not change with the count.
I am using WAMP v.2.5 on a Windows10 machine. My project is a PHP project running off a MySQL DB. It includes numerous AJAX calls, which work fine. I have one specific call however which is giving me a 'Unexpected end of input' error.
The call is made from a View, is directed to a global ajax handler PHP script which forwards the request to the Controller, which then asks the Model for the response. The appropriate Model method is being fired. The method contains error checking and will throw exceptions for an empty result. The DB Query within is valid, and returns results when used in the console. 9 times out of 10 however, the ajax fn will complete without receiving / reading the result of the query and thus generates the above error. Sometimes it will work fine.
When placed on a live server, everything works as it should. It's almost as if the script was running too quickly on the local machine to wait for the DB response or for any exception to be thrown.
Can anyone tell me how to properly test what's happening, or have a solution to the above problem?
EDIT:
Trail of affected code:
$(document).ready(function()
{
//some code
updateFilteredScheduleList();
//some code
});
function updateFilteredScheduleList()
{
var opts = $.extend(true, {}, dialogOptions);
getFilteredScheduleResults()
.done(function(returnedData)
{
var returnedDataObj = parseAjaxJSONResponse(returnedData);
if(returnedDataObj.hasOwnProperty('success'))
buildScheduleList(returnedDataObj.response);
})
.error(function(xhr, options, error)
{
opts.message = error;
displayDialog(opts);
return false;
});
}
function getFilteredScheduleResults()
{
var values = getFilterValues();
values.controller = 'WSVisits';
values.method = 'getFilteredScheduleResults';
console.log(values);
return $.ajax({
type: 'post',
cache: false,
data: values,
url: controllersAjaxPath
});
}
function getFilterValues()
{
var values = {};
//get values of view filters
return values;
}
function parseAjaxJSONResponse(data)
{
var opts = $.extend(true, {}, dialogOptions);
try
{
var tmp = JSON.parse(data);
if(tmp.hasOwnProperty('error'))
{
opts.message = tmp.error;
displayDialog(opts);
return false;
}
return tmp;
}
catch(e)
{
opts.message = e.message;
displayDialog(opts);
return false;
}
}
PHP method (slightly edited):
function getFilteredScheduleResults($args = null)
{
$id = intval($args['MyID']);
$region_id = (!$id) ? ( intval($args['RegionID']) > 0) ? intval($args['RegionID']) : 0 : 0;
$county_id = (!$id) ? ( intval($args['CountyID']) > 0) ? intval($args['CountyID']) : 0 : 0;
$language_id = (!$id) ? ( intval($args['LanguageID']) > 0) ? intval($args['LanguageID']) : 0 : 0;
$center_id = (!$id) ? ( intval($args['CenterID']) > 0) ? intval($args['CenterID']) : 0 : 0;
$type_id = (!$id) ? ( intval($args['TypeID']) > 0) ? intval($args['TypeID']) : 0 : 0;
$support_type_id = (!$id) ? ( intval($args['SupportTypeID']) > 0) ? intval($args['SupportTypeID']) : 0 : 0;
$address_token = (!$id) ? ( trim($args['AddressContains']) !== '') ? trim($args['AddressContains']) : null : null;
$purpose_id = (intval($args['PurposeID']) > 0) ? intval($args['PurposeID']) : 0;
$associate_id = (intval($args['AssociateID']) > 0) ? intval($args['AssociateID']) : 0;
if(!empty($args['From']))
{
$from_obj = DateTime::createFromFormat('d/m/Y', $args['From']);
$args['From'] = (!$from_obj) ? null : $from_obj->format('Y-m-d');
}
if(!empty($args['To']))
{
$to_obj = DateTime::createFromFormat('d/m/Y', $args['To']);
$args['To'] = (!$to_obj) ? null : $to_obj->format('Y-m-d');
}
$sql = " /*query*/ WHERE 1 ";
if($id)
$sql.= " AND ( s.MyID = :MyID ) ";
else
{
if($region_id)
$sql.= " AND ( RegionID = :RegionID ) ";
if($county_id)
$sql.= " AND ( CountyID = :CountyID ) ";
if($language_id)
$sql.= " AND ( LanguageID = :LanguageID ) ";
if($center_id)
$sql.= " AND ( CenterID = :CenterID ) ";
if($type_id)
$sql.= " AND ( s.TypeID = :TypeID ) ";
if($support_type_id)
$sql.= " AND ( SupportTypeID = :SupportTypeID ) ";";
if(!is_null($address_token))
$sql.= " AND ( UPPER(CONCAT_WS(' ', Add1, Add2, Add3, CityTown)) LIKE UPPER(:AddressToken) ) ";
}
$sql.= " GROUP BY s.MyID ORDER BY MyName ASC ";
$db = new Database();
try
{
$db->query($sql);
if($id)
$db->bind(':MyID', $id);
else
{
if($region_id)
$db->bind(':RegionID', $region_id);
if($county_id)
$db->bind(':CountyID', $county_id);
if($language_id)
$db->bind(':LanguageID', $language_id);
if($center_id)
$db->bind(':CenterID', $center_id);
if($type_id)
$db->bind(':TypeID', $type_id);
if($support_type_id)
$db->bind(':SupportTypeID', $support_type_id);
if(!is_null($address_token))
$db->bind(':AddressToken', '%' . $address_token . '%');
}
$db->execute();
$tmp = $db->fetchAllAssoc();
$get_assignments_only = (!empty($args['AssignmentsOnly']));
$returned = [];
$sql = " SELECT VisitID FROM visits_ws WHERE MyID = :MyID ";
if($purpose_id)
$sql.= " AND ( VisitPurposeID = :Purpose ) ";
if($associate_id)
$sql.= " AND ( ( Associate1ID = :AssociateID ) OR ( Associate2ID = :AssociateID ) OR ( Associate3ID = :AssociateID ) OR ( Associate4ID = :AssociateID ) ) ";
if(!empty($args['From']))
$sql.= " AND ( VisitDate >= :From ) ";
if(!empty($args['To']))
$sql.= " AND ( VisitDate <= :To ) ";
$db->query($sql);
foreach($tmp as $i => $t)
{
$db->bind(':MyID', $t['MyID']);
if($purpose_id)
$db->bind(':Purpose', $purpose_id);
if($associate_id)
$db->bind(':AssociateID', $associate_id);
if(!empty($args['From']))
$db->bind(':From', $args['From']);
if(!empty($args['To']))
$db->bind(':To', $args['To']);
$db->execute();
$visits = $db->fetchAllAssoc();
if( ($get_assignments_only) && (empty($visits)) )
continue;
if( ( ($purpose_id) || ($associate_id) || (!empty($args['From'])) || (!empty($args['To'])) ) && (empty($visits)) )
continue;
$tmp[$i]['HasVisits'] = (empty($visits)) ? 0 : 1;
$tmp = $schools[$i];
unset($tmp['Name']);
$schools[$i]['Address'] = build_address($tmp);
unset($schools[$i]['Add1']);
unset($schools[$i]['Add2']);
unset($schools[$i]['Add3']);
unset($schools[$i]['CityTown']);
unset($schools[$i]['CityPostCode']);
unset($schools[$i]['Name']);
unset($schools[$i]['LanguageID']);
unset($schools[$i]['PrincipalID']);
unset($schools[$i]['ContactID']);
unset($schools[$i]['TypeID']);
unset($schools[$i]['CenterID']);
unset($schools[$i]['SupportTypeID']);
unset($schools[$i]['CountyID']);
unset($schools[$i]['AreaCodeID']);
unset($schools[$i]['NetworkCodeID']);
unset($schools[$i]['RegionID']);
$returned[] = $tmp[$i];
}
return ['jct_success'=>'ok', 'response'=>$returned];
}
catch(PDOException $e)
{
return ['jct_error'=>$e->getMessage()];
}
}
Found the culprit:
I had to update my Apache max_input_vars to a higher limit to allow the number of individual parameters being returned to actually be returned. Post size was not the issue.
I'm developping a php application which is used to process IP adresses. Thus, I'm juggling with mysql tables containing up to 4 billion rows.
I have a script that currently needs to fetch 65536 adresses from this table and the mysql query fails to give a response via PHP or even via phpMyAdmin when I try to extract these 65K lines.
The table containing the IP Adresses has 3 indexes ( 1 unique, 2 primary ) which are supposed to help it go faster but I simply cannot get past having mysql give an associative array back to PHP in order to continue my data processing.
Any tips as to how to circumvent this problem ?
Thx in advance !
$request = new Request(DB_NAME);
$request->select = '*';
$request->from = Etherwan_Adressage_Ip::TABLE_NAME;
$request->where = Etherwan_Adressage_Ip_Ressource::PRIMARY_KEY." = '".$options->Ressource_ID."'";
$request->order = " inet_aton(IP) ";
$Compteur = 0;
$Liste = array();
$result = $request->exec('select');
for ($i=0 ; $i<$result['length'] ; $i+=$CIDR->Adresses_Totales){
$Possible = TRUE;
$Selected = FALSE;
for ($j=$i ; $j<$i+$CIDR->Adresses_Totales ; $j++){
if ($result[$j]['Date_Affectation'] != '0000-00-00 00:00:00'){
if (isset($options->Include)){
if ($options->Include->Type != $result[$j]['Type_Liaison'] || $options->Include->Liaison_ID != $result[$j]['Liaison_ID'] || str_replace('/', '', $options->CIDR) != $result[$j]['Bits']){
$Possible = FALSE;
} else {
$Selected = TRUE;
}
} else {
$Possible = FALSE;
}
break;
}
}
if ($Possible){
$Liste[$Compteur]['text'] = $result[$i]['IP'] . " / " . $result[$i+$CIDR->Adresses_Totales-1]['IP'];
$Liste[$Compteur]['value'] = $result[$i]['Ressource_ID'];
$Liste[$Compteur]['selected'] = $Selected;
$Liste_IP = array();
for ($j=$i ; $j<$i+$CIDR->Adresses_Totales ; $j++){
if ($result[$j]['Nom'] != ''){
$result[$j]['Dispo'] = 0;
} else {
$result[$j]['Dispo'] = 1;
}
$Liste_IP[] = $result[$j];
}
$Liste[$Compteur]['Liste_IP'] = $Liste_IP;
$Compteur++;
}
}
$Liste['maxLength'] = $Liste['length'] = $Compteur;
return $Liste;
Link to table indexes ( JPG )
Link to data sample ( JPG )
I'm creating a page where you can save your predictions for soccermatches.
Every week there are 9 matches and a user can post his prediction for a match via a form.
The result of this form will result in the following array:
Array
(
[week] => 12
[game_id_1] => 28
[game_1_home] => 2
[game_1_away] => 2
[game_id_2] => 29
[game_2_home] => 2
[game_2_away] => 1
[game_id_3] => 31
[game_3_home] => 4
[game_3_away] => 0
[game_id_4] => 30
[game_4_home] => 2
[game_4_away] => 0
[game_id_5] => 32
[game_5_home] => 0
[game_5_away] => 2
[game_id_6] => 33
[game_6_home] => 1
[game_6_away] => 0
[game_id_7] => 35
[game_7_home] => 1
[game_7_away] => 1
[game_id_8] => 34
[game_8_home] => 2
[game_8_away] => 4
[game_id_9] => 36
[game_9_home] => 3
[game_9_away] => 0
)
I already wrote a validation part for the first match but instead of copying this 8 times I think this can go much easier.
Anyone an idea how to do this and please give me advice if I can improve this piece of code.
$blnOK = true;
$strResult = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (isset($_POST['game_id_1']) && !empty($_POST['game_1_home']) && !empty($_POST['game_1_away']))
//check if the posts are not empty, then put in variables
{
$strGame_id_1 = $_POST['game_id_1'];
$strGame_1_home = $_POST['game_1_home'];
$strGame_1_away = $_POST['game_1_away'];
//Check if strings are numeric
if ((ctype_digit($strGame_1_home)) && (ctype_digit($strGame_1_away)))
{
//Check if prediction already exists in database for user
$strQueryPrediction = "SELECT count(id) amount FROM prediction where player_id = 1 and game_id = $strGame_id_1";
$resultQueryPrediction = mysql_query ($strQueryPrediction);
$intPredictionKnown = mysql_result($resultQueryPrediction, 0);
if ($intPredictionKnown == 0)
{
//NOT KNOWN so INSERT
$blnOK = executeQuery("INSERT INTO prediction (player_id, game_id, predict_home, predict_away) VALUES (1, $strGame_id_1, $strGame_1_home, $strGame_1_away)", $strErrorText, $db);
echo "Your prediction is saved";
}
else
{
//KNOWN so UPDATE
$blnOK = executeQuery("UPDATE prediction SET predict_home = $strGame_1_home, predict_away = $strGame_1_away WHERE player_id = 1 AND game_id = $strGame_id_1", $strErrorText, $db);
echo "Your prediction is updated";
}
}
else
{
$strResult = "Too bad, your prediction could not saved.";
$blnOK = false;
}
}
else
{
echo "Input is empty";
}
}
You could, and arguably should, use a loop to save you copying the code a number of times. You say there are 9 games, so you can do the following :
$blnOK = true;
$strResult = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
for ($i = 1; $i <= 9; $i++)
{
if (isset($_POST['game_id_' . $i]) && !empty($_POST['game_' . $i . '_home']) && !empty($_POST['game_' . $i . '_away']))
//check if the posts are not empty, then put in variables
{
$strGame_id = $_POST['game_id_' . $i];
$strGame_home = $_POST['game_' . $i . '_home'];
$strGame_away = $_POST['game_' . $i . '_away'];
//Check if strings are numeric
if ((ctype_digit($strGame_' . $i . '_home)) && (ctype_digit($strGame_' . $i . '_away)))
{
//Check if prediction already exists in database for user
$strQueryPrediction = "SELECT count(id) amount FROM prediction where player_id = 1 and game_id = $strGame_id";
$resultQueryPrediction = mysql_query ($strQueryPrediction);
$intPredictionKnown = mysql_result($resultQueryPrediction, 0);
if ($intPredictionKnown == 0)
{
//NOT KNOWN so INSERT
$blnOK = executeQuery("INSERT INTO prediction (player_id, game_id, predict_home, predict_away) VALUES (1, $strGame_id, $strGame_home, $strGame_away)", $strErrorText, $db);
echo "Your prediction is saved";
}
else
{
//KNOWN so UPDATE
$blnOK = executeQuery("UPDATE prediction SET predict_home = $strGame_home, predict_away = $strGame_away WHERE player_id = 1 AND game_id = $strGame_id", $strErrorText, $db);
echo "Your prediction is updated";
}
}
else
{
$strResult = "Too bad, your prediction could not saved.";
$blnOK = false;
}
}
else
{
echo "Input is empty";
}
}
}
Whenever you have to do something multiple times, think of using a loop if possible, or creating a function which you can call multiple times.
I recently migrated a PHP site to my server and after migration I receive this error message. As I'm not really familiar with PHP, I'd really appreciate any help. Thanks.
Warning: strpos() expects parameter 1 to be string, resource given in
.../public_html/store /product_list.php on line 121
Line 121 is as follows...
$exists = (strpos($handle, "Resource id") !== false) ? true : false;
Here is the rest of the code on the top of the page for relevance.
<?php session_start();
include_once("../includes/define.inc.php");
include("../includes/common.php");
include("../includes/mysql_functions.php");
if( isset( $_GET['category'] ) )
{
$exists = checkIfExists("aw_category", "aw_category_urlalias='". $_GET['category']."'", "aw_category_id");
if( !$exists )
{
header("Location: " . PRODUCT_LIST );
}
}
$get_category = ( isset( $_GET['category'] ) ) ? $_GET['category'] : "";
$category_id = ( $get_category == "" ) ? "" : getCategoryIDByAlias( $get_category );
$get_page = (isset($_GET['page']) ) ? $_GET['page'] : 0;
/*category menu*/
$qry_cat = "SELECT aw_category_urlalias, aw_category_id,aw_category_name,aw_category_order,aw_category_status FROM aw_category WHERE aw_category_status = 1 ORDER BY aw_category_order asc";
$result_cat = Query($qry_cat);
/*product*/
$qry_pro = "SELECT *
FROM aw_product
INNER JOIN aw_category
ON aw_product.aw_product_category = aw_category.aw_category_id
INNER JOIN aw_image
ON aw_product.aw_product_id = aw_image.aw_img_prodid
WHERE aw_product.aw_product_status = 1";
if( $category_id == "" )
{ //Feature Product
$qry_pro .= " AND aw_product.aw_product_category = 1";
} else {
$qry_pro .= " AND aw_product.aw_product_category = ".$category_id."";
}
$qry_pro .= " GROUP BY aw_product.aw_product_id
ORDER BY aw_product.aw_product_priority desc,aw_product.aw_product_date desc";
if( $get_category=="" )
{ //Feature Product
$qry_pro .= " LIMIT 6";
}
$result_pro = Query( $qry_pro );
//$row_pro = mysql_fetch_array($result_pro);
$result_pro2 = Query( $qry_pro );
if( !$get_category == "" )
{
/*Pagination*/
$num_per_page= 12;
$num_rows = mysql_num_rows($result_pro);
$num_pages = ceil($num_rows/$num_per_page);
$nav = "";
$begin = $get_page * $num_per_page;
$qry_pro .= " LIMIT " . $begin . ",12";
$result_pro = Query( $qry_pro );
$row_pro = mysql_fetch_array($result_pro);
if( $get_page > 0 )
{
$nav ="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".( $get_page-1 )."\">« Previous</a> | ";
}
for($p=0;$p<$num_pages;$p++)
{
if($get_page == $p)
$nav .="<a class=\"page_a\" style='text-decoration:underline' href=\"".PRODUCT_LIST."?category=".$get_category."&page=".$p."\">".($p+1)."</a> | ";
else
$nav .="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".$p."\">".($p+1)."</a> | ";
}
if($get_page<$num_pages-1)
{
$nav .="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".($get_page+1)."\"> Next »</a>";
}
}//-------
/*news*/
$qry_news = "SELECT aw_news_title FROM aw_news ORDER BY aw_news_date desc LIMIT 8";
$result_news = Query($qry_news);
function getCategoryIDByAlias( $alias )
{
$query = "SELECT aw_category_id FROM aw_category WHERE aw_category_urlalias='".$alias."'";
$rs = Query( $query );
$row = mysql_fetch_array( $rs );
return $row['aw_category_id'];
}
function checkIfThumbExists( $thumb )
{
//$exists = ( file_exists( $img_src_thumb ) ) ? true : false;
//echo $exists;
//$exists = ( is_file( $img_src_thumb ) ) ? true : false;
//echo $exists;
//$AgetHeaders = #get_headers( $img_src_thumb );
//$exists = ( preg_match( "|200|", $AgetHeaders[0] ) ) ? true : false;
//echo $exists;
//$header_response = get_headers($img_src_thumb, 1);
//$exists = ( strpos( $header_response[0], "404" ) !== false ) ? false : true;;
//echo $exists;
$handle = #fopen($thumb, 'r');
$exists = (strpos($handle, "Resource id") !== false) ? true : false;
if( $exists )
{
$size = getimagesize( $thumb );
if( $size[3] == 'width="214" height="214"')
{
$exists = true;
} else {
$exists = false;
}
}
return $exists;
}
?>
Try replacing line 121 with the following:
$handle = #file_get_contents($thumb);
$handle = #fopen($thumb, 'r');
$handle not is string
The error is clear. Read manual of stropos()
It need to take a string in parameter, but in you case you set there one source($handle = #fopen($thumb, 'r');) and one string("Resource id")
Use file_get_contents, as example.
fopen returns a resource and strpos expects the first parameter to be a string.
You may use file_get_contents instead, but are you sure you want to check the binary data of a image?
$data = file_get_contents($thumb);
I don't know what are you trying to do with this line, but if you want to weather the file exists or not, i recommend you to use the native PHP functión file_exists, that gives you the chance to check if the file exists or not:
$exists = file_exists($thumb)
Here is PHP reference.
http://es1.php.net/manual/es/function.file-exists.php
As mentioned in other answers you are giving strpos a file handle or 'resource', which is wrong.
However, it looks like you want to test is if the file exists so I would simply do:
$handle = #fopen($thumb, 'r');
if($handle)
{
// File exists
}
else
{
// File doesn't exist
}
As fopen() will return a pointer (resource) if the file can be opened, else false if not.
file_get_contents() looks like the wrong option as it appears you are trying to open and image, so why would you want to search the binary for a string.