I need a little help with this code please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

I need a little help with this code please

Post by kalidG »

Hello, i've writen this code to insert some data into a datbase and it didn't work and didn't display any error i don't know why
here's the code (i am sure i missing something tell me if found anything):

Code: Select all

 
if(isset($_POST['submit'])){//On test si l'utilisateur a cliqué sur le boutton reserver
 
        $validation = 0;//test d'erreur
    //Recuperation de tout les variable
        $civilite = $_POST['civilite'];
        $nom = $_POST['nom'];
        $prenom = $_POST['prenom'];
        $email = $_POST['email'];
        $adr = $_POST['adr'];
        $cpostale = $_POSt['cpostale'];
        $ville = $_POST['ville'];
        $pays = $_POST['pays'];
    //Test de validation
    if(($civilite =="") ||($nom =="") || ($prenom =="") ||($email =="") || strpos($email, '@') === false){
        /*Rq: on a utilisé le '===' operateur en php parceque si en utilise seulemnt le '==' la fontion strpos peut retourner "" 0 ou bien true/false mais avec '===' on ai sure que cette fonction va retouner true/false boolean pour plus d'informations voir documentation URL: --http://www.php.net/manual/en/function.strpos.php-- */ 
                $validation = 1;
        }else{
            $validation =0;
        }
    if($validation == 0){
        $insert_query = "INSERT INTO clients ( civilite, nom, prenom, adresse, cpostale, ville, pays, num_sem, type_appart, email ) VALUES('{$civilite}', '{$nom}', '{$prenom}', '{$adr}', '{$cpostale}', '{$ville}', '{$pays}', '{$num_semaine}', '{$str}', '{$email}' )" ;
                                    
    $insert = mysql_query($insert_query) or die("Erreur d'insertion de client" . mysql_error());                            
    //Mise a jour de disponibilité
    $dispos = mysql_query("SELECT{$dispo} FROM dispos WHERE num_semaine = {$num_semaine}") or die("Erreur de selection de nombre" . mysql_error());
    $tab = mysql_fetch_array($dispos);
    $nbr_dispo = $tab[$dispo]; 
    $nbr_dipo--;
    $update = mysql_query("UPDATE dispos SET {$dispo} = {$nbr_dipo}") or die("Erreur de mise a jour" . mysql_error());
    }else{
        $succe =0;
    }
        
    }//Fin de if(isset($_POST['submit']))
 
ps: this code assume that connection to the database is done also datbase selection
and i am sorry coments are in french i didn't have time to translate it
Thank you for ur help,
Khaled
jeetu2009
Forum Newbie
Posts: 2
Joined: Sun Dec 27, 2009 11:28 am

Re: I need a little help with this code please

Post by jeetu2009 »

i think there is some minor mistake plz try this code on specified line
line 11 $cpostale = $_POST['cpostale'];
line:22 insert_query = "INSERT INTO clients ( civilite, nom, prenom, adresse, cpostale, ville, pays, num_sem, type_appart, email ) VALUES('$civilite', '$nom', '$prenom', '$adr', '$cpostale', '$ville', '$pays', '$num_semaine', '$str', '$email' )" ;
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: I need a little help with this code please

Post by kalidG »

Nope Sorry it doesn't work :banghead: it is driving me crazy i am sure i am missing something
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: I need a little help with this code please

Post by kalidG »

I fixed all the code but i still have this one error in mysql:

this is the code:

Code: Select all

 
$update = mysql_query("UPDATE dispos SET " .  $dispo . " = " . $nbr_dispo . " WHERE num_semaine = " .  $num_semaine ,$conn) or die("Erreur de mise a jour" . mysql_error());
 
:oops: i can't find where is the error:
here's the message:
Erreur de mise a jourYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= WHERE num_semaine =' at line 1
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: I need a little help with this code please

Post by kalidG »

lool :lol: this kind a funny isn't i figured it out it is some variable issue :oops: :P
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

Re: I need a little help with this code please

Post by mellowman »

:drunk:
Post Reply