1

I'm making a php page that inserts values written by the user into an MySql table. I'm trying to get the textbox values sent to the php code portion and can't do it.

I currently have this php function:

function insertion($Alias,$Password,$Nom,$Adresse,$Telephone,$CatPrefere){
       try{
        $insert = $mybd->prepare("CALL insertClients(?,?,?,?,?,?,?)",array(PDO::ATTR_CURSOR, PDO::CURSOR_FWDONLY));
        $insert->bindParam(1,$Alias);
        $insert->bindParam(2,$Password);
        $insert->bindParam(3,$Nom);
        $insert->bindParam(4,$Adresse);
        $insert->bindParam(5,$Telephone);
        $insert->bindParam(6,0);
        $insert->bindParam(7,$CatPrefere);
        $insert->execute();
       }
       catch(PDOException $e){ 
       echo('Erreur insertion dans table client: '.$e->getMessage());
       exit();
       }

And this Javascript function (notice the last line here, i call my php function):

function inscription() {
    var Alias = document.getElementById("alias").value;
    var Password = document.getElementById("password").value;
    var Nom = document.getElementById("nom").value;
    var Adresse = document.getElementById("adresse").value;
    var Telephone = document.getElementById("telephone").value;
    var Categories = document.getElementById("categorie");
    var CatPrefere = Categories.options[Categories.selectedIndex].value;
    <?php insertion(Alias,Password,Nom,Adresse,Telephone,CatPrefere);?>
}

How do i send all thoses variables to my php function?

If this is all correct then something else might not work in my spaghetti code.

Also i'm working on a single .php file named Inscription.php.

4
  • PHP runs on the server in order to generate the page. Javascript runs inside your user's browser (the client side). The only way to use Javascript variables is to pass them with a new request (likely using AJAX) Commented Apr 30, 2018 at 3:50
  • 1
    You might want to learn ajax to do that. Here is a similar question Commented Apr 30, 2018 at 3:50
  • If you can or do use jQuery this would be considerably easier. Is that the case? Commented Apr 30, 2018 at 5:46
  • PDO also supports named placeholders so you can pass in an associative array to the execute call and do it all in one shot. This is often a lot less messy than you have here because if you remove an argument you don't need to renumber a bunch of things. Commented Apr 30, 2018 at 5:47

1 Answer 1

0

I think that is not possible. What you can do it is change the URL to get values in $_GET.

Look that stack overflow topic: send javaScript variable to php variable

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.