wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
You just open your browser and type in http://localhost in order to run your php scripts - make sure wamp is running before going to that address in order for it to work. You store all your files in C:/wamp/www
-
That code wont work. You must use double quotes when using whitespace characters within strings: $str = 'G f h s hhss s f'; $str = str_replace(array("\r\n", "\r", "\n"), ' ', $str); echo $str; // outputs: G f h s hhss s f
-
That script will basically export all the data from the person table and put into the person.sql file within the backup folder What is happening when you run the script?
-
How many more posts do you we need on this discussion? Thread locked, search the forum next time!
-
That is the result resource from your query.
-
No problem. Glad I could help!
-
That is because $data is an array and explode will only work on strings. You will need to loop through the $data array, eg: $translations= file('translation.txt'); foreach($translations as $translation) { list($id, $english, $spanish) = explode(' | ', $translation); $translate[$id][0] = $english; $translate[$id][1] = $spanish; } echo '<pre>', print_r($translate, true), '</pre>';
-
Simplified/cleaner version: <html> <body> <table border="1" cellspacing="0" cellpadding="5" width="440" style="border-collapse:collapse;"> <tr style="background-color:gainsboro"> <th>Product Code</th> <th>Description</th> <th>Price<br />(exc VAT)</th> <th>Price<br />(Inc. VAT)</th> </tr> <?php $odd = 'whitesmoke'; $even = 'azure'; $products = file('info.txt'); foreach($products as $i => $product_info) { list($product_code, $description, $price, $priceVAT) = explode('~', $product_info); $bg = ($i%2) ? $odd : $even; echo " <tr style=\"background-color:$bg\"> <td>$product_code</td> <td>$description</td> <td>\$$price</td> <td>\$$priceVAT</td> </tr>\n"; } ?> </table> </body> </html> info.txt: 001~Black Shoes~19.00~25.00 002~Light Blue T-Shirt~10.00~12.50 003~Item3 here~0.00~0.00 004~Item4 here~0.00~0.00
-
[SOLVED] How Do I Serialize an Array in a text file?
wildteen88 replied to Dave3765's topic in PHP Coding Help
Have a look at the file called exampledata2.php in the AdvATE folder to see how to create your array. -
[SOLVED] How Do I Serialize an Array in a text file?
wildteen88 replied to Dave3765's topic in PHP Coding Help
Surly the script you have allows you to change how many rows/columns there are without having to hack the default serialized array? -
[SOLVED] How Do I Serialize an Array in a text file?
wildteen88 replied to Dave3765's topic in PHP Coding Help
You use serialize() on the $data_array variable. You don't write the contents of the variable to a file then serialize the contents of that file. If you do that then the data is no longer an array and is considered a string! What are you trying to do to the original serialized array. -
Well there is you problem. You are outputting text/html before you call the header function Output is considered anything passed back to the browser, this can be text, html, newlines spaces etc. PHP will output anything before and after the PHP tags (<?php ?>) or any function your use within PHP that returns output eg echo, print, print_r, sprint etc. You should do all processing before you output anything rather than do them both at the same time. If you dont want to change your script you can use output buffering as a dirty fix.
-
You have output on line 13 in submitregister.php and you are calling header() on line 111 in that file. You cannot have any output before you use header. What is on/around line 13 in submitregister.php?
-
use mysql_real_escape_string prehaps. Also post some code on how you are applying addslashes.
-
[SOLVED] How Do I Serialize an Array in a text file?
wildteen88 replied to Dave3765's topic in PHP Coding Help
Use PHP's built in unserialize function on that string. Eg: <?php $data = 'a:20:{i:0;a:4:{s:4:"row0";s:14:"Row 0 column 0";s:4:"row1";s:14:"Row 0 column 1";s:4:"row2";s:14:"Row 0 column 2";s:4:"row3";s:14:"Row 0 column 3";}i:1;a:4:{s:4:"row0";s:14:"Row 1 column 0";s:4:"row1";s:14:"Row 1 column 1";s:4:"row2";s:14:"Row 1 column 2";s:4:"row3";s:14:"Row 1 column 3";}i:2;a:4:{s:4:"row0";s:14:"Row 2 column 0";s:4:"row1";s:14:"Row 2 column 1";s:4:"row2";s:14:"Row 2 column 2";s:4:"row3";s:14:"Row 2 column 3";}i:3;a:4:{s:4:"row0";s:14:"Row 3 column 0";s:4:"row1";s:14:"Row 3 column 1";s:4:"row2";s:14:"Row 3 column 2";s:4:"row3";s:14:"Row 3 column 3";}i:4;a:4:{s:4:"row0";s:14:"Row 4 column 0";s:4:"row1";s:14:"Row 4 column 1";s:4:"row2";s:14:"Row 4 column 2";s:4:"row3";s:14:"Row 4 column 3";}i:5;a:4:{s:4:"row0";s:14:"Row 5 column 0";s:4:"row1";s:14:"Row 5 column 1";s:4:"row2";s:14:"Row 5 column 2";s:4:"row3";s:14:"Row 5 column 3";}i:6;a:4:{s:4:"row0";s:14:"Row 6 column 0";s:4:"row1";s:14:"Row 6 column 1";s:4:"row2";s:14:"Row 6 column 2";s:4:"row3";s:14:"Row 6 column 3";}i:7;a:4:{s:4:"row0";s:14:"Row 7 column 0";s:4:"row1";s:14:"Row 7 column 1";s:4:"row2";s:14:"Row 7 column 2";s:4:"row3";s:14:"Row 7 column 3";}i:8;a:4:{s:4:"row0";s:14:"Row 8 column 0";s:4:"row1";s:14:"Row 8 column 1";s:4:"row2";s:14:"Row 8 column 2";s:4:"row3";s:14:"Row 8 column 3";}i:9;a:4:{s:4:"row0";s:14:"Row 9 column 0";s:4:"row1";s:14:"Row 9 column 1";s:4:"row2";s:14:"Row 9 column 2";s:4:"row3";s:14:"Row 9 column 3";}i:10;a:4:{s:4:"row0";s:15:"Row 10 column 0";s:4:"row1";s:15:"Row 10 column 1";s:4:"row2";s:15:"Row 10 column 2";s:4:"row3";s:15:"Row 10 column 3";}i:11;a:4:{s:4:"row0";s:15:"Row 11 column 0";s:4:"row1";s:15:"Row 11 column 1";s:4:"row2";s:15:"Row 11 column 2";s:4:"row3";s:15:"Row 11 column 3";}i:12;a:4:{s:4:"row0";s:15:"Row 12 column 0";s:4:"row1";s:15:"Row 12 column 1";s:4:"row2";s:15:"Row 12 column 2";s:4:"row3";s:15:"Row 12 column 3";}i:13;a:4:{s:4:"row0";s:15:"Row 13 column 0";s:4:"row1";s:15:"Row 13 column 1";s:4:"row2";s:15:"Row 13 column 2";s:4:"row3";s:15:"Row 13 column 3";}i:14;a:4:{s:4:"row0";s:15:"Row 14 column 0";s:4:"row1";s:15:"Row 14 column 1";s:4:"row2";s:15:"Row 14 column 2";s:4:"row3";s:15:"Row 14 column 3";}i:15;a:4:{s:4:"row0";s:15:"Row 15 column 0";s:4:"row1";s:15:"Row 15 column 1";s:4:"row2";s:15:"Row 15 column 2";s:4:"row3";s:15:"Row 15 column 3";}i:16;a:4:{s:4:"row0";s:15:"Row 16 column 0";s:4:"row1";s:15:"Row 16 column 1";s:4:"row2";s:15:"Row 16 column 2";s:4:"row3";s:15:"Row 16 column 3";}i:17;a:4:{s:4:"row0";s:15:"Row 17 column 0";s:4:"row1";s:15:"Row 17 column 1";s:4:"row2";s:15:"Row 17 column 2";s:4:"row3";s:15:"Row 17 column 3";}i:18;a:4:{s:4:"row0";s:15:"Row 18 column 0";s:4:"row1";s:15:"Row 18 column 1";s:4:"row2";s:15:"Row 18 column 2";s:4:"row3";s:15:"Row 18 column 3";}i:19;a:4:{s:4:"row0";s:15:"Row 19 column 0";s:4:"row1";s:15:"Row 19 column 1";s:4:"row2";s:15:"Row 19 column 2";s:4:"row3";s:15:"Row 19 column 3";}}'; $data_array = unserialize($data); echo '<pre>' . print_r($data_array, true) . '</pre>'; ?> You can now modify the array's values how you want them. Once done you can re-serialize with serialize -
[SOLVED] How Do I Serialize an Array in a text file?
wildteen88 replied to Dave3765's topic in PHP Coding Help
What do you mean by the individual values? serialize() will serialize the whole contents of tester2.txt as it'll see it as a string (text) and not an array. How was tester2.txt populated in the first place? -
[SOLVED] Can I use eval() to interpret code lines from a file?
wildteen88 replied to stuntpeople's topic in PHP Coding Help
That is fine however in your function (getitems) you'll need to define all those variables in vars.php as global. You cannot use variables within a function that is defined outside of it, unless you define it as global (within the function) or your pass that variable as an argument. Functions have there own variable scope. You'll want to read up on variable scrope in order to understand how variables work with functions. Incorrect: $myvar = 'hello world'; function myfunc() { echo $myvar; } myfunc() // produces undefined variable 'myvar' notice Correct $myvar = 'hello world'; function myfunc() { global $myvar; // tell the function myvar is a global variable. echo $myvar; } myfunc() // produces hello world -
[SOLVED] Can I use eval() to interpret code lines from a file?
wildteen88 replied to stuntpeople's topic in PHP Coding Help
You'd have to use eval in this situation. Working code: <?php // your vars here // myVars format: // $myVars['variable_name_here'] = 'variable value'; $myVars['movie_project_01'] = 'movie01'; $myVars['current_location'] = '(Unknown Location)'; function getitems($filename, $length) { global $myVars; // grab your variables. if (is_file($filename)) { $lines = file($filename); foreach ($lines as $line_num => $line) { if ($length != 0) { if ($line_num >= $length) { break; } extract($myVars); // get variables out of the array. eval("echo \"$line\";"); } } } } You're best of defining all the variables you'll use in news.php within an array, I called this myVars. That way all you have to do is set $myVars as global rather than all your variables. -
You'll want to use htmlspecialchars or htmlentities if you are passing HTML over the url. Eg: $dSetting = 5.1; $iSize = 300; $sDisplay = '<a class="nocHTMLtool_Anchor" href="display_incidents.php" target="_blank" style="font-weight: bold; color: black;">51</a>'; echo '<iframe src="/.../noc/test/gage_test2.php?dSetting=' . $dSetting . '&iSize=' . $iSize . '&sDisplay=' . htmlentities($sDisplay, ENT_QUOTES) . '"></iframe>';
-
Yes you can do this however you you'll need to change the forms action, so it submits to itself (the page the form is displayed on) rather than getting submitted to another page. Example: <?php $error = null; // form validation: if(isset($_POST['name']) && empty($_POST['name'])) { $error[] = 'Please fill in the name field'; } if(isset($_POST['age']) && empty($_POST['age'])) { $error[] = 'Please fill in the age field'; } // display errors if there is any: if(is_array($error)) { echo 'Please correct the following:<br />'; echo '<ul><li>' . implode('</li><li>', $error) . '</li></ul>'; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name" /><br /> Age: <input type="text" name="age" /><br /> <input type="submit" name="submit" value="Submit" /> </form>
-
Tested your attached configuration and it works fine for me, Although I did have to change your file paths as my setup is different to yours. Ofcourse this will happen. Web browsers do not understand PHP and thus nothing will happen. PHP is a server side language. This is why you have to install Apache and configure it with PHP in order for your PHP files to work. When you request PHP files from localhost what is happening is Apache will send the request PHP file to the PHP interpreter (php.exe), this will parse the PHP code within the .php file. When PHP finishes parsing the file it'll return the output back to Apache (which will be html/text). Apache will then send that ouput back to the browser. The browser will then parse the HTML/CSS/Javascript within the output from the script. PHP code will never reach the browser (unless you have a misconfigured server). This has nothing to do with PHP and shouldn't affect PHP.
-
This is most probably due to the fact that Windows by default will hide file extensions frm file names when viewed in Windows Explorer. I always disable this feature, to do so open any folder and goto Tools > Folder Options > View (tab) > Uncheck Hide extensions for known file types. Click Ok to apply the changes you'll now see file extensions for files. You did remove the # from infront of that line didn't you when you added it to the httpd.conf? Apache will ignore lines begging with # within the httpd.conf, these lines are considered as comments. When you modified the DocumentRoot you did change the main <Directory></Directory> block too. (This is located a few lines down from where you set the DocumentRoot to. It is not necessary to move files outside of the PHP folder. Keep all files within the PHP folder. Also make sure that restart Apache when you make changes to the httpd.conf (this also includes PHP's configuration file too which is called php.ini).
-
That code will go into the script which processes the form when it is submitted. Looking at your forms action tag the script which processing the form is checkmeout.php
-
[SOLVED] Php Installtion problem
wildteen88 replied to vishal99's topic in PHP Installation and Configuration
If you are getting an an Internal server error then this is an Apache configuration issue. Check Apaches error log for the reason for the Internal server error.