Jump to content

AndyB

Staff Alumni
  • Posts

    5,465
  • Joined

  • Last visited

    Never

Posts posted by AndyB

  1. A couple of observations. While javascript might be one way to 'validate' user input not every visitor will have javascript active. Regardless of platform or browser, you can always validate input server-side as you don't care what your visitors have/don't have and use/don't use.

    One reason why some people might like to use client-side validation is that they create scripts in two parts: the data input script and the data processing script. In that case they may find they want the user to go back to a blank form just because one field was invalid. Bad design. Better to have the data input and processing in the same script so you can echo back user inputs when you need them to resubmit the form without filling it out again. Then you'll need some conditional branching to test whether the form has been submitted or whether this is the first visit to the form. isset() is one way of testing for specific input to use for such branching.

    And, of course, when you pass data via URL (click a link like showstuff.php?id=27) you can't validate that client-side if your visitors edit what's in the browser address bar to showstuff.php (for example). Isn't isset() nice to have?
  2. [b]You[/b] might always know exactly what's going on with your scripts, but your scripts (sometimes) have to deal with user input ... and users are the most unreliable things in the universe. If a user 'forgets' to provide a form input, wouldn't it be nice to know that an important variable had been set (by the user's input) before you processed their data?
  3. Basically, put what users enter into your database 'as is' and then when you display it use the [a href=\"http://ca.php.net/manual/en/function.nl2br.php\" target=\"_blank\"]nl2br() function[/a] to convert 'new lines' into html <br> tags:
    [code]$nice_text = nl2br($text);
    echo $nice_text;[/code]
  4. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You are a Genius [/quote]
    Not exactly. I spend time reading here, time looking through the manual, time looking through other people's scripts, and have gradually reduced the number of crazy mistakes I make to manageable proportions :)
  5. [!--quoteo(post=365709:date=Apr 17 2006, 05:58 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 17 2006, 05:58 PM) [snapback]365709[/snapback][/div][div class=\'quotemain\'][!--quotec--]so what would the purpose of taking strings out of a specific file without pulling the whole file.[/quote]
    It's called modular design (among other things). By using an included file instead of entering the same content into every page of a site, you can change one file and have every page change. Also, you never need to debug a piece of code that works only the stuff outside the included parts.

    An approximate HTML equivalent to an included file is an external javascript or external CSS file.
  6. Simply, you cannot have any output to the browser before the header() function. In the script you gave, just delete the title line (and anything above it that you didn't include here). That should fix it.
  7. The link you gave to the validator output (as well as the online code itself) are both the same. They use HREF (incorrect) and should be href, they have an image alt tag missing, and they pass a parameter in the link using & which needs to be &amp; which is what causes all the errors on line 73.

    If you fix those online and revalidate there should not be any errors.

  8. [code]<div class='random-image'><a HREF='index.php?page=viewgallery&category=Random'><img src='gallery/tn_mr_bean1.jpg' /></a></div> [/code]

    Change to:
    [code]<div class='random-image'><a href='index.php?page=viewgallery&amp;category=Random'><img src='gallery/tn_mr_bean1.jpg' /></a></div> [/code]

    That should clear all your errors.
  9. Your code/life will be simplest if you create an array of all the countries, and then use a simple piece of code like the below to generate your drop-down and show the selected country:
    [code]include("country_array.php");
    echo "<select size='1' name='country'>";
    for ($i=0;$i<count($countries);$i++ {
        echo "<option value='". $countries[$i]. "'";
        if ($country_from_db==$countries[$i]) { echo " selected style='background-color:#6ff'"; }
        echo ">". $countries[$i]. "</option>\n";
    }
    echo "</select>";[/code]
    The countries array file looks like:
    [code]
    $countries = array("Afghanistan", "Albania", lots more sountries, "Zambia", "Zimbabwe");[/code]
  10. Suggestions.

    First, I assume that id is sent to this page from a page (contact_menu.php presumably) which contains a form using the method="get" since your commented code suggests checking form values. If the form uses method="post" the $_GET array value will always be absent.

    Second, there's no way to tell at which stage the script tries to find a page that doesn't exist. For debugging purposes I'd suggest changing each instance of the header/location function to something simple like:
    [code]echo "failed at line whatever";
    exit;[/code]
    At least then you'll know what's causing it to fail.

    Third, add Barand's check in your script.

    And if a page can't be found, then the script is looking for a file that doesn't exist with the name you expect in the location you expect.
  11. [!--quoteo(post=365192:date=Apr 15 2006, 08:33 PM:name=hpughLW)--][div class=\'quotetop\']QUOTE(hpughLW @ Apr 15 2006, 08:33 PM) [snapback]365192[/snapback][/div][div class=\'quotemain\'][!--quotec--]What do you mean by a relative page address?[/quote]
    This link explains ... [a href=\"http://www.thuto.org/ubh/web/html/relad1.htm\" target=\"_blank\"]http://www.thuto.org/ubh/web/html/relad1.htm[/a]

    In your case, if contact_menu.php is in the same folder as the script with the problem, then this will work [relative address]
    [code]header("Location: contact_menu.php");[/code]
  12. [a href=\"http://localhost/contact_menu.php\" target=\"_blank\"]http://localhost/contact_menu.php[/a] is the only page that wouldn't be displayed. Are you sure it exists with that name in that folder? Personally, I'd change the redirect to a relative page address so when the script is uploaded to the server it'll still work as expected.
  13. Move the select closing tag ahead of the submit input and close the option tags.
    [code]<html>
    <head>
    <title>search2</title>
    <body>
    search me via search box
    <form  method="post" action="search.php>
    <SELECT NAME="name">
    <?
    $db=mysql_connect("localhost","xxx","xxx");
    mysql_select_db("freedating", $db);
    $query="select * from pro_membersu";
    $result=mysql_query($query);
    while($record=mysql_fetch_assoc($result)){
    echo "<OPTION VALUE='".$record["fname"]."'>".$record[name]. "</option>";
    }
    echo "</select>";
    ?>
    <input type="submit" value="submit">

    </form>
    </body>[/code]
×
×
  • 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.