Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3997696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:26:00+00:00 2026-05-20T07:26:00+00:00

I have two problems here: 1. I have a problem with the value of

  • 0

I have two problems here:
1. I have a problem with the value of the checkbox
2. I have a problem with the mysql_fetch_array($variable, ASSOC); method –> all the data from my database are VARCHAR type

1. All the variable with, at the end ‘Cb’, signified that this value is from a checkbox of a FORM. If a checkbox is checked, it means that the row (ex: Username) will be in the Select method for my Database (ex: SELECT Username FROM…)

I receive this Error
1. Undefined index: fonctionCb in C:\wamp\www\Projet Compte Utilisateur\manip_liste.php on line 7
2. Undefined variable: tab in C:\wamp\www\Projet Compte Utilisateur\manip_liste.php on line 14
…etc from all the checkbox if they are not checked .. here is my PHP code

<?php   
$prep = "";

if(!$_POST['username'])
    echo 'Nom d\'utilisateur manquant';

if(($_POST["userCb"]) && ($_POST["suffixeCb"]) && ($_POST["fonctionCb"]) && ($_POST["passwordCb"])){
    $prep = " * ";
    $tab = "User    SUFFIXE     SITE    FONCTION    PASSWD";
}
else{   
        if($_POST["userCb"]){
            $prep += "username ,";
            $tab += "USER   ";
        }           
        if($_POST["suffixeCb"]){
            $prep += "suffixe ,";
            $tab += "SUFFIXE    ";
        }   
        if($_POST["passwordCb"]){
            $prep += "password ,";
            $tab += "PASSWD ";
        }
        if($_POST["siteCb"]){
            $prep += "siteWeb ,";
            $tab += "SITE   ";
        }
        if($_POST["fonctionCb"]){
            $prep += "fonction ";
            $tab += "Fx ";
        }
    }//ELSE

require("db_action.php");   //Require in the database connection.
$bd = db_open();
$data = db_select($prep,  $_POST["username"]); //Envoie des variables à afficher et du Username pour le SELECT

echo "'$tab'";
echo "'$data'";    ?>    

2. The second ERROR
and also I got this error from the fetch_array method
Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\Projet Compte Utilisateur\db_action.php on line 68

Here is the code from my method

function db_select($prep, $username){

        $querycon = "SELECT '$prep' FROM info_compte WHERE username = '$username'";
        if(!mysql_query($querycon)){
            echo "Il n\'y a aucun '$username' dans la base de données";
            $response = "";
        }
        else{
                while ($row = mysql_fetch_array(mysql_query($querycon), MYSQL_ASSOC))
                    printf("%s  %s  %s  %s  %s", $row["username"], $row["suffixe"], $row["password"], $row["siteWeb"], $row["fonction"]);  //The PRINTF dont work 
            }

        return $response;   
}//db_select

Thank you all to answer and i specify that i’m a beginner in practice who wants to learn ..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:26:00+00:00Added an answer on May 20, 2026 at 7:26 am

    For part 1, one problem is that you may have a trailing comma on the end of $prep depending on what columns you end up selecting. To solve this try the below code (note I’ve added backticks around your column names, it’s good practice but not required). The isset() function checks if a variable actually exists. Currently you are trying to access variables that may not exist, hence the errors.

    <?php   
    $prep = array();
    $tab = '';
    
    if(!isset($_POST['username']))
        echo 'Nom d\'utilisateur manquant';
    
    if(isset($_POST["userCb"]) && isset($_POST["suffixeCb"]) && isset($_POST["fonctionCb"]) && isset($_POST["passwordCb"])){
        $prep[] = "*";
        $tab = "User    SUFFIXE     SITE    FONCTION    PASSWD";
    }
    else{   
            if(isset($_POST["userCb"])){
                $prep[] = "`username`";
                $tab .= "USER   ";
            }           
            if(isset($_POST["suffixeCb"])){
                $prep[] = "`suffixe`";
                $tab .= "SUFFIXE    ";
            }   
            if(isset($_POST["passwordCb"])){
                $prep[] = "`password`";
                $tab .= "PASSWD ";
            }
            if(isset($_POST["siteCb"])){
                $prep[] = "`siteWeb`";
                $tab .= "SITE   ";
            }
            if(isset($_POST["fonctionCb"])){
                $prep[] = "`fonction`";
                $tab .= "Fx ";
            }
        }//ELSE
    
    // This line glues the pieces of the $prep array back together
    $prep = implode(',', $prep);
    
    require("db_action.php");   //Require in the database connection.
    $bd = db_open();
    $data = db_select($prep,  $_POST["username"]); //Envoie des variables à afficher et du Username pour le SELECT
    
    echo "'$tab'";
    echo "'$data'";    ?> 
    

    For your part 2 error, you have to assign the return of the mysql_query into a variable and pass that to mysql_fetch_array. You don’t just pass it the query string. Try this:

    function db_select($prep, $username){
            $username = mysql_real_escape_string($username);
            $querycon = "SELECT $prep FROM info_compte WHERE username = '$username'";
            $response = mysql_query($querycon);
            if(!$response){
                echo "Il n\'y a aucun '$username' dans la base de données";
                $response = "";
            }
            else{
                    while ($row = mysql_fetch_array($response, MYSQL_ASSOC))
                        foreach($row as $item)
                        {
                            echo $item.' ';
                        }
                    }
    
            return $response;   
    }//db_select
    

    UPDATE:

    Note as well as the large addition for part 1, I’ve removed the single quotes around $prep in you SQL statement in part 2.

    Read up on isset() but also, you can consider using array_key_exists(). I’m not sure on the relative performance comparison of the two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem at a high level: We have two business applications. App1 inputs
I used pole display(E POS) in my POS c# application.I have two major problem
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I actually have two questions regarding the same problem but I think it is
Ok I have two modules, each containing a class, the problem is their classes
I am wondering how you would approach this problem I have two Taxrates that
So. I have a problem where I have two versions of GCC on a
I am working on a business problem in C#.NET. I have two classes, named
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping
The problem: I often have to update two or more repositories: One for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.