wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
The cause of the error is on line 1 in D:\wamp\www\pandalho\index.php. The error was returned from D:\wamp\www\testing\index.php on line 5 What is on line 1 in D:\wamp\www\pandalho\index.php? <<< That is the file that is causing the error.
-
You will have to provide separate rewrite rules for the different urls with or without the page number, eg: RewriteRule (.*)mod_category/([^/]+)$ mod_category.php RewriteRule (.*)mod_category/([^/]+)/page_(.*)\.htm[l]?$ mod_category.php [L]
-
Do you mean add a new line (<br />)/paragraph (<p></p>) after ten items have been pulled out from a database? If so then following should do it: $qry = 'YOUR QUERY HERE'; $result = mysql_query($qry); $i = 0; // Initiate the counter while($row = mysql_fetch_assoc($result)) { // echo your row(s) here // check to see if $i is less than 10, if it is increment counter by one, else echo a new line. if($i < 10) $i++; // increment counter by one else echo '<br />'; // echo new line if $i is not less than 10; }
-
Download 2 files from database that has one user id
wildteen88 replied to brucensal's topic in PHP Coding Help
If you are using PHP5 then you could read this Zend article. -
[SOLVED] [http 403 error] - can someone check my php?
wildteen88 replied to LuckY07's topic in PHP Coding Help
Have you used your mysql username/password for the mysql_connect function. Looks like you havn't. If you have installed MySQL and havn't setup username/password already then use root as the username and nothing for the password instead, eg: mysql_connect("localhost","root",""); You have to provide a valid username/password when connecting to mysql. Also ensure the mysql server is actually running too. -
$result will return true whether or not any rows was returned or not. What you should use is mysql_num_rows to see if any rows was returned or not, ge: $query = "SELECT * from firms ORDER BY firmID DESC"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo "No results found."; } else { while($row = mysql_fetch_assoc($result)) { echo (whatever the results were); } }
-
[SOLVED] [http 403 error] - can someone check my php?
wildteen88 replied to LuckY07's topic in PHP Coding Help
redirect the user back to shoutbox.php when their post has been added to database. That way if the user hits the refresh button your web browser wont resend the POST data back to the page. <?php //the host, name, and password for your mysql mysql_connect("localhost","username","password"); //select the database mysql_select_db("news"); if(isset($_POST['submit'])) { //use the PHP date function for the time $time = date("h:ia d/j/y"); /* protect ourselves from SQL Injection */ $name = mysql_real_escape_string($_POST['name']); $message = mysql_real_escape_string($_POST['message']); // inserting it into the shoutbox table which we made in the mysql statements before mysql_query("INSERT INTO shoutbox (id, name, message, time) VALUES ('NULL','$name', '$message','$time')"); // redirect the user. header("Location: shoutbox.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Shoutbox</title> </head> <body> <?php //returning the last 5 messages $result = mysql_query("select * from shoutbox order by id desc limit 5"); //the while loop while($r = mysql_fetch_array($result)) { //getting each variable from the table $time = $r['time']; $id = $r['id']; $message = $r['message']; $name = $r['name']; echo $time . "<br>\n"; echo $name . "<br>\n"; echo $message . "<hr>\n"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br> <INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'> <input type="submit" name="submit" value="submit"> </form> </body> </html> Notice I have moved the code block which adds the entry to the database before the html. This is because you cannot send any headers when there is any form of output. Output is considered anything outside of the php tags, or anything from echo/print/sprintf etc. -
From the website you referenced looking at the code they use the number one and not a lower case L. So it should be: sprintf('%01d %s', 10133760, 'KB') //Output: 10133760 KB
-
[SOLVED] [http 403 error] - can someone check my php?
wildteen88 replied to LuckY07's topic in PHP Coding Help
You can use superglobal variables with in query if you wish (or any other string), however you have to wrap them in curly braces - {} if you use them inside double quotes. This is to do with how PHP parses arrays within quotes. -
If you want to parse that contents the php file you'll need to use a http address and not a local address eg: $module_contents = file_get_contents("http://localhost/new/inc/modules/" . $module . '.php');
-
[SOLVED] [http 403 error] - can someone check my php?
wildteen88 replied to LuckY07's topic in PHP Coding Help
Yes those where the changes that needed to made. However with regarding the following That is ok for personal use however not for production use. It is not recommended to place raw user data ($_POST, $_GET, $_COOKIE, etc.) directly into a query as your query will be prone to SQL injection attacks, which can be used to hack your site, or even worse completely erase your database. In order to protect yourself from SQL injection attacks I'd recommend you to use the built in mysql_real_escape_string function. This will help to protect you from such attacks. So instead of doing: "VALUES ('NULL',$_POST['name'],$_POST['message'],$_POST['time'])"); Do: $name = mysql_real_escape_string($_POST['name']); $message= mysql_real_escape_string($_POST['message']); "VALUES ('NULL', '$name', $message, $time)"); You do not have run mysql_real_escape_string on all fields only those which store strings. If a fields only needs a number then validate with is_numeric to see if the data only contains numbers. Corrected Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Shoutbox</title> </head> <body> <?php //the host, name, and password for your mysql mysql_connect("localhost","username","password"); //select the database mysql_select_db("news"); if(isset($_POST['submit'])) { //use the PHP date function for the time $time = date("h:ia d/j/y"); /* protect ourselves from SQL Injection */ $name = mysql_real_escape_string($_POST['name']); $message= mysql_real_escape_string($_POST['message']); // inserting it into the shoutbox table which we made in the mysql statements before mysql_query("INSERT INTO shoutbox (id, name, message, time) VALUES ('NULL','$name', '$message','$time')"); } //returning the last 5 messages $result = mysql_query("select * from shoutbox order by id desc limit 5"); //the while loop while($r = mysql_fetch_array($result)) { //getting each variable from the table $time = $r['time']; $id = $r['id']; $message = $r['message']; $name = $r['name']; echo $time . "<br>\n"; echo $name . "<br>\n"; echo $message . "<hr>\n"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br> <INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'> <input type="submit" name="submit" value="submit"> </form> </body> </html> If you still get the 403 error message then check WAMP's configuration. Make sure you are running your script from http://localhost and not directly loading it into a web browser from c:\mywebsite -
Better to use mysql_fetch_assoc then mysql_result: $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo '<pre>' . print_r($row, true) . '</pre>'; $row will be an associative array. I use print_r above to display the contents of the $row array.
-
use ./reception/ instead. the ./ means from the current (working) directory (or cwd for short) NOTE: ./ will work if your url is wwwmysite.com as the browser will read reception/ from wwwmysite.com/reception/ However if your url is this: wwwmysite.com/dir2/ then the browser will read reception/ from wwwmysite.com/dir2/reception/. As dir2/ is the cwd. Instead you should use ./../reception/. The ../ means backup one level in the directory tree.
-
Download 2 files from database that has one user id
wildteen88 replied to brucensal's topic in PHP Coding Help
You cannot use the same header multiple times. Only one or the other will be received, usually the first. The others will be ignored. What you'll want to do is is perhaps get the files out the database then create an archive file (zip/rar etc) to store them in. Then you'd use 1 header for downloading the archive file. -
[SOLVED] [http 403 error] - can someone check my php?
wildteen88 replied to LuckY07's topic in PHP Coding Help
Where is shoutbox.php stored? If you have wamp installed then it should be C:/wamp/www I believe. Also I noticed the script replies on register_globals. register_globals was disabled by default as of PHP4.2 and is now depreciated. Consider finding a more up to data tutorial, however the code is still workable just needs a few variable names to be changes to the $_POST superglobal. Another thing I noticed is it uses short tags (<? ?>). Short tags is not enabled by default when PHP is installed. Instead convert <? to <?php -
No .CSS file...where is the styling coming from?
wildteen88 replied to cheap5.0's topic in PHP Coding Help
@cheap5.0 I have edited your posts within this thread and wrapped your code within code tags ( ). Please make sure you use code tags when posting code. This makes it easier identify text from code and and minimises the need for scrolling. Also it is advised to only post relevant bits of code not whole scripts. Instead please use the File Attachment feature for posting whole scripts. -
Instead of using foreach to join the values within an array together you could just use implode instead: <?php Class test { function insert($fields, $values, $table) { $qryFields = implode("','", $fields); $qryValues = implode("','", $values); $qry = "INSERT INTO $table('$qryFields') VALUES ('$qryValues')"; mysql_query($qry) or die('QUERY ERROR: Inserting failed...<br /><code>'.$qry.'</code><br />' . mysql_error()); } } if(isset($_POST['submit'])) { $name = $_POST['name']; $age = $_POST['age']; $fields = array('name', 'age'); $values = array($name, $age); $test = new test; $test->insert($fields, $values, 'table_test'); } ?>
-
You could check to see how many parts have been returned from explode, if its two then fname lname if three fname m lname. $name = 'fname lname'; $parts = explode(' ', $name); switch(count($parts)) { case 2: list($fname, $lname) = explode(' ', $name); $mname = 'N/A'; break; case 3: list($fname, $mname, $lname) = explode(' ', $name); break; } echo 'Firstname: ' . $fname . '<br />'; echo 'Middlename: ' . $mname . '<br />'; echo 'Surname: ' . $lname;
-
If the names themselves don't have have space within them then you could use explode to split the names into three variables, like so: $name = 'fname m lname'; list($fname, $mname, $lname) = explode(' ', $name); echo 'Firstname: ' . $fname . '<br />'; echo 'Middlename: ' . $mname . '<br />'; echo 'Surname: ' . $lname;
-
any one heard of phpev5?
wildteen88 replied to aircooled57's topic in PHP Installation and Configuration
Where is the link to your website? You might be better of looking into a content management system (CMS). -
any one heard of phpev5?
wildteen88 replied to aircooled57's topic in PHP Installation and Configuration
Well what are you wanting to do? Learn PHP? If all you want to do is learn PHP then install WAMP and away you go. Before using WAMP make sure you have the documentation for it, such how to start/stop/restart WAMP, where to place your php files, how to access/run your scripts. For learning PHP I'd suggest the first place to go is php.net reading the manual (chapters I and III) in order to learn the basics. Then search online for some tutorials, such as sitepoint.com or php-mysql-tutorials.com. -
any one heard of phpev5?
wildteen88 replied to aircooled57's topic in PHP Installation and Configuration
Do you mean phpdev5? phpdev5 is just a pre-configured package for installing AMP (Apache MySQL and PHP) on Windows. There are many other pre-configured packages out there such as WAMP or XAMPP I prefer to install AMP manually rather than using a pre-configured package. -
In order to run and test your PHP scripts you'll need to install PHP. Dreamweaver doesn't come with PHP, and in order to test your PHP scripts in Dreamweaver you need to setup a test server, which you do by installing Apache and PHP. PHP is server sided language. Which means it runs on the server side and not the client side (eg: web browser) like HTML/CSS. In your last thread here I told you what to do in order to install PHP and to configure Apache with PHP on windows. If you don't want to do a manual install of Apache and PHP then you could install WAMP from wampserver.com which is a pre-configured package.
-
Try: $information = "username=MyUsername; password=mypass; somethinelse=tralala"; $variables = explode('; ', $information); foreach($variables as $variable) { list($variable_name, $variable_value) = explode('=', $variable); $$variable_name = $variable_value; } echo '$username = ' . $username . '<br />'; echo '$password = ' . $password . '<br />'; echo '$somethinelse = ' . $somethinelse;
-
Download the windows binaries zipped package from php.net (not the source code). Extract the contents of the zip to C:/php. Add the following lines to Apache's httpd.conf: LoadModule php5_module "C:/php/php5apache2_2.dll"; PHPIniDir "C:/php" AddType application/x-httpd-php .php Save the httpd.conf. Now go to C:\php and rename a file called php.ini-recommended to php.ini Restart Apache. To test php create a file called phptest.php and place it in C:/Program Files/Apache Foundation/Apache2/htdocs (Note your path to Apache might differ, also delete any existing files within the htdocs folder too) Add the following code in phptest.php: <?php phpinfo(); ?> Open your web browser and go to the following address http://localhost/phptest.php If your installation of PHP was a success you should get a page full of PHP's current configuration and operating environment.