HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
Query works - but not the first time the page loads?
HuggieBear replied to mibole's topic in PHP Coding Help
Change $p = $_GET['p']; if(is_null($p)) { $p = 0; } To $p = (isset($_GET['p'])) ? $_GET['p'] : 0; The reason your code doesn't work is because $p isn't null. It's assigned the value of $_GET['p']. Although $_GET['p'] may well have been empty, $p has still been assigned it's 'emptyness' hence not null. Regards Huggie -
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
No problem, I wrote it as GET to save me creating a form when developing it. Regards Huggie -
With most things, yes, with the mail() function, No! It's standards are as well defined as any of the PHP functions, but the headers parameter that it accepts is what governs which mail servers will happily receive it. However, by posting the code we will be able to see which headers you're currently using. Regards Huggie
-
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
Friendly, as promised, working code based on the UK Government Data Standards Catalogue entry for Postcodes. <?php // Get the postcode from the url $postcode = $_GET['postcode']; // Split out any spaces $postcode = str_replace(" ", "", $postcode); // Specify what our areas actually are $areas = array('BR1','BR2','BR3','BR4','BR5','BR6','BR7','BR8','DA1','DA4','DA5','DA6','DA7','DA8','DA14','DA15','DA16','DA17','DA18','SE1','SE2','SE3','SE4','SE5','SE6','SE7','SE8','SE9','SE10','SE11','SE12','SE13','SE14','SE15','SE16','SE17','SE18','SE19','SE20','SE21','SE22','SE23','SE24','SE25','SE26','SE27','SE28','SW2','SW4','SW8','SW9','SW11','SW12','SW16','SW17','SW18','CR0','CR2','CR4','CR7','CR8'); // Use length to help check the different formats for UK postcodes $char = strlen($postcode); if (($char == 5) && preg_match('/([a-z]\d)\d[a-z]{2}/', $postcode, $matches)){ // S1 2AB if (in_array(strtoupper($matches[1]), $areas)){ $match = 1; } } elseif (($char == 6) && preg_match('/([a-z]{2}\d)\d[a-z]{2}/i', $postcode, $matches)){ // BR1 2AB if (in_array(strtoupper($matches[1]), $areas)){ $match = 1; } } elseif (($char == 6) && preg_match('/([a-z]{1}\d{2})\d[a-z]{2}/i', $postcode, $matches)){ // S12 3AB if (in_array(strtoupper($matches[1]), $areas)){ $match = 1; } } elseif (($char == 7) && preg_match('/([a-z]{2}\d{2})\d[a-z]{2}/i', $postcode, $matches)){ // BR12 3AB if (in_array(strtoupper($matches[1]), $areas)){ $match = 1; } } elseif (($char == 7) && preg_match('/([a-z]{2}\d[a-z])\d[a-z]{2}/i', $postcode, $matches)){ // SW1W 2AB if (in_array(strtoupper($matches[1]), $areas)){ $match = 1; } } else { echo "Sorry, your postcode appears to be invalid"; exit(); } // Echo the output to the screen if ($match){ echo "Congratulations, " . strtoupper($matches[1]) . " is in our area<br>\n"; } else { echo "Sorry, " . strtoupper($matches[1]) . " isn't in our area<br>\n"; } ?> Regards Huggie -
Calling javascript.js file from a php file
HuggieBear replied to jholstein's topic in PHP Coding Help
There were form tags in the PHP code, I know, I changed them! I only added a 'name' element to the relevant form tag though, and then changed the javascript to look at that field. It all works here. Regards Huggie -
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
I'll take a look at this a little later this morning if I get the chance. Regards Huggie -
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
Working fine! I must have pasted it incorrectly. Thanks mate Don't forget, you'll need to do some validation on this first, as if I entered my postcode as BR21 then it'd tell me it's in your area, even though it's actually not as it's only looking at the first three characters. Regards Huggie -
Calling javascript.js file from a php file
HuggieBear replied to jholstein's topic in PHP Coding Help
OK, try with the attached files. Regards Huggie [attachment deleted by admin] -
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
Check you've copied and pasted it correctly, as I've just checked it and it works. Regards Huggie -
Call me old fashioned, but I'd say that means it doesn't work. Try changing the query to this... mysql_query("INSERT INTO albums (album_id,album_name, album_desc,album_cover) VALUES ('0', 'Peter', 'Griffin' , 'yes')") or die (mysql_error()); Regards Huggie
-
[SOLVED] I thought this would be a simple script?
HuggieBear replied to fri3ndly's topic in PHP Coding Help
Try this... <?php // Set the areas you cover $areas = array('BR1','BR2','BR3'); // Get the postcode from the form $postcode = strtoupper($_POST['postcode']); // Check the areas against the postcode entered if (in_array(substr($postcode, 0, 3), $areas)){ echo "$postcode is in area!!!"; } else { echo "Sorry, the postcode $postcode is outside of our work region"; } ?> This is basic and will need lots more validation. Regards Huggue -
It is, but it looks as though you want to know so you can create tabular data in columns. If so then there's loads of posts on here about it, just search these forums. Regards Huggie
-
Calling javascript.js file from a php file
HuggieBear replied to jholstein's topic in PHP Coding Help
Your PHP file is incorrect, but not because the php's incorrect, but your html field names aren't correct. That's why it's not working. Can you post the full code for your page? Regards Huggie -
redirecting to the ID of newest item created
HuggieBear replied to envexlabs's topic in PHP Coding Help
If you're using MySQL then make your insert using mysql_query() and then straight after, use mysql_insert_id() <?php if ($r = mysql_query("INSERT INTO product_table VALUES ('something','something')")){ header('Location: product.php?product_id=' . mysql_insert_id($r)); } ?> Regards Huggie -
Something like this should work (Untested)... <?php // Maximum posts to show $show = 25; // Run the query and assign the total rows to a variable $r = mysql_query("SELECT count(`id`) FROM `table`"); $total = mysql_result($r, 0, 0); // Set the true offset if the value is less than 0 $offset = ($total - $show < 0) ? 0 : $total - $show; // Run the query with the offset $r = mysql_query("SELECT * FROM `table` ORDER BY id LIMIT $offset, $show"); // Then process $r as you were before ?> Regards Huggie
-
I can't see that, I guess it's a member only feature. You can do it, but you'd need more than one query, that's all. Regards Huggie
-
OK, well the tagbox here shows the newest messages at the top of the box! Which would be "SELECT * FROM table ORDER BY id DESC LIMIT 25". If you wanted it the other way around then you'd need to use this more than one query. Regards Huggie
-
What columns are in your database? Huggie
-
If you're ordering by ID (Assuming that id is auto incrementing) then use DESC Regards Huggie
-
Newest comment first is DESC (Descending) not ASC (Ascending). Rergards Huggie
-
[SOLVED] Upload file and create directory for each user?
HuggieBear replied to sayedsohail's topic in PHP Coding Help
In that case you can pretty much ignore all the permissions stuff I believe as Windows doesn't implement it properly. Regards Huggie -
Alternatively just drop an onClick event in <button name="delete" value="delete" onClick="location.href='http://www.google.co.uk'">Delete</button> Regards Huggie
-
Oh I see. Why not just create an image and use that as a hyperlink? Huggie
-
OK, well mark this topic as solved by using the 'Topic Solved' button and start a new thread for that question. Regards Huggie :-)
-
[SOLVED] Upload file directory setting
HuggieBear replied to emediastudios's topic in PHP Coding Help
I'm based in the UK and I'll PM you from here on in... Regards Huggie