Jump to content

DavidGS

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

DavidGS's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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).
×
×
  • 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.