Jump to content

DavidGS

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by DavidGS

  1. Thanks! I managed to do it with a str_replace too, but this is much easier.
  2. OK, so I have a form with a textarea and submit button. I made a simple PHP program which gets the form data and writes it to a database. Works perfectly, information always gets stored without hassle. However, whenever I submit something with an apostrophe ('), it won't write it to the database. It refreshes the page and whichever changes I make that included the apostrophe in it would get removed, like they were never there. The form code: print "<form>\n"; print "<textarea name='text' cols='80' rows='5'>$text</textarea><br><br>\n"; print "<input type='SUBMIT' value='Update'>\n"; print "</form>\n"; The post code: if ($_POST['text']) { $textupdated = $_POST['text']; mysql_query("UPDATE profile_content SET text='$textupdated' ") or die(mysql_error()); } The $text variable is from an array: $qry = mysql_query("SELECT * FROM profile_content"); $contents = mysql_fetch_array($qry); $text= $array['text'];
  3. I know this is a rather trivial question, but how do I go about setting the value of a variable through a URL? Like, say you had a page which has "tabs" and for each tab you want to display different content. To make sure the user sees the right tab, you would use something like http://example.com/index.php?tab=1 When I try to set the value of a variable that way it doesn't return anything. print "$pageid"; with the URL http://localhost/index.php?pageid=1 Nothing is printed because pageid doesn't have a value. But if I try defining the variable in the script: $pageid = 1; It returns whatever value I defined it with instead. What is right way of using variables in your URL?
  4. Thanks, ~n[EO]n~, that's exactly what I needed.
  5. OK, so I have a news system set up on my website and I am using a database to store the news in. It's just one table called "news" and there are 5 columns (id, name, title, contents, date). I am using a while loop to list all the news on the main page, but all the old content stays at the top and the new stuff is at the bottom. I want the new stuff up top and all the old stuff down the bottom. This is the code: $query = "SELECT * FROM news"; $result = mysql_query($query) or die(mysql_error()); while($news = mysql_fetch_array($result)) { print "<br><b>{$news['title']}</b><br>\n"; print "<i>By {$news['name']}</i>.<br>\n"; print "<p>{$news['contents']}</p>\n"; print "<small>{$news['date']}</small><br>\n"; } It works without errors, but as I said, since all the newest records are stored at the bottom of the table, they're listed last instead of first. What loop would I use to list these rows in reverse-order?
  6. Orio, Basically the user can put in anything they like as long as it doesn't have certain characters in it. Example, they register with the URL "joe", their personal URL would be http://www.website.com/joe/ Because this will be an actual URL I don't want characters than can cause any errors when trying to access it. So by limiting what the user can select as his personal URL I can avoid any errors The user will be able to enter letters, numbers and underscores and them only. They register with the URL "joe_bob6", their personal URL would be http://www.website.com/joe_bob6/ That would be an acceptable URL and there would be no issue accessing it. But if the user registered with the URL "$joe%bob/", their URL would be http://www.website.com/$joe%bob// which may be problematic and cause an interpretation error in PHP (particularly with the dollar sign). This is so that can be avoided.
  7. You know how when you register a MySpace account you can choose a personal URL? Basically I am making a social networking website and I am adding the same feature. The only problem is how would I validate a URL the person registering has entered to make sure it doesn't contain any characters that could case problems? Like, I wouldn't want the person entering @ because that would be interpreted as an e-mail address or . because that would be mistaken for a file type separator. I want to validate it to make sure it only contains letters, numbers and underscores. Anyone have an expression I could use?
  8. THANKS! It works great. What would I enter if I didn't want any symbols other than a particular symbol in a string. Because I am making a website that lets you register your own personal URL (like MySpace) and I don't want to let the user enter any characters other than letters, numbers and underscores to prevent any errors with their URL.
  9. Hm, when I use this code to check if e-mails entered are valid, It always returns the same value, even if the e-mail isn't valid. if (!eregi("\b[A-Z0-9_%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b",$emailused)) {$validemail = 1;} else {$validemail = 0;} I just can't figure out why.
  10. OK, so I need a code to validate that a user's e-mail address, URL and age entered into a form is valid (syntax). I have the form set up and it works and writes information to a database. It checks that a URL entered isn't already in a database and same with the e-mail. All I want it to do now is check that that the e-mail address entered is in the correct format, to check if the URL entered only contains letters, numbers and underscores and the age entered is actually a number. For the e-mail validation, it should accept e-mail addresses from top-level domains other than .com (like .co.uk and .com.au), the URL validation should accept letters numbers and underscores and the age validation should only accept two-digit numbers (any zeros at the start eliminated). Any help would be appreciated.
  11. It still does it! This is driving me nuts, even when I test to see if PEAR works it still redirects. <?php require 'DB.php'; if (class_exists('DB')) { print "ok"; } else { print "failed"; } ?> This code should print "OK" if PEAR's installed, but all it does (in order) is: 1. Tries connecting to localhost 2. Says it's transferring data from localhost 3. Says it's connecting to www.localhost.com 4. Says it can't find the server on www.localhost.com What is going on?! ??? I have WAMP Server installed and I am accessing the file by typing in http://localhost/peartest.php (the file's in the directory and everything).
  12. So I am learning PHP and I was reading over how PHP can connect to databases, so I created a MySQL database and wrote a small program in PHP to see if it can access the database. Assuming my MySQL username was "user" password was "password" and I was accessing a database named "exampledb", the code would be: DB::connect('mysql://user:password@localhost/exampledb'); BUT when I run the program in Firefox, instead of connecting to http://localhost/ it connects to http://www.localhost.com/ and I don't want that to happen. How can I fix this?
  13. This is http:// which always uses forward slashes. When navigating through Windows Explorer you use backslashes. That's to do with the web client, not the web server. It may not make a difference but surely it's worth a try? I use XAMPP for Windows but learning to install PHP/Apache could be good experience for the future! I get a "Server not found" error from Firefox when I change it to a backslash.
  14. Yeah it'd be nicer to have them all managed at once rather than have to set them up all manually. It's just the PHP book I am reading explains how to set them up manually to work with each other. No luck. Thanks for the help.
  15. This is http:// which always uses forward slashes. When navigating through Windows Explorer you use backslashes.
  16. OK, so I want to be able to run my own PHP files in Firefox without having to upload them to a web-server. I downloaded and installed Apache HTTP server 2.2.6, PHP5 and FastCGI 2.4.6. I configured PHP5 to work with Apache by editing the Apache config file (httpd.config) and adding the following lines: Alias /fcgi-bin/ "c:/Program Files/PHP/" FastCgiServer "c:/Program Files/PHP/php.exe" -processes 5 AddType application/x-httpd-fastphp .php Action application/x-httpd-fastphp /fcgi-bin/php.exe I included to the FastCGI extension with Apache by adding this line to the LoadModule section of the Apache config file: LoadModule fastcgi_module modules/mod_fastcgi-2.4.6-AP22.dll I used the "Test Configuration" program to check the config file and it said there were no errors. Apache is set up for localhost as I will only use it to test websites on my computer. I created a PHP file to test "hello.php", all it does is echo "Hello" on the screen. I know it works because I uploaded to a free web-server and it executes. However, whenever I try and execute the file through Firefox by accessing it through http://localhost/hello.php (the file is in the proper directory), I get an error message: Forbidden You don't have permission to access /fcgi-bin/php.exe/hello.php on this server. How could I be forbidden from accessing my own PHP files when I can access all the other files on http://localhost/ without problems?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.