HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
Running PHP script in Authenticated session
HuggieBear replied to mceldon's topic in PHP Coding Help
Take a look at the [url=http://uk.php.net/manual/en/ref.curl.php]CURL[/url] library Regards Huggie -
GET variable coming up empty when inserting integers
HuggieBear replied to jumpenjuhosaphat's topic in PHP Coding Help
[quote author=Cep link=topic=123969.msg513089#msg513089 date=1169722662] [quote author=jumpenjuhosaphat link=topic=123969.msg513084#msg513084 date=1169722081] No, I'm using the get method. It needs to be the get method so that the pages can be bookmarked. If I use the post method, it'll hide the underlying variables and the page won't be markable.[/quote] I'm a little lost by this but if you say so. [/quote] Cep, Your understanding of HTML forms is slightly off the mark. When you submit a form, you can use either the POST or the GET method. The OP clearly has GET in his/her form method and so the parameters will be passed in the URL. Regards Huggie -
[quote author=jagguy link=topic=123965.msg513090#msg513090 date=1169722904] You wouldn't run the file on its own as it expects a value and returns a value. [/quote] I'm fully aware of that, but by adding the line I suggested and running the code again, you'll be doing some debugging. Identifying if the value that actually gets passed to the php script from Flash is actually what you expect. Regards Huggie
-
OK, my advice would be to a) separate the parts of the if statement for readability, b) change the short <? tags for <?php and c) check that your variable names are consistent, as identified by Tyche. [code]<?php if(($user['wilderness'] == 1) && ($ir['posX'] == $users['posX']) && ($ir['posY'] == $users['posY'])){ echo $user['username']; } ?>[/code] Also, check the case sensitivity. If all this fails then we may need a little bit more of the code. Regards Huggie
-
OK, my advice would be to add this line to the top of your script, just below include("dbconnect.php"); [code=php:0]echo $_GET['alName'];[/code] Does it output the value you're expecting? Huggie
-
Do a search on these forums and google, for the term CAPTCHA. Regards Huggie
-
If you echo each of the variables before hand, do they show the correct data? That should be the first thing you do, if they aren't then it's likely to be variable assignment at fault, if they are then it's the if statement. Regards Huggie
-
You should read up about [url=http://uk.php.net/manual/en/ref.errorfunc.php]error reporting[/url] within php. Also the [url=http://uk.php.net/manual/en/function.error-reporting.php]error_reporting()[/url] function Regards Huggie
-
[quote author=chriscloyd link=topic=123806.msg513032#msg513032 date=1169718183] $_SESSION['member'] or $_SESSION['nonmember'] [/quote] Chris, This is a good point, I had assumed that as the OP had only posted a snippet of code that they had already assigned the session variables to $member or $nonmember. Huggie
-
(help) retrieving database information to print image on page
HuggieBear replied to ra2833's topic in PHP Coding Help
Maybe you need to use something like [url=http://uk.php.net/manual/en/function.imagecreatefromstring.php]imagecreatefromstring()[/url] Regards Huggie -
Strange chronological order array sorting problem.
HuggieBear replied to Gazdaman's topic in PHP Coding Help
OK, you were on the right track with strtotime(); Here's some sample code I just knocked up, you could even put it into a function if you wanted. [code]<?php // Test data (unordered) $folders = array('01-01-1970-first', '05-01-1970-second', '10-06-2000-fifth', '05-03-1985-third', '19-12-1993-fourth'); // Loop through each folder foreach ($folders as $name){ preg_match('/^(\d{2})-(\d{2})-(\d{4})/', $name, $segments); // match each segment of the date $gnu_date_format = $segments[3].$segments[2].$segments[1]; // put date in gnu format (yyyymmdd) for passing to strtotime() $timestamp = strtotime($gnu_date_format); // change the date format to a unix timestamp $newlist[$timestamp] = $name; // new array keyed on timestamp } // Sort the new list ksort($newlist); // Echo the folder names foreach ($newlist as $folder){ echo "$folder<br>\n"; } ?>[/code] Regards Huggie -
Fair comment, I wasn't saying that what you'd posted was incorrect. I think it's good that people are prepared to make posts regarding additional methods. Regards Huggie
-
The code you have looks fine, and if you view the source and get the result that you've pasted then the only conclusion is that the 'processing' you've cut out is causing an issue of some kind. Regards Huggie
-
[quote author=mjdamato link=topic=123806.msg512326#msg512326 date=1169651760] I would assume that both of those can't be true at the same time. Thus, your test will always pass. [/quote] Hence, the change to AND instead of OR :) Huggie
-
You must output a header in imagecreator.php, like this: [code=php:0]header("Content-type: image/jpg");[/code] Of course this will change depending on the type of image you're outputting. Regards Huggie
-
In that case you need AND, not OR. [code]<?php if ((!$member) && (!$nonmember)){ // do whatever } ?>[/code] With OR, only one of the sides needs to be true for the whole statement to be true, with AND, both sides need to be true, which is what you're after. Regards Huggie
-
OK, what are you trying to achieve? It maybe that !$member isn't actually doing what you think it is. Regards Huggie
-
Try putting a '$' symbol in front of nonmember... You've missed it out :) Regards Huggie
-
Well, I think that you have the answer right there! Have you tried what they suggested, or have you asked your host to do it? Regards Huggie
-
Have you read the manual, as this makes it pretty clear! [b]mysql_fetch_array()[/b] [quote]Fetch a result row as an associative array, a numeric array, or both[/quote] [b]mysql_fetch_assoc()[/b] [quote]Fetch a result row as an associative array[/quote] Regards Huggie
-
How to insert things into a MySQL database with an ' in?
HuggieBear replied to oskare100's topic in PHP Coding Help
I'd go with [url=http://uk.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string()[/url]. Regards Huggie -
Another alternative, if you want to use it in multiple places, you could create the image like you are and save it. Depending on the type of image you're creating, you'll have a line that looks something like this, that outputs the image to the browser: [code=php:0]imagejpeg($im);[/code] or [code=php:0]imagejpeg($im, null, 100);[/code] By changing, or adding the second parameter, you can save the image. [code=php:0]$filename = '/home/domains/domain.co.uk/images/dynamic.jpg'; imagejpeg($im, $filename, 100);[/code] Regards Huggie
-
Correct way to get mysql results into an array in a class
HuggieBear replied to littlened's topic in PHP Coding Help
[quote author=bqallover link=topic=123799.msg512139#msg512139 date=1169632344] Have a look at using [url=http://uk.php.net/manual/en/function.mysql-fetch-assoc.php]mysql_fetch_assoc[/url] instead of mysql_fetch_array. [/quote] No need, mysql_fetch_array() returns both numeric and associative arrays. Just change the constant... Change this code: [code=php:0]while ($row = mysql_fetch_array($result)){[/code] To this: [code=php:0]while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){[/code] Regards Huggie -
This is a bit scrappy, as I've cobbled it together in about 10 mins, but it should give you an idea as to what's going on. [code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"> <input type="text" name="country"> Country<br> <input type="submit" name="search" value="Search"><br /><br /> <?php include_once('*****'); // If page number is set then use it, if not, set one! $page = !isset($_GET['page']) ? '1' : $_GET['page']; // Define the number of results per page $max_results = 5; // Figure out the limit for the query based on the current page number. $from = (($page * $max_results) - $max_results); // Specify the default SQL query $sql = "SELECT countries_name FROM countries WHERE 1=1"; // Amend the serach parameters if there are any if (isset($_GET['country'])){ $sql .= " AND countries_name LIKE '{$_GET['country']}%'"; } // Run the query to get the total number of results. $result = mysql_query($sql) or die(mysql_error()); $total_results = mysql_num_rows($result); // Amend the limit and order by parameters and re-query $sql .= " ORDER BY countries_name LIMIT $from, $max_results"; // Re-run the query with additional constraints $result = mysql_query($sql) or die(mysql_error()); if ($total_results < 1){ echo "Sorry, your search produced no results"; } else { echo "Your search produced $total_results results<br><br>\n"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "{$row['countries_name']}<br>\n"; } // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Construct the base link... $href = $_SERVER['PHP_SELF']."?"; foreach ($_GET as $k => $v){ if ($k != "page"){ $href .= "$k=$v&"; } } //Previous and next links $plink = "<< Previous"; $nlink = "Next >>"; echo "<center>"; // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"{$href}page={$prev}\">{$plink}</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"{$href}page={$i}\">{$i}</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"{$href}page={$next}\">{$nlink}</a> "; } echo "</center>"; } ?>[/code] You can see the code in action here... http://dizzie.co.uk/php/daviboy.php try it with no search data, an empty field, a full coutry, e.g sweden, and just the first letter e.g. S Regards Huggie
-
Sorry, haven't had a chance to post it yet, really busy at work, but I'll try to get on it now. Regards Huggie