wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
[SOLVED] Faulty Form Validation... STUMPED
wildteen88 replied to christofurr's topic in PHP Coding Help
Your form validation is showing all errors because your comparisons are incorrect. Look at the following code: if ($missA = "1A") Here you are assigning the variable missA the value "1A" and then testing whether its true. All assignments will return true and so it echo's out all error messages Instead you should use the comparison operator (==) -
If you are going to be echo'ing out HTML you will need to escape the quotes, eg: <?php echo "<a href=\"http://www.somesite.com\" target=\"_blank\">anchor</a><br>description."; ?> Or you could just use single quotes when defining the string: <?php echo '<a href="http://www.somesite.com" target="_blank">anchor</a><br>description.'; ?> Basically whatever character you use when you start the string (' or ") you must escape that character when you want to use it within the string. If you don't escape your quotes then you'll get errors. You escape the quote by adding a forward slash in front of it as shown above.
-
problem in installation
wildteen88 replied to hell_nishit's topic in PHP Installation and Configuration
Nerd to more info like:- What OS you are using? What steps you have taken to install Apache and PHP? What errors/problems you are getting -
[SOLVED] Get a varable to loop out side the loop
wildteen88 replied to redarrow's topic in PHP Coding Help
You are passing invalid parameters to functions. You cannot pass this lot as a parameter: ($new_width[1])&&($new_width[2])&&($new_width[3]) What you are doing there is a comparison. In order to achieve what you are trying to do you have to run through the following functions ImageCreateTrueColor, ImageCreateFromJPEG, imagecopyresampled, Imagecopyresized, ImageJPEG, and imagedestroy for every size image you want to create from the original image. Here is a good way of doing it: <?php // this our dedicated function that creates our resized images function createImage($width, $height, $srcimg, $img_thumb) { $srcImg = ImageCreateTrueColor( $width, $height ) or die('Problem In Creating image'); if( function_exists('imagecopyresampled' )) { imagecopyresampled( $srcImg, $srcimg, 0, 0, 0, 0, $width, $height, ImageSX($srcimg), ImageSY($srcimg) ) or die('Problem In resizing img #' . $key); } else { Imagecopyresized( $srcImg, $srcimg, 0, 0, 0, 0, $width, $height, ImageSX($srcimg), ImageSY($srcimg) ) or die('Problem In resizing img #' . $key); } ImageJPEG( $srcImg, $img_thumb, 90 ) or die('Problem In saving img'); imagedestroy( $srcImg ); } if(isset($_POST['Submit'])) { $size[1] = 100; $size[2] = 200; $size[3] = 300; $filedir = './pics/'; $thumbdir[1] = './pics1/'; $thumbdir[2] = './pics2/'; $thumbdir[3] = './pics3/'; $prefix = '00005'; $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $prod_img = $filedir.$userfile_name; $prod_img_thumb[1] = $thumbdir[1].$prefix.$userfile_name; $prod_img_thumb[2] = $thumbdir[2].$prefix.$userfile_name; $prod_img_thumb[3] = $thumbdir[3].$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); $srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); $sizes = getimagesize($prod_img); $aspect_ratio = $sizes[1]/$sizes[0]; if (($sizes[1] <= $size[1]) || ($sizes[1] <= $size[2]) || ($sizes[1] <= $size[3])) { $new_width = $sizes[0]; $new_height = $sizes[1]; } else { $new_height[1] = $size[1]; $new_height[2] = $size[2]; $new_height[3] = $size[3]; $new_width[1] = abs($new_height[1]/$aspect_ratio); $new_width[2] = abs($new_height[2]/$aspect_ratio); $new_width[3] = abs($new_height[3]/$aspect_ratio); } // loop through each img width and call a dedicated function to // create different sizes of the uploaded image foreach($new_width as $cur_img => $cur_img_width) { // this function uses the variables set above createImage($cur_img_width, $new_height[$cur_img], $srcimg, $prod_img_thumb[$cur_img]); } } /*echo '<a href="'.$prod_img.'"> <img src="'.$prod_img_thumb[3].'" width="'.$new_width[3].'" height="'.$new_height[3].'"> </a>';*/ // show the created images foreach($prod_img_thumb as $cur_img => $img_thumb) { echo '<h3>Img #' . $cur_img . '</h3> <a href="' . $prod_img . '"> <img src="'.$prod_img_thumb[$cur_img].'" width="'.$new_width[$cur_img].'" height="'.$new_height[$cur_img].'"> </a><br /> Dimensions: ' . $new_width[$cur_img] . 'px X ' . $new_height[$cur_img] . 'px'; } } else { echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> <input type="file" name="image"><p> <input type="Submit" name="Submit" value="Submit"> </form>'; } ?> -
I just downloaded the script of off sourceforge. I would say to add the following two lines at the begging of htdocs/config.php ini_set('session.auto_start', 'off'); ini_set('register_globals', 'off'); looking at the script config.php is the file that is always included and is the first file to be included for every page for V-Webmail.
-
Yes you have to add it at the beginning of every page. Or if your script has a main configuration file that always gets included you just add it to the beginning of that file. Unfortunately no there is not any alternatives due to the way your host has PHP setup.
-
Yes you can create a var to store what str_replace will return. But you got to pass it a source to do replacements with. $zinja = str_replace( ":)", "<img src='/bildes/smile.gif'>,", $zinja ); Everything highlighted above is correct. Except for the highlighted variable in red. That variable must contain the raw data that contains the raw smiley symbols for str_replace to replace it.
-
where does the $zinja variable come from? I do not see that variable any where in your code.
-
You cannot use sessions on different servers. When you use an iframe that is a sperate instance of PHP. The PHP code is parsed on the site the iframe is serving. Not the site that has the iframe on it. You will probably want to look in cURL for what you are trying to do.
-
Yes of course you can. Have you not tried it? Just make sure you define the function before you use it.
-
The comma is just a symbol that separates parameters for functions. It is nothing special. it does not have a special roll in any sort of formatting.
-
Yes your host is right. php_flag or php_value is only available ifPHP is compiled as an Apache Module. What your hosts suggests is to use the ini_set function within your script to change PHP configuration rather than using an .htaccess file. Have a read of the manual on ini_set for how to use it and what PHP settings you can change with it.
-
What! Can you please rephrase your question. Please include more detail. About 2 or 3 sentences of what you are trying to do?
-
What happen if you define the rewrite base to the root RewriteBase / RewriteCond $1 !^(index\.php|images|core|robots\.txt) RewriteRule ^(.*)$ index.php/?$1 [NC,L]
-
It is best to look at Apaches error log for the reason why you are getting 500 internal error message. I think it maybe because Apache is not recognising the php_flag attributes within the .htaccess file.
-
When you go to save the file in notepad make sure the File Type box is set to All Files and not Text Document (*.txt). If you cannot save changes to the hosts file then there may be security software on your computer that is preventing you from saving to the hosts file. For example I have ZoneAlarm Firewall. It has the option called 'Lock host file' (under Firewall > Advanced). If that setting is enabled then I get similar errors as to you.
-
In order to do that you will have to edit your host file (On Win XP it is in "C:\windows\system32\drivers\etc\hosts") and add the following line to it: 127.0.0.1 test.localhost Then setup a Virtual Host within the httpd.conf file for each subdomain you setup within the hosts file. Here is an example of what you have to do here. And here is the documentation for setting up virtual hosts. NOTE: You must restart Windows when you make any changes to the hosts files. Also make a backup of you hosts file before making any changes - boot into safe mode to make a backup of this file.
-
Why are you placing these variables on their line and then not doing anything with them? $_SESSION['BusinessName']; $_SESSION['User_Name']; $_SESSION['Password']; I guess you are doing it to initiate the variables. You don't need to initialize them before use. PHP wont do any think with them. PHP automatically initializes session variables when you call session_start() function. I would just remove those lines and any similar lines. Also I cannot see how the two blocks of code for the two pages relate to each other. On the first page you create a session var called BusinessName with the value from $BusinessName variable - where is that variable set to?. Then you have about two instances of $_SESSION['BusinessName']; on their own (for no apparent reason). After that you print out the contents of the session. Which miraculously reports back a value. This is where it gets confusing. ON page 2 you are now dealing with _POST data. Where does that come from? I did not see you using a form on page1. See I cannot really help as I cannot see any connection between the two pages and so I cannot help you fix the problem you are having. If you could repost post your question in a manner that what ever you code you post actually links together in some way that I/We can understand it in order to help you.
-
[SOLVED] how to write this in .htaccess?
wildteen88 replied to bilis_money's topic in PHP Coding Help
php_value or php_flag directives will only work within a .htaccess file if the web host has enabled the use of .htaccess files and that PHP is running as an Apache Module. If PHP is running under CGI then those directives will not work. To check whether your host has PHP setup as an Apache Module create a new file call it test.php and add the following code: <?php phpinfo(); ?> Upload it to your host and then run it. Look for the line that begins with Server API. To the right of it will state whether it is running as CGI or Apache x.0 Module (x representing Apaches Version number). Also check with your host whether you can use .htaccess files. If you host has disallowed the use of .htaccess file OR that PHP is not running as an Apache Module then you cannot change PHP configuration through .htaccess files. In stead you will have to resort to chigley's suggestion for using ini_set. -
[SOLVED] Loop Through and Append to String
wildteen88 replied to TripleDES's topic in PHP Coding Help
If you are dealing with an array and you want to place each array item into a string to be saved to a variavle use implode: <?php $parts = array('nuts and bolts', 'spanners', 'a chain'); $var = implode(', ', $parts); echo $var; ?> The result is a nice list like so: nuts and bolts, spanners, a chain -
You can do it all in one script. When you submit the form you will want it to submit to itself by having $_SERVER['PHP_SELF'] as the action eg: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Make sure your submit button has a name, for example submit. Then some place in your script you have an if statement that will check whether $_POST['submit'] variable exist like so: if(isset($_POST['submit'])) { // do all validation here // if it passes validation save post'd data to .csv } Here is a working example of what I mean: <?php // check that form has been submitted // if _POST['submit'] var exists it has been submitted if(isset($_POST['submit'])) { // lets validate posted data $err = null; // check that the name field has been filled in // and that it only contains letters and spaces if(!isset($_POST['name']) || !eregi('[a-zA-Z ]+', $_POST['name'])) { $err[] = 'Make sure you have filled in your name and that it only contains letters'; } // check that the age field has been filled in // and that it contains only numbers if(!isset($_POST['age']) || !is_numeric($_POST['age'])) { $err[] = 'Make sure you have filled in your age and that it only contains numbers'; } // check whether any errors have been flaged from validation proccess above: if(is_array($err)) { // errors have been flagged // lets display them // The form will be shown too. echo 'Please correct the following errros:'; echo "\n<br />\n<ul>\n <li>" . implode("</li>\n <li>", $err) . "</li>\n</ul>\n<br />\n"; } else { // no errors have been flagged // data is valid, lets add it to a .csv file // open the .csv file $csv_handler = fopen('data.csv', 'a'); // remove the submit var. We don't want to store this. unset($_POST['submit']); // prepare data to be added to csv file // format to be added to file: // "[name]", "[age]" $csv_entry = '"' . implode('", "', $_POST) . "\"\r\n"; // write the prepared string to the csv file fwrite($csv_handler, $csv_entry, strlen($csv_entry)); // close the file fclose($csv_handler); // print a successfully added message echo "Successfully added name and age to csv"; exit; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : '' ?>" /><br /> Age: <input type="text" name="age" value="<?php echo isset($_POST['age']) ? $_POST['age'] : '' ?>"><br /> <input type="submit" name="submit" value="Add" /> </form> Note it is basic and is just a simple example of how to process form information on the same page.
-
Yes it applies to all versions of PHP. You probably didn't see that error last time because your PHP4 setup had display_errors set to off so you didn't see the error - however you would of gotten a blank page instead. Or your PHP4 setup had output buffering enabled in the php.ini
-
Your email address is hidden as it is in italics. Only you can see your email address no one else (apart from Admins/Moderators ofcourse). Normal members cannot see your email addy. ABout your PM's not showing up in the Outbox I am not sure about that. Also separating your username from your display name is defenently a no no.
-
Don't use nl2br when you insert text into the database. Only use nl2br when you go to display the text to the page. The database will preserve whitespace characters (newlines). The browser ignores whitespace characters that is why when you print text will newlines in it shows it as just one line. When you use nl2br it converts the whitespace newline chars into a HTML line break (<br />).
-
Unable to make aligment between PHP and Apache
wildteen88 replied to akirajt's topic in PHP Installation and Configuration
Could you post the full error message you are getting here. From what you have said your configuration should be fine. Make sure your firewall is setup to allow incomming connections to Apache on port 80 and that Apache is running.