PHP - Queuing For Remote Resource Control
I currently have two robots wirelessly controlled with a web-server and streaming webcam. Now I would like to create some form of queuing system so that only one user can have control over one robot at a time for a limited amount of time (~5 mins) before being kicked off. I would prefer that any waiting users would be presented with an estimate of their time remaining upon visiting the webpage. However, I am not sure how to go about doing this. Does anybody have any suggestions?
Similar TutorialsHey PHPFreaks. I made a php code, thats only needed to be showed for admin accounts only. I tryed to echo the mysql_num_rows($result); and it gave me this: Resource id #51 Heres a piece of my code where the problem is: $result = mysql_query("SELECT adminlevel FROM accounts WHERE name = '".$_SESSION['auth_username']."'") or die(mysql_error()); echo $result; echo mysql_num_rows($result); if(mysql_num_rows($result) == 1) { echo '<br /><br /><a href="home.php?admin">Admin Area</a>'; } Hope you can help I keep getting a resource #6 at the top of my script and not sure why. <?php if (isset($_REQUEST['option'])) { switch ($_REQUEST['option']) { case 0: ?> <h1 class="backstage">Biographies Management</h1><br /> <h2 class=backstage>Bio Types</h2><br /> <?php $query = "SELECT * FROM efed_list_styles AS styles"; $result = mysql_query ( $query ); $rows = mysql_num_rows($result); if ($rows > 0) { print'<table width="100%" class="table1"> <tr class="rowheading"> <td> </td> <td width="40" align="center">ID</td> <td>Name</td> </tr>'; $i = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $sClass = 'row2'; if ($i++ % 2) $sClass = 'row1'; printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('backstage_libs/biolayout.php?option=1&id=$row[id].', 'content'); return false;\">Edit</a></td>"; printf ( "<td align=\"center\" valign=\"top\" width=\"40\">%s</td>", $row ['id'] ); printf ( "<td valign=\"top\">%s</td>", $row ['name'] ); echo '</tr>'; } echo '</table><br>'; } else { echo '<span>There are no bio types.</span><br /><br />'; } returnmain(); footercode(); break; case 1: require_once('../backstageconfig.php'); require_once('../backstagefunctions.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM `efed_list_styles` WHERE `id` = '" . $id . "'"); $row = mysql_fetch_array($query); echo $query; ?> <h1 class="backstage">Bio Layouts Management</h1><br /> <h2 class="backstage"><?php echo $row['name']; ?> Biography Layout</h2><br /> <?php } } ?> Hello everyone, I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it? Here is the code that I am having trouble with Code: [Select] function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; } Hello everyone, I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it? Here is the code that I am having trouble with Code: [Select] function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; } I was expecting a return string, but got Resource id #2 instead. How do I have a string returned instead of that? heres my table user code Bob One Ted Two I dont get it Code: [Select] <html> <body> <?php $con = mysql_connect("localhost","user","PassWord"); if (!$con) { echo 'Could not connect to MySQL server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } $db = mysql_select_db("userdb") or die("Unable to select database"); if (!$db) { echo 'Could not select db. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } $query = "SELECT code from usertbl WHERE user = 'Ted' LIMIT 0 , 30"; $result = mysql_query($query, $con); if (!$result) { echo 'Could not query server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } echo $result; ?> </body> </html> When I use that query in phpmyadmin it works Any pointers much appreciated This works...
$result = mysql_query("SELECT * FROM login_attempts"); while($row = mysql_fetch_array($result)) { $diff = strtotime($row['login_date'])-time(); if ($diff > -300){ $count = $count + 1; } if ($count > 4) { $result = "locked"; } }This returns Resource ID 5... $result = mysql_query("SELECT * FROM login_attempts WHERE login_username='$username'"); while($row = mysql_fetch_array($result)) { $diff = strtotime($row['login_date'])-time(); if ($diff > -300){ $count = $count + 1; } if ($count > 4) { $result = "locked"; } }What's the problem? Many thanks, Hi, I was in the process of making thumnails for avatars It used to work before but now the files are being saved as resource ID and not in an image format. I can not point out what the issue is and also may I add when I try to echo nothing is happening. Code: [Select] $filename = $_FILES['myfile']['tmp_name']; if ($_POST['cpic']) { // Set a maximum height and width $width = 100; $height = 100; // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; $ratio_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location = "cid/$myid/$filename"; imagejpeg($image_p, $location, 100); $query =mysql_query ("UPDATE clp SET avatar ='$location' WHERE cid='1'"); header ("LOCATION: editprofile.php"); } I keep getting the mysql resource id #4 on a query that I am running and I have tried everything that I have read to fix it and nothing is working. I tried using the mysql_fetch_array, mysql_fetch_accoc, and the mysql_fetch_row functions I would appreciate any help that can be given to me. Here is my code as it stands now Code: [Select] <?php include('includes/config.php'); $last = $_GET['l_name']; $first = $_GET['f_name']; $sql = 'SELECT * FROM `ttmautos` WHERE `l_name` LIKE \'$last\' AND `f_name` LIKE \'$first\''; $autographs = mysql_query($sql, $connection)or die(mysql_error()); $row = mysql_fetch_array($autographs); echo $sql; echo $autographs; $l_name = $row['l_name']; $f_name = $row['f_name']; $sent = $row['date_sent']; $return = $row['date_return']; $address = $row['address']; $isent = $row['item_sent']; $ireturn = $row['item_return']; $project = $row['project']; $team = $row['team']; $address = stripslashes($address); ?> I'm trying to show my friend my website and it's not letting him or me view it. I am using my own IP-address. (dashed out for security, but it is correct) http://--.---.--.---/index-1.php When he and I type this into our browser, we can an error called "Resource Not Found". But, when I use localhost address, it works fine. http://localhost/index-1.php Does anyone know what is wrong? Do I need to open a specific port? USING XAMPP. Hi, I have the following code which I have been able to put together with alot of the brilliant help on this forum. When I run this code it just came up with a blank screen and the CSS however I added another error print "echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error() . '<br>';" and the result now is "fetchdata: Resource id #2". However, when search for this on Google many of the responses data back from between 2002-2006. Does it just mean that there is an error with the second if query or does Resource id #2 refer to a specific error? Im really puzzled why I cant find anything more modern to this error on Google. <?php if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters $id = (int) $_GET['id']; // cast value as an integer, and assign to $id $query = "SELECT * FROM productfeed WHERE id = $id"; if( !$fetchdata = mysql_query($query) ) { // numeric values shouldn't be quoted in query strings. echo "query: $query<br>Failed with error: " . mysql_error() . '<br>'; } else { while($row = mysql_fetch_array($fetchdata)) $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>"; echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error() . '<br>'; } } else { echo 'Product is not available. Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>'; exit(); } ?> How can I fix this error? Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given Code: [Select] function fetch_most_recent_fans($ctag) { $sql = "SELECT `company_fans`.`company_id`, `company_fans`.`user_id`, `company_fans`.`fan_date`, `companies`.`companytag`, `users`.`firstname`, `users`.`lastname`, `users`.`username` FROM `company_fans` LEFT JOIN `companies` ON `companies`.`companyid` = `company_fans`.`company_id` LEFT JOIN `users` ON `users`.`id` = `company_fans`.`user_id` WHERE `companies`.`companytag` = {ctag} ORDER BY `company_fans`.`fan_date` DESC LIMIT 10"; $query = mysql_query($sql); $return = array(); while (($row = mysql_fetch_assoc($query)) !== false) { $return[] = $row; } return $return; } I am currently trying create a sales system where it checks the user's username against the database to check whether they are in the list of buyers. The mysql query returns "Resource id #35", I need it to return the actual username (which I manually inserted into the database to test). PHP code that fetches from database: <?php $con = mysql_connect("x","x","x"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("x", $con); $check_buyer = "SELECT * FROM Buyers WHERE Buyer='x'"; $buyer = mysql_query($check_buyer); ?> Product page: <?php include("/home/x/public_html/scripts/buyer.php"); if ($user->data['user_id'] == ANONYMOUS) { echo 'To use ' . $product . 'you must be logged in!'; echo '<br /><a href="http://x/forum/ucp.php?mode=register">Register</a>'; echo ' or '; echo '<a href="http://x/forum/ucp.php?mode=login">Sign In</a>'; } elseif ($user->data['username_clean'] == $buyer) { echo "<h3>Welcome to x</h3>"; } else { echo "You need to buy this product to use it!"; echo $user->data['username_clean']; //test whether username is outputted correctly - which it did echo $buyer; //Fetched from mysql - returned "Resource id #35", not the desired username } ?> Any help would be great! Thanks, otester If $result contains the result of mysql_query, a select count distinct query, how do I access the count? I've tried $result[0] to no avail and $result only returns the resource #. Here is what is echoing the string "Resource id #1". However I do not know if it is the php or javascript that is outputting this. Can anyone tell me why this is showing and how to make it not show? PHP: Code: [Select] $directory = "Images/items/$product/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); $imgone = $images[0]; $gallery = '<tr><td valign="top" align="center">'; foreach($images as $image) { $tn = explode("/", $image); $tnname = $tn[3]; $gallery .= '<a href="#" rel="'.$image.'" class="image" alt="Images/items/'.$product.'/large/'.$tnname.'"><img src="Images/items/'.$product.'/thumbs/'.$tnname.'" class="thumb" border="1" style="margin-bottom:7px;"/></a> '; } if(is_dir("Images/items/".$product)) $gallery .= "</td></tr><tr><td width='300'>".$link."<div id='image' class='bigimg' align='left'>"; if(is_dir('Images/items/'.$product)) $gallery .= '<img src="'.$imgone.'" border="0"/></div></a></td></tr>'; JS (jQuery) Code: [Select] $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var large = $(this).attr("alt"); $('#image').hide(); $('#image').fadeIn('slow'); $('#image').html('<a href="' + large + '" ><img src="' + image + '"/></a>'); return false; }); }); I created this function to update my tour system. The query is working and is updating one row in the table, but I get a resource boolean error in the return section of the function. Any idea why? Code: [Select] function update_tour($uid, $step) { $step = (int)$step; $uid = (int)$uid; $sql = "UPDATE `users` SET `tour_step` = ${step} WHERE `id` = '${uid}'"; $q = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($q) === 1) ? mysql_result($q, 0): false; }
Hi Okay, I have a table with two columns..'annoyed' and 'ignored'. I poulated 'annoyed' with Bob and 'ignored' with Sally. I ran the following test due to problems I was having in my main script and I get the old MySQL "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/testing_ig.php on line 16 Here is the code: <?php $DBhost = "localhost"; $DBuser = "xxxxx"; $DBpass = "xxxxx"; $DBName = "xxxxx"; $table = "ignore"; mysql_connect($DBhost,$DBuser,$DBpass) or die(); @mysql_select_db("$DBName") or die(); $ignorequery = "SELECT * FROM $table WHERE annoyed='Bob' AND ignored='Sally'"; $checkignore = mysql_query($ignorequery); $ifignored = mysql_num_rows($checkignore); //<--- This is line 16 if ($ifignored >= 1) { echo "exists"; } else { echo "doesn't exist"; } ?> I must be really tired because I'm not seeing the problem...? I always use my queries like below mysql_query("SELECT id FROM someTable", $cn); but some times i see in my error_log says: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. Why is this happening? I mean, there is no problem with my sites and all they are working as they should be but why php generates this error? Hi guys, I have this problem and id appreciate all your advice in helping solve it. I'm working on a service with is "cloud" hosted. However I want it so when a person employed by Corporation A logs onto myservice.corporationa.com they enter their Corporation A LDAP details but somehow that sends them to myservice.com and authenticates them. I know how to do the get LDAP details part to put on myservice.corporationa.com but no idea how to do the rest and make it send back etc. Any ideas? Many many thanks in advance. (PS - If this all makes sense please do let me know) Hey people! I'm currently working on an free API that i will be sharing with the web community in the next few months and had a question that much of this project hinges upon: Is there a way to allow a remote include of one php file from my server? Case: I am allowing 2 ways for users to access the APi: 1. Using AJAX or cURL accessing a REST method over POST or GET (This part is already functional) 2. Allowing an include of the API Library I'm not sure if it will be completely opensource yet, only free, this is why I don't want to simply provide the source files to users. Example of what I would like to do: <?php include('http://mysite.com/myAPI/classLib.php'); ?> Anybody have a solution for that?? Thanks in advance, E |