Jump to content

Recommended Posts

Hi Guys, actually I'm doing hard with this code.

the fact is that Im inserting data (name, phone number, nss) and  im doing a select to get the id number where nss is like $nss (.

I don`t know why I can`t receive data, i think the fact is that all the code is inside an if statement) But that is why im here guys. 

In adittion I tryed to get the max id in order to print into mail function. But I couldn't . This is my code...

 

 

 

************************************************************************************************************
 

//Database connection done perfectly

$mysqli = mysqli_connect( "****", "***", "***", "***");

 

 

************************************************************************************************************
 

// Im working with bots and the intent received is this, in addition i get variables correctly.


if (intent_recibido('registro')){
    $name = obtener_variables()['name'];
    $lastname = obtener_variables()['lastname'];
    $gender = obtener_variables()['gender'];
    $day_of_birth = obtener_variables()['day_of_birth'];
    $email = obtener_variables()['email'];
    $address = obtener_variables()['address'];
    $phone = obtener_variables()['phone'];
    $nss = obtener_variables()['nss'];

    

************************************************************************************************************
 

//here im inserting the variables in the correct order. The database is getting the values correctly too.


        $sql = ("INSERT INTO pacient (name,lastname,gender,day_of_birth,email,address,phone,nss)
            VALUES ('$name','$lastname','$gender','$day_of_birth','$email','$address','$phone','$nss') ");

************************************************************************************************************
            
   // this is the answer of the bot, which tell us that it has sent an email to confirm account.


enviar_texto("$name $lastname, le hemos enviado por correo un mail para confirmar su registro, el valor de nss es $nss y su id es $id");

 

 

************************************************************************************************************

//here is the section when im going to select the id from the table, where the nss number is equal to the nss variable number that i've putted (but idk if the insert is done at this point....

 
$result = $mysqli->query("SELECT `id` FROM `pacient` WHERE `nss` = $nss ");
 $finalId = mysqli_fetch_assoc($result);
 $id = $finalId['id'];

************************************************************************************************************
//in this section we are sending a mail with the information that i've putted. 

For example i'm getting the mail, the name and lastname correctly from my function (which gets the parameters and turn the information in readable characters to php)

 

 $to = $email;
 $cc = "email@email.com";
$subject = "Registro AlergoPED";
$message = "Estimado $name $lastname, gracias por registrarte en AlergoPed, su numero de identificacion es $id ";
$headers = 'From: webmaster@darystortas.com' . "\r\n" .
    'Reply-To: webmaster@darystortas.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
mail($to, $subject, $message, $headers);

}

************************************CODE DONE ***********************************************************

 

So guys, Idk what is happening here, I tryed lot of things but when im get the email I dont get the id value..... I think is because the insert hasn't been completed while the if is open.....

In adition I wanto to ask you guys if somebody knows how to get correctly the data from this code... 

Firstly I was trying to get the max id from my table and then plus 1 to increase the number. and in that order put the id by myself or atleast get the value in that way.

I tryed closely, but i finish getting the array value.. I going to show my code...

 

function obtener_Id(){
global $mysqli;
$resultado_oId = $mysqli ->query("SELECT TOP 1 'id' FROM
'pacient' ORDER BY RowID DESC ")
$id_sacada = mysqli_fetch_assoc($resultado_oId);
$id_enLaMano = $id_sacada['id'];
return $id_enLaMano;
//$id_dinamica = $id_enLaMano + 1;
//return $id_dinamica;
}

Link to comment
https://forums.phpfreaks.com/topic/310449-selecting-data-inserted-in-the-same-if/
Share on other sites

First please use the code icon (<>) and select PHP so it formats your code to make is easier to read. Second you probably should be using PHPMailer for your email. It is much easier to use and gives you better control. Finally to debug this you need to make sure you have errors enabled but your insert does not contain the field 'id'. Where do you add that to the record?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.