Jump to content

Recommended Posts

Im a n00b to PHP.

 

i think ive pinned down the problem to the while loop condition, yet it is almost word for word of whats in the book im using. This is driving me nuts. Please help.

 

Code:

 

<?php>

        database connection lines removed

 

        /*gets clothing type from nuke_type_cloth table*/

        $type_query="SELECT clothing_type FROM nuke_type_cloth ORDER by clothing_type";

 

        $type_result = mysqli_query($cxn,$type_query);

 

        /*begin display form*/

        echo "<p><form action='submit_new.php' method='POST'></p>\n";

 

        /*display clothing type radio buttons*/

        $counter = 0;

        while ($type_row = mysqli_fetch_assoc($type_result))

        {

                extract($type_row);

                /*echo "in loop";*/

 

 

                echo "<input type='radio' name='category' value='$clothing_type'";

                        if($counter == 0)

                        {

                                echo "checked";

                        }

                echo ">$clothing_type";

                $counter++;

        }

 

        echo "<input type='radio' name='category' value='new'>";

        echo "<input type='text' name='new_cat_name' size='20' maxlength='25'></td>\n";

 

        /*display gender type*/

        /*gets genders from nuke_sex_cloth table*/

        $gender_query="SELECT gender FROM nuke_sex_cloth";

 

        $gender_result = mysqli_query($cxn,$gender_query);

 

        /*display gender type radio buttons*/

        $counter=0;

        while($gender_row = mysqli_fetch_assoc($gender_result))

        {

                extract($gender_row);

                echo "<input type='radio' name='category' value='$gender_type'";

                        if($counter == 0)

                        {

                                echo "checked";

                        }

                echo ">$gender_type";

                $counter++;

        }

 

 

        echo "<input type='submit' value='Add New Item'>\n";

        echo "</form>\n";

?>

Link to comment
https://forums.phpfreaks.com/topic/41053-wtf-is-wrong-with-my-while-loop/
Share on other sites

Let me do this for you before I look through it.

 

<?php
        //database connection lines removed

        /*gets clothing type from nuke_type_cloth table*/
        $type_query="SELECT clothing_type FROM nuke_type_cloth ORDER by clothing_type";

        $type_result = mysqli_query($cxn,$type_query);

        /*begin display form*/
        echo "<p><form action='submit_new.php' method='POST'></p>\n";

        /*display clothing type radio buttons*/
        $counter = 0;
        while ($type_row = mysqli_fetch_assoc($type_result))
        {
                extract($type_row);
                /*echo "in loop";*/


                echo "<input type='radio' name='category' value='$clothing_type'";
                        if($counter == 0)
                        {
                                echo "checked";
                        }
                echo ">$clothing_type";
                $counter++;
        }

        echo "<input type='radio' name='category' value='new'>";
        echo "<input type='text' name='new_cat_name' size='20' maxlength='25'></td>\n";

        /*display gender type*/
        /*gets genders from nuke_sex_cloth table*/
        $gender_query="SELECT gender FROM nuke_sex_cloth";

        $gender_result = mysqli_query($cxn,$gender_query);

        /*display gender type radio buttons*/
        $counter=0;
        while($gender_row = mysqli_fetch_assoc($gender_result))
        {
                extract($gender_row);
                echo "<input type='radio' name='category' value='$gender_type'";
                        if($counter == 0)
                        {
                                echo "checked";
                        }
                echo ">$gender_type";
                $counter++;
        }


        echo "<input type='submit' value='Add New Item'>\n";
        echo "</form>\n";
?>

well i was trying to debug the first while loop by echoing "in loop" to see if it actually went into the loop but it doesnt. The second while loop is a duplicate of the first so that doesnt work either.

 

Im not getting an error message, it just doesnt display anything to the browser.

You probably have either an error with your query, or an empty/non-existent table.

Anyway, change the line that runs the query to:

$type_result = mysqli_query($cxn,$type_query) or die(mysqli_error());

 

If you get no errors, make sure you have records inside the nuke_type_cloth table.

 

Orio.

PHP should show most of errors (the more serious ones) unless you set it not to show them. If you want to see all of the errors, in the beginning of the script add this: error_reporting(E_ALL);

Can you show the whole script (including the connection to the database)? Just replace the username, password, db-name etc' with "XXXXX". Maybe you have a problem in the beginning.

 

Orio.

Good call. I originally had included a file with the login information for security reasons but when i put the variables into the script itself it worked this time. Now i need to troubleshoot the second loop.

 

Orio would you be interested in helping me get my website running? we can discuss specifics including $$ at my email address. You can find it in my profile.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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