SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member auctioncatalogs's Avatar
    Join Date
    Jun 2001
    Location
    New York, NY
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with mysql_fetch_array and forms

    I'm a newcomer to PHP/mySQL, and I'm probably missing something obvious...

    Here's the problem (shopping cart application): I've tried to write an array to pull from the database registered customer shipping preferences (form input used is radio buttons) and have it write to this form.

    Interestingly enough, their credit card choices DO work perfectly!

    What am I missing :-( Any help would be greatly appreciated. Thank you!

    Here's the code for the array:

    if(($num_rows = mysql_num_rows($result))!=0) {
    $searchSuccess="YES";
    while($row = mysql_fetch_array($result))
    {

    if($row["shipvia"] == "Book Rate"){
    $Bshipvia = "checked";
    }elseif ($row["shipvia"] == "Priority Mail"){
    $Pshipvia = "checked";
    }elseif ($row["shipvia"] == "International"){
    $Ishipvia = "checked";
    }

    if($row["card_type"] == "Master Card"){
    $MCcheck = "checked";
    }elseif ($row["card_type"] == "Visa"){
    $Vcheck = "checked";
    } elseif ($row["card_type"] == "Discover"){
    $Dcheck = "checked";
    } elseif ($row["card_type"] == "American Express"){
    $AXcheck = "checked";
    } elseif ($row["card_type"] == "Personal Check"){
    $PCcheck = "checked";
    } elseif ($row["card_type"] == "Money Order"){
    $MOcheck = "checked";
    }

    $optselect1 = $row["country"] ;
    $optselect2 = $row["ship_country"] ;

    And here's where I'm trying to write to the form:

    <INPUT type=radio name="Ship" value="Book Rate" <?php echo $Bshipvia ?> ><b><font face="Verdana,Arial,Helvetica" size="1" color="#eeeecc">Media/Parcel Post (6 to 9 days)</font></b>&nbsp;
    <INPUT type=radio name="Ship" value="Priority Mail" <?php echo $Pshipvia ?> ><b><font face="Verdana,Arial,Helvetica" size="1" color="#eeeecc">Priority Mail (2 to 4 days)</font></b>&nbsp;
    <INPUT type=radio name="Ship" value="International" <?php echo $Ishipvia ?> ><b><font face="Verdana,Arial,Helvetica" size="1" color="#eeeecc">International</font></b></td>

    Mark

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well in the code snippet you give us, you are missing a closing "}" curly brace to close the while loop. BTW, if there should logically only be one record in the result set - and you are only going to work with one record to make the form - then the while loop is unnecessary. you can just write:

    $row = mysql_fetch_array($result);
    if ( ..... and so on...

    But, I suspect that your problem is that none of those if conditions for the shipping type are being met! The syntax looks OK. When you are debugging you need to place echo statements in your code to try and give you some idea as to what the problem is. For example add this to the code and when you have found the problem remove it.
    PHP Code:
    echo '<br> shipvia : '$row["shipvia"], '<br>';
    if(
    $row["shipvia"] == "Book Rate"){ 
       
    $Bshipvia "checked"
    }elseif (
    $row["shipvia"] == "Priority Mail"){ 
       
    $Pshipvia "checked"
    }elseif (
    $row["shipvia"] == "International"){ 
       
    $Ishipvia "checked"
    } else {
       echo 
    'No matching shipvia type found<b>';

    That might help give a clue as to what the problem might be.

  3. #3
    SitePoint Member auctioncatalogs's Avatar
    Join Date
    Jun 2001
    Location
    New York, NY
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks freakysid for your quick reply and the insights on the while loop and debugging.

    Turns out, the problem arose in another form that orinally populated the database.

    Again, Thanks!
    Mark


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
  •