Select Option form. Mysql database help D:

Ok so I have to do this page : http://pedago.cegepoutaouais.qc.ca/media/maube/stages2011/journaux.asp

And I have the code for the form : on my file module05.php

[php]

Classer par <SELECT NAME="Classe">
Date Étudiant Superviseur en ordre Ascendant Descendant [/php]

So now I have to show the informations in my database. But I don’t even know where to start… I’ve looked for hours on the internet and I can’t find what I want :frowning:

I have this php code too but, I don’t even know if I’m doing the right thing…

[php]<?php
$con = mysql_connect(“localhost”,“root”,"");
mysql_select_db(“journal”, $con);
$sql = “SELECT * FROM journal”;
$result=mysql_query($sql,$con);

if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

$VarClasse=$_POST[“Classe”];

// Requête permettant d’aller chercher dans la base de donnée le numéro de lot écrit dans le formulaire
$result = mysql_query(“SELECT * FROM journal WHERE journal=’” .$VarClasse."’");

// Affiche la table (html) pour y rentrer les enregistrements de la base de donnée
echo "

";

// Affiche les enregistrements de la base de donnée
while($row = mysql_fetch_array($result))
{
echo “

”;
echo “”;
echo “”;
echo “”;
echo “”;
}
echo “
Date Étudiant Superviseur
” . $row[‘DateJournal’] . “” . $row[‘NomEtu’] . “” . $row[‘NomSup’] . “
”;

mysql_close($con);
?>
[/php]

I cleaned up your form, you need to close your option tags (they are not one-sided) and you also had and extra in there…

<form method="POST" action="module05.php">
	
    Classer par 
    <select name="Classe">
    	<option value="Date">Date</option>
        <option value="Etudiant">Étudiant</option>
        <option value="Superviseur">Superviseur</option>
    </select>
    en ordre
    <select name="ASCDESC">
        <option value="Ascendant">Ascendant</option>
        <option value="Descendant">Descendant</option>
    </select>
    
</form>

I also cleaned up the php, you’ll notice a comment towards the top that has a query in it. From what I could tell that query is pointless because you never use it later in the file.
At a glance it all looks fine. I add an or die() to the end of the mysql_query, this will give you an error message if the query is unsuccessful
[php]

<?php $con = mysql_connect("localhost","root",""); mysql_select_db("journal", $con); /* // This query is worthless, it can be deleted $sql = "SELECT * FROM journal"; $result=mysql_query($sql,$con); */ if (!$con){ die('Could not connect: ' . mysql_error()); } $VarClasse = $_POST["Classe"]; // Requête permettant d'aller chercher dans la base de donnée le numéro de lot écrit dans le formulaire $result = mysql_query("SELECT * FROM journal WHERE journal='" .$VarClasse."'") or die("ERROR: " . mysql_error()); // Affiche la table (html) pour y rentrer les enregistrements de la base de donnée echo " "; // Affiche les enregistrements de la base de donnée while($row = mysql_fetch_array($result)){ echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Date Étudiant Superviseur
" . $row['DateJournal'] . "" . $row['NomEtu'] . "" . $row['NomSup'] . "
"; mysql_close($con); ?>

[/php]

Let us know if there are any errors

Oh I see thank you ^^ I didn’t know that, now I just have to figure out the rest I guess… :confused:

Geuh yeah now I have Undefined index: Classe in C:\wamp\www\Programmation\prog\module05.php on line 52

undefined index means that it has no value…

if…
[php]$_POST[‘Classe’];[/php]
does not have a value then it is undefined and it will let you know…

If it’s ok that it is undefined then you should ignore it (when you publish the page find a way to not show that error ie. error_reporting(0) ), otherwise you need to look to see why no values are being passed to it.

Ah, ok I taught that by doing that it would go get what I have selected in the options. Like when we write in a form

It should but there is an error somewhere in your code that is preventing that…

Sponsor our Newsletter | Privacy Policy | Terms of Service