Results 1 to 8 of 8

Thread: Checking Fields

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Checking Fields

    Hello, I actually have 2 questions. The first is I am trying to make a scirpt that will make sure that a file field is filled in. For normal text or password fields I use
    Code:
    if (!$whatever) {
    I tried that and I also tried
    Code:
    if (strlen($whatever) < 1) {
    Neither one worked out. I am guessing it is because you can not check an image fields contents because it is made for uploading. Is there a way I can check to make sure it is filled in?

    Also, is there a way to have a search look for anything that looks has a few letters matching? I am thinking of using eregi(), but I am trying to search a mysql database and do not know what I need to search in (the sting that I search for the pattern within it). How can I do this?

    Thanks
    Last edited by Titan85; 04-23-2007 at 12:48 AM.
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Use the isset() function:
    Code:
    if (!isset($whatever)) { // it is NOT set
    - Mike

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried that and even if there is a file specified it gives the error I specified if it is not set. Any ideas? Also, does anyone have an idea on what I should do with the search?
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    if ($var !== ("" || null)) {

    Try that...
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Titan85 View Post
    The first is I am trying to make a scirpt that will make sure that a file field is filled in.
    Use the isset function to examine the $_FILES super-global array:

    PHP Code:
    if (isset($_FILES['control-name'])) {
        
    /* File uploaded */

    You'll probably want to perform further analysis to ensure the user sent what you wanted. See the PHP documentation for more information.

    For normal text or password fields I use
    Code:
    if (!$whatever) {
    I would recommend more strenuous tests based on regular expressions. For example, sending a string of white space would still pass that test, but be completely useless. Probably.

    I tried that and I also tried
    Code:
    if (strlen($whatever) < 1) {
    Neither one worked out. I am guessing it is because you can not check an image fields contents because it is made for uploading. Is there a way I can check to make sure it is filled in?
    Are you actually trying to examine the input field? You cannot: it is a means to an end and not actually sent to the server. Only the uploaded data, if any, is transmitted.

    Also, is there a way to have a search look for anything that looks has a few letters matching? I am thinking of using eregi(), but I am trying to search a mysql database and do not know what I need to search in (the sting that I search for the pattern within it). How can I do this?
    There are pattern matching search techniques in SQL. For example,

    &#160;&#160;SELECT * FROM table WHERE forename LIKE '%ic%'

    would match names like Michael, Jessica, etc. Some database engines, including MySQL, support regular expressions, too. See the reference for string comparison functions in MySQL for a start.

    Quote Originally Posted by boxxertrumps View Post
    if ($var !== ("" || null)) {
    That would be equivalent to:

    PHP Code:
    if ($var !== false) { 
    as the OR logical operator (||) always yields a boolean.

    Mike

  6. #6
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, i got the image checker working, but the search still isn't. Now it is not returning results at all. Here is my code:
    PHP Code:
    $get mysql_query("SELECT * FROM `teams` WHERE name LIKE '%$value%'") or die ("Error Searching Teams! \n<br />\n" .mysql_error()); 
    Value is:
    PHP Code:
    $value mysql_real_escape_string($_POST['value']); 
    Is it not reading what value is? Thanks
    Thanks DD, you saved me countless times

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Titan85 View Post
    Here is my code:
    PHP Code:
    $get mysql_query("SELECT * FROM `teams` WHERE name LIKE '%$value%'") or die ("Error Searching Teams! \n<br />\n" .mysql_error()); 
    Value is:
    PHP Code:
    $value mysql_real_escape_string($_POST['value']); 
    Is it not reading what value is?
    I don't see any obvious problems. Try echoing or logging the values to make sure that they are what you expect. For instance, include the following somewhere before the query:

    PHP Code:
    echo "<!-- {$value}\n";
    var_dump($_POST);
    echo 
    "  -->\n"
    The comment, beginning at the second line, may be quite long depending upon how much data was submitted via the POST method.

    Mike

  8. #8
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, its working now. I thought that I had some data in the database like what I was searching, but I actually didn't :/. Just my stupid mistake. Thanks for the help.
    Thanks DD, you saved me countless times

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •