HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
If statement issues with checking my cookie info!?!
HuggieBear replied to suess0r's topic in PHP Coding Help
You're cookie is called [color=green]cookie_city[/color], but when you check it to see if it's set, you're referring to is as [color=brown]choose_city[/color]. The inconsistency is what's causing the problem. Regards Huggie -
Sure... [code]<?php if (isset($_POST['submit'])){ $_SESSION['total']++; } ?> <input name="total incr" type="hidden" value="<?php $_SESSION['total'];?>">[/code] Regards Huggie EDIT: You're too fast for me pip3r :)
-
counting the number of txt extension files in a directory.
HuggieBear replied to ted_chou12's topic in PHP Coding Help
No problem, I always try to provide an example in order to help understand. Huggie -
counting the number of txt extension files in a directory.
HuggieBear replied to ted_chou12's topic in PHP Coding Help
Thorpe got there first, but I was just going to say that this: [code]<?php $number = 1; function doubleup($num){ return $num*2; } echo doubleup($number); ?>[/code] Produces the same result as this: [code]<?php $number = 1; echo doubleup($number); function doubleup($num){ return $num*2; } ?>[/code] Regards Huggie -
Fair comment. Huggie
-
[SOLVED] php string variables in a MySQL clause
HuggieBear replied to twistedmando's topic in PHP Coding Help
If that worked then mark the topic as solved so others can take advice from it. Regards Huggie -
[quote author=thepip3r link=topic=119158.msg487619#msg487619 date=1166474817] Do not use $_REQUEST. It's a security nightmare [/quote] $_REQUEST should be taken into consideration with regards to security, but to say don't use it isn't really helpful. There are uses for it and if used correctly, can be perfectly secure. Regards Huggie
-
You need to just do put the call to the function inside the loop... [code]<?php if ($handle = opendir('.')) { while (($file = readdir($handle)) !== false){ echo "$file\n"; output_iptc_data($file); } closedir($handle); } function output_iptc_data($image_path) { $size = getimagesize( $image_path, $info); if(is_array($info)){ $iptc = iptcparse($info["APP13"]); foreach (array_keys($iptc) as $s) { $c = count ($iptc[$s]); for ($i=0; $i <$c; $i++){ echo $s." = ".$iptc[$s][$i]."<br>\n"; } } } } ?>[/code] Regards Huggie
-
The latter would work better. Below is an example using $_REQUEST, so it will pick up all the values regardless of whether POST or GET was used. [code]<?php foreach ($_REQUEST as $k => $v){ echo "$k - $v<br>\n"; } ?>[/code] Regards Huggie
-
[SOLVED] php string variables in a MySQL clause
HuggieBear replied to twistedmando's topic in PHP Coding Help
If you're trying to get the amount then you need to fetch that data too. Try this code (error checking included this time)... [code]<?php $sql = "SELECT amount FROM colors WHERE color = '$color'"; $result = mysql_query($sql); if (!$result){ echo "Unable to run query: $sql<br>\n" . mysql_error(); } else { $row = mysql_fetch_array($result, MYSQL_ASSOC); echo $row['amount']; } ?>[/code] Regards Huggie -
[SOLVED] adding up numbers from each text files.
HuggieBear replied to ted_chou12's topic in PHP Coding Help
Ted, You've taken the code from two different posts there. My code should work with your details like this: [code]<?php // Directory path $dir = '/others/'; //this is the path to my txt files, I have three, they each have "2","3", and "3", // Open the directory $dh = opendir($dir); while (($file = readdir($dh)) !== false){ if ($file != '.' && $file != '..'){ $fullfile = $dir . $file; $subtotals[] = file_get_contents($fullfile); } } // Add them all together $total = 0; foreach ($subtotals as $st){ $total = $total + $st; } // Echo the total echo "$total\n"; ?>[/code] Regards Huggie -
OK, something like this would do it... [code]<?php $uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here $uploadfile = $_FILES['Picture1']['name']; // No need for basename() here if(!empty($_FILES['Picture1'])){ var_dump($uploaddir); var_dump($_FILES['Picture1']['size']); var_dump($_FILES['Picture1']['error']); var_dump($_FILE); var_dump($_FILES['Picture1']['type']); var_dump($_FILES['Picture1']['name']); } $fullpath = $uploaddir . $uploadfile; if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){ echo("File Uploaded"); $sql = "INSERT INTO business_info (picture1) VALUES ('$fullpath')"; $result = mysql_query($sql); if (!$result){ echo "Error inserting data: " . mysql_error(); } } else { echo ("file no uploaded!"); print_r($_FILES); echo realpath('./'); } ?>[/code]
-
[SOLVED] php string variables in a MySQL clause
HuggieBear replied to twistedmando's topic in PHP Coding Help
You need single quotes around your value... [color=blue]$extract="SELECT amount FROM colors WHERE color = [color=red]'[/color]$color[color=red]'[/color]";[/color] Regards Huggie -
[SOLVED] adding up numbers from each text files.
HuggieBear replied to ted_chou12's topic in PHP Coding Help
I've tested that code now and it works fine. It's adding them up correctly. You don't need to define the array first, the foreach loop should be happy with assigning each new value to [code=php:0]$subtotals[][/code] You do have the [code=php:0]$total = 0;[/code] outside the loop don't you? Regards Huggie -
Here's a really quick and easy guide to file permissions. http://www.htmlite.com/php042.php Regards Huggie
-
You could, but if the comments are always delimited by the ;---- then the RegEx that Orio suggested would probably be better, if it's coming from an external source, which it is, the RegEx is possibly more reliable. Regards Huggie
-
For standards compliant html, you should change the suggested line from this: [code=php:0]echo "<option value=\"$option\"".(($option==$_POST[test1])?" selected":"").">$option</option>\n";[/code] To this: [code=php:0]echo "<option value=\"$option\"".(($option==$_POST[test1])?" selected='selected'":"").">$option</option>\n";[/code] Regards Huggie
-
OK, well you didn't post that part of the code. Regards Huggie
-
Something like this would work, just replace the database column and form fields with the names you require. [code]<?php // Connect to the database include('connect.php'); // Query the database to get the values for the dropdown $sql = "SELECT id, name FROM menu_options"; $result = mysql_query($sql); if (!$result){ echo "Unable to execute $sql<br>\n" . mysql_error(); // Error if we got no result } // Start the select menu echo "<select name='menu_name'>\n"; // Echo each option of the menu while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>"; } // End the menu echo "</select>"; ?>[/code] Regards Huggie
-
If that worked, then mark the topic as solved and raise any new questions in a new topic, this will help people when searching titles for meaningful phrases. Regards Huggie
-
You don't want to use nl2br() at all. You want to leave them as new lines... If you provide your code we'll be able to help more. Regards Huggie
-
It's just a simple html form element... [code]<input type="file" name="file_to_upload"> <input type="submit" name="submit" value="Upload">[/code] It will put the browse button in automatically. Regards Huggie
-
[quote author=Orio link=topic=119118.msg487385#msg487385 date=1166457502] it doesnt make a diffrence in this case... Orio. [/quote] Pun totally intended :)
-
Why are you using realpath() on a path that's already 'real'? The following should work fine: [code]<?php $uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here $uploadfile = $_FILES['Picture1']['name']; // No need for basename() here if(!empty($_FILES['Picture1'])){ var_dump($uploaddir); var_dump($_FILES['Picture1']['size']); var_dump($_FILES['Picture1']['error']); var_dump($_FILE); var_dump($_FILES['Picture1']['type']); var_dump($_FILES['Picture1']['name']); } $fullpath = $uploaddir . $uploadfile; if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){ echo("File Uploaded"); echo("$uploaddir"); echo("$uploadfile"); } else { echo ("file no uploaded!"); print_r($_FILES); echo realpath('./'); } ?>[/code] Regards Huggie
-
Use single quotes... [code=php:0]$totalCost+=$row['price'];[/code] Regards Huggie