Home>

tried to make data from the form to the site (API) through CURL, but apparently something does not understand in this library, even though there are many examples on the Internet. Can you tell how to transfer them? Thank you in advance < 3.

code with form:

&lt;
H2 Class= "Popup-title" &gt;
Certificate of learning period &lt;
/h2 &gt;
        &Lt;
Form class= "reference-form" action= "" &gt;
            &Lt;
DIV Class= "Reference SELECT" &GT;
                &Lt;
SELECT CLASS= "GROUPS" NAME= "GROUPS" ID= "GROUPS" &GT;
                    &Lt;
Option value= "Default" disabled selected &gt;
Select Group &LT;
/Option &GT;
                    &Lt;
? php.
                    $ Groups= LoadGroups ();
                    Foreach ($ Groups AS $ Group) {
                    ? &Gt;
                    &Lt;
OPTION ID= "&LT;
?= $ group ['id']? &gt;
"Value="&lt;
?= $ group ['id']? &gt;
"&Gt;
&Lt;
?= $ Group ['Name']? &gt;
&Lt;
/Option &GT;
                    &Lt;
? php}? &gt;
                &Lt;
/SELECT &GT;
            &Lt;
/div &gt;
            &Lt;
DIV Class= "Reference SELECT" &GT;
                &Lt;
Select class= "Obiturients" name= "Obiturients" id= "obiturients" &gt;
                    &Lt;
Option value= "Default" disabled selected &gt;
FULL NAM;
/Option &GT;
                &Lt;
/SELECT &GT;
            &Lt;
/div &gt;
            &Lt;
Button class= "Reference-BTN" &gt;
Create &LT;
/Button &gt;
        &Lt;
/Form &GT;
    &Lt;
/div &gt;

AJAX code

$ ('. reference-link'). Magnificpopup ();
    $ ('. Groups'). Change (Function () {
    Let Gid= $ (this) .val ();
    Let Form= $ (this) .Closest ('Form');
    $.ajax ({
        URL: 'DATA.PHP',
        Method: 'Post',
        Data: {GID: GID}
    }). DONE (FUNCTION (OBITURIENT) {
        Console.log (Obiturient);
        OBITURIENT= JSON.PARSE (Obiturient);
        Form.find ('[Name= "Obiturients"] "). Empty ();
        Obiturient.Foreach (FUNCTION (OBITURIENT) {
            form.find ('[Name= "Obiturients"]'). Append ('&lt;
Option value= '+ obiturient.id +' &gt;
'+ Obiturient.o_fam +' '+ Obiturient.o_name +' '+ Obiturient.o_otch +' &lt;
/Option &GT;
')
        })
    })
})
})

data.php

&lt;
? php.
Require_ONCE 'DB.PHP';
If (ISset ($ _ post ['gid'])) {
    Global $ obiturient;
    $ Connection= New MySqli ('Localhost', 'root', 'root', 'rups');
    $ STMT= $ Connection-&GT;
Query ("Select * from` Obiturient` Where `group_id`=". $ _post ['gid']);
    $ OBITURIENT= $ STMT-&GT;
fetch_all (mysqli_assoc);
    Echo JSON_ENCODE ($ Obiturient);
}
FUNCTION LOADGROUPS () {
    Global $ groups;
    $ Connection= New MySqli ('Localhost', 'root', 'root', 'rups');
    $ STMT= $ Connection-&GT;
Query ("SELECT * from` Groups` ");
    $ groups= $ STMT-&GT;
fetch_all (mysqli_assoc);
    RETURN $ GROUPS;
}

you need to convey exactly

Append ('&lt;
Option value= '+ obiturient.id +' &gt;

CURL itself:

$ CURL= CURL_INIT (); //Session Initialization
CURL_SETOPT ($ CURL, CURLOPT_URL, 'HTTP: //Diplom/example.php'); //Url site to which we appeal
CURL_SETOPT ($ CURL, CURLOPT_HEADER, 1); //Display headlines
CURL_SETOPT ($ CURL, CURLOPT_POST, 1); //Transfer data by POST
CURL_SETOPT ($ CURL, CURLOPT_RETURNTRANSFER, 1); //Now CURL will return to us the answer, and will not lead
curl_setopt ($ curl, curlopt_postfields, //here variables that will be transmitted by the POST method
Array (
'Obiturients'= &gt;
$ _Post ['obiturients'],
));
CURL_SETOPT ($ CURL, CURLOPT_USERAGENT, 'MSIE 5'); //this line as if says: "I'm not a script, I IE5" :)CURL_SETOPT ($ CURL, CURLOPT_REFERER, "http://ya.ru"); //what if there is a repurrant of $ res= curl_exec ($ CURL)
CURL_CLOSE ($ CURL);

From the second box box, but I could not pull out Value according to the examples from the Internet and send this value. Thank you again in advance for your help.

Chet I do not see php code

Jean-Claude2021-05-17 20:32:28

I do not see any curl at all, it's hard to say, it seems fine, if there are no errors of several options: 1) SELECT does not return anything 2) maybe there is no such value in the database table, which comes $ _POST ['GID']

Jean-Claude2021-05-17 20:32:28

Attached CURL, I hope to help find the problem

NesKwi2021-05-17 20:32:28

We will not be able to help, it is most likely somewhere in the variable comes emptiness, you have no check for the correctness of the data, whether $ _post ['...'] begins, returns anything to the database returns that Well, CURL and so on .... the debugger turn on and immediately everything will become clear.

Jean-Claude2021-05-17 20:32:28

Here the screen is what the norms seem to be, but it sends data from two boxes of form, and we only need the meaning of "Value" in the Option, which we have prescribed in Ajax, will be grateful if you would help get this value: 3. Screenshot: yapx.ru/v/msqgs.

NesKwi2021-05-17 20:32:28