-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Uploading an image folder using php/mysql
PFMaBiSmAd replied to mikebarbaro's topic in PHP Coding Help
http://swfupload.org/ -
There's at lest three different reasons mysql_num_rows($result) won't be equal to 1 and the form will be redisplayed. 1) The query failed with an error and mysql_num_rows will be a -1 2) There is no matching row in the table and mysql_num_rows will be a 0 3) There are two or more matching rows in the table and mysql_num_rows will be 2 or more. TeNDoLLA suggested checking what value mysql_num_rows($result) returns by using var_dump(mysql_num_rows($result)); Have you done that?
-
Your last question has nothing really to do with the first question and the solutions already posted (unless you are trying to make a template system that has embedded conditional logic in it, in which case you wouldn't do it this way at all.) The [i_VAR] is simply a unique place holder/tag that you make up and put into a STRING at the point where you want to substitute/replace it with an actual value when the code is executed. Your if ($alldata[$i]['image'] == "") code isn't the same situation, because it is not a string you are trying to replace values in. It's an array that expects array index values to address the elements of the array.
-
Each image you put onto a WEB PAGE must use an <img src="..." alt=""> HTML TAG. The src="..." attribute must be a URL to where the browser fetches the image from. You cannot output the raw image data directly in the HTML source of a WEB PAGE (well you can, but it is not nice for a couple of different reasons.) As TeNDoLLA indicated in your existing thread for this problem, you would use a .php script in the URL in the src="..." attribute. That .php script would output the correct content type header followed by the image data. -------- To store the images in a folder, you would put the file name of the image into the database (instead of the actual image data) and simply use the file location and the file name when you output the URL in the <img src="..." alt=''> tag on the web page.
-
I'm not sure how 'real' your example is, but a function would be used like this - <?php function td_class_num($i){ return "<td class='num'>$i</td>"; } for ($i=1; $i<=8;$i++) { echo "<tr>" . td_class_num($i) . "</tr>"; } ?>
-
Or you could write a function that would accept and operate on the current value at the time the function is called.
-
@cyberRobot, setting the error_reporting level just stops the error from being reported. Php must still detect and handle the error every time it occurs. It's always best to write code that does not produce any php errors, warnings, or notices during its normal and expected execution. You should only get errors for unexpected things so that you can find and fix what is causing the error, such as a hacker trying to break into your script or a legitimate visitor doing something that your code did not take into account.
-
http://us3.php.net/manual/en/language.operators.string.php Since the .= references the variable (it's the same as $var = $var . 'some new string' using your second example causes a php undefined error to be triggered on the first line using .= since the $I variable doesn't initially exist. Php must handle the error and this takes a handful of extra microseconds for the error checking and handling code to run each time and depending on your error_reporting, display_errors, and log_errors settings will cause an error message to be output to the browser or logged to the error log file (which will cause your log file to fill with errors that will make finding actual errors harder.) The first code example you posted should be used, since it initially creates the $I variable and does not produce any php errors.
-
Can you help create an array of function for this code?
PFMaBiSmAd replied to wright67uk's topic in PHP Coding Help
LOL, when I tested, I didn't have a form, so I just set $_GET['treetype'] = '...'; variables in the code and I also removed the two unnecessary lines that are setting - $treetype = $_GET["treetype"]; and $girthsize = $_GET["girthsize"]; You have two problems - 1) The two lines of code that are setting $treetype = $_GET["treetype"]; and $girthsize = $_GET["girthsize"]; are also messing up the two arrays of data because they define the two variable names as scaler variables first, then they are treated as arrays. If you would use print_r($items), you could have seen where the problem is occurring at. You don't need these two lines and they weren't in the original code that I posted. 2) The code currently only matches exact values, so your value="..." attributes in the form must match the array keys exactly. Alder is not equal to alder. -
Different visitors will have different session ids and will each have their own separate session data.
-
Here's your error message - headers already sent by (output started at /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php:1) in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/PHOTO_SITE/gallery/process.php on line 89 Based on the code you posted, you have a space or some other character before the <?php tag that is on line 1. You cannot output any characters to the browser before you do something that requires a http header.
-
What does var_dump($price2); show? And what exactly happens and what do you expect to happen?
-
^^^ Inside a string it is not. $date = "$year-$month"; and $date = $year.'-'.$month; produce exactly the same result.
-
The $date variable contains a YYYY-MM value. In order to select matching information from your table, you would need to use just the YYYY-MM part of actDate in the query.
-
There's a BIG sticky post at the top of this forum section that address header errors - HEADER ERRORS - READ HERE BEFORE POSTING THEM http://www.phpfreaks.com/forums/index.php?topic=37442.0
-
Read the error message. It tells you where the output is occurring at in your code that is causing the problem - output started at D:\AppServ\www\mission1\checklogin.php:10 (line 10.) Then look at line 10 in your code and try to determine what your code is doing on line 10 that could be sending output to the browser and eliminate that output.
-
user login, error on line 10, ')' unexpected
PFMaBiSmAd replied to silverglade's topic in PHP Coding Help
Line 10 has two extra ) in it. All you need is - if (strlen($post_username) >25 || strlen($post_password) < 15) -
Help with getting variable data to update in table
PFMaBiSmAd replied to harlequeen's topic in PHP Coding Help
You are only getting one set of values, the last set, because you are not using array names for your form fields. Your form fields should have name attributes like - The team_id (hidden) field - name='team_id[]' The input Points input field - name='points[]' -
Can you help create an array of function for this code?
PFMaBiSmAd replied to wright67uk's topic in PHP Coding Help
I tried the code you posted and got - Your total is: 21! The code you actually executed must be something different than what you posted. -
-
Because your function definition is inside of a conditional statement, the definition must come before the call to the function.
-
Can you help create an array of function for this code?
PFMaBiSmAd replied to wright67uk's topic in PHP Coding Help
I would do something like this - <?php // define the arrays that associate the keywords to the values ... $swordtype['wood'] = 20; $swordtype['bronze'] = 40; // other data here... $shieldtype['wood'] = 20; $shieldtype['bronze'] = 40; // other data here... $treetype['alder'] = 10; $treetype['apple'] = 14; // other data here... $items = array(); // data associated with each item $items['swordtype'] = array('legend'=>'Sword','values'=>$swordtype); // The legend is used when printing user messages, form field legends... The values is the array of keyword/value $items['shieldtype'] = array('legend'=>'Shield','values'=>$shieldtype); $items['treetype'] = array('legend'=>'Tree','values'=>$treetype); $errors = array(); // keep track of any validation errors $result = array(); foreach($items as $key => $record){ if(empty($_GET[$key])){ // empty $errors[] = "The {$record['legend']} type is empty!"; // or you could set a default value here... } else { // something was submitted, check if a valid keyword if(!isset($record['values'][$_GET[$key]])){ // keyword doesn't exist $errors[] = "The {$record['legend']} type: {$_GET[$key]}, doesn't exist!"; // or you could set a default value here... } else { // keyword exists, get the value $result[$key] = $record['values'][$_GET[$key]]; } } } if(empty($errors)){ // no validation errors, use the submitted data here... $total = array_sum($result); echo "Your total is: $total!"; } // display any errors if(!empty($errors)){ echo "The following errors occurred-<br />"; foreach($errors as $error){ echo "$error<br />"; } } ?> -
I would go through your code and every place you have a header('Location: xxxx.xxx'); redirect statement, add an exit; statement after it to prevent the remainder of the code on the page from being executed. Edit: I would also set error_reporting to E_ALL and display_errors to ON (in a local php.ini if php is running as a CGI application or in a .htaccess file if php is running as an Apache Module) so that any things like session errors would be reported and displayed. If output_buffering is turned on in your master php.ini, I would turn it off as well since it hides any output from your code when you perform a redirect.
-
Typecasting when selecting data from database
PFMaBiSmAd replied to fe_81's topic in PHP Coding Help
The following works for float, integer, string, and boolean - <?php function convert_type($val){ if(is_numeric($val)){ return $val + 0; } if(strtolower($val) == 'false'){ return false; } if(strtolower($val) == 'true'){ return true; } return $val; } $row = array_map('convert_type',$row); echo json_encode($row); ?>