SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why doesn't it generate the array error?

    There is a query made to the table Books which tries to find a similar username id the column book. If the username doesn't exist the script just proceeds to the next step.

    IF the username exists, it generates an error in the ERROR ARRAY and then redirects to my error page. Or at least it should!

    Here lies the root of the problem. It just proceeds regardless if there is a username match or not. I'm not getting any errors of any sort besides this inability to work!

    any idea what I'm missing?

    PHP Code:
    <?php 
    // start the session 
    session_start(); 
    header("Cache-control: private"); //IE 6 Fix 
    include "scripts/dbconnect.php";
    $result mysql_query("SELECT book FROM books",$db);
    while (
    $row mysql_fetch_array($result)) { 

    $_SESSION['form_errors'] = array(); 

    if ((
    $_POST['client_username']) == $row['book'] ) { 

        
    $_SESSION['form_errors']['client_username'] = '<br /><table width=220 height=24 border=0 cellpadding=0 cellspacing=0><tr><td><span class=text-error-validation >ERROR</span></td></tr></table>'
    } else { 
        
    $_SESSION['form_errors']['client_username'] = null

    }


    if (!empty(
    $_SESSION['form_errors']['client_username'])) 

        
    header("Location: myerrorpage.php" ); 

    ?>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,191
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    empty

    Maybe if you tried this instead?
    PHP Code:
    if ($_SESSION['form_errors']['client_username']) 

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    move this out of the loop

    $_SESSION['form_errors'] = array();

  4. #4
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Neither of the solutions actually worked. Clamcrusher, do you mean this?

    PHP Code:
    $result mysql_query("SELECT name FROM clients",$db);
    $_SESSION['form_errors'] = array(); 

    while (
    $row mysql_fetch_array($result)) { 

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i had a closer look at your code, you shouldnt be looping through your entire database result set to do this. although you could do it like that, its not efficient.

    PHP Code:
    <?php
    // start the session
    session_start();
    header("Cache-control: private"); //IE 6 Fix
    include "scripts/dbconnect.php";

    $_SESSION['form_errors'] = array();

    $result mysql_query("SELECT book FROM books WHERE book = '".$_POST['client_username']."'",$db);

    if (
    mysql_num_rows($result) > 0) {
        
    // we found a match
        
    $_SESSION['form_errors']['client_username'] = '<br /><table width=220 height=24 border=0 cellpadding=0 cellspacing=0><tr><td><span class=text-error-validation >ERROR</span></td></tr></table>';
        
    header("Location: myerrorpage.php" );
        exit;
    }


    ?>


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
  •