Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <code>isset()</code> function checks if a variable actually exists. Currently you are trying to access variables that may not exist, hence the errors.</p> <pre><code>&lt;?php $prep = array(); $tab = ''; if(!isset($_POST['username'])) echo 'Nom d\'utilisateur manquant'; if(isset($_POST["userCb"]) &amp;&amp; isset($_POST["suffixeCb"]) &amp;&amp; isset($_POST["fonctionCb"]) &amp;&amp; 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'"; ?&gt; </code></pre> <p>For your part 2 error, you have to assign the return of the <code>mysql_query</code> into a variable and pass that to <code>mysql_fetch_array</code>. You don't just pass it the query string. Try this:</p> <pre><code>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 </code></pre> <p>UPDATE:</p> <p>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.</p> <p>Read up on <code>isset()</code> but also, you can consider using <code>array_key_exists()</code>. I'm not sure on the relative performance comparison of the two.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload