Jump to content

Recommended Posts

Hi Everybody,

I am a very beginner in PHP,

Please find my first script below:

I created a html form and with this php script I would like to send it by mail:

 

So far I have the code below:

I also marked the "problem code" in bold and orange to make it more clear..

So the issue is  that the value of $cursusid need to be looked up in a datbase and the return value of this query (kolumn cursus)

needs to be send also with by email..

 

Please let me know if something is not clear and already a real THANK YOU for all your help

 

Kindly regards

Koen

 

 

 

 

-----------------------------------------------------------------------

 

<?php

if(isset($_POST['email'])) {

 

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "xx@xx.be";

$email_subject = "XyZ - Inschrijvingsformulier Cursussen";

 

function died($error) {

// your error code can go here

echo "Gelieve terug te keren en de gegevens te vervolledigen of te wijzingen.<br /><br />";

echo $error."<br /><br />";

die();

}

 

// validation expected data exists

if(!isset($_POST['naam']) ||

!isset($_POST['voornaam']) ||

!isset($_POST['adres']) ||

!isset($_POST['postcode']) ||

        !isset($_POST['woonplaats']) ||

!isset($_POST['telefoon']) ||

!isset($_POST['Alg_voorwaarden']) ||

!isset($_POST['email'])) {

died('Gelieve terug te keren en de gegevens te vervolledigen of te wijzingen.');

}

 

$naam = $_POST['naam']; // not required

$voornaam = $_POST['voornaam']; // not required

$adres = $_POST['adres']; // not required

$postcode = $_POST['postcode']; // not required

$woonplaats = $_POST['woonplaats']; // not required

$telefoon = $_POST['telefoon']; // not required

$gsm = $_POST['gsm']; // not required

$email_from = $_POST['email']; // required

$geboorteplaats = $_POST['geboorteplaats']; // not required

$geboortedatum = $_POST['geboortedatum']; // not required

$opleiding = $_POST['opleiding']; // not required

$andereopleiding = $_POST['andereopleiding']; // not required

$beroep = $_POST['beroep']; // not required

$opmerkingen = $_POST['opmerkingen']; // not required

$Alg_voorwaarden = $_POST['Alg_voorwaarden']; // not required

$bedrag_voorschot = $_POST['bedrag_voorschot']; // not required

$overschrijving_datum = $_POST['overschrijving_datum']; // not required

$overschrijving_naam = $_POST['overschrijving_naam']; // not required

 

 

$cursusid = $_POST['cursusid'];

 

// extra Koen

 

 

$con = mysql_connect("localhost","xxx","xxx");

 

mysql_select_db("naturopathica_b", $con);

 

$result = mysql_query("SELECT cursus FROM cursussen where ID=$cursusid")or die("dit Error: ".mysql_error());

$array = mysql_fetch_assoc($result);

echo gettype($array['cursus']);

 

 

mysql_close();

 

//

 

 

$error_message = "";

$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

  if(!eregi($email_exp,$email_from)) {

  $error_message .= 'Ongeldig emailadres.<br />';

}

 

  if(strlen($error_message) > 0) {

  died($error_message);

  }

$email_message = "Inschrijving cursus .\n\n";

 

 

function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}

 

$email_message .= "Naam: ".clean_string($naam)."\n";

$email_message .= "Voornaam: ".clean_string($voornaam)."\n";

$email_message .= "Adres: ".clean_string($adres)."\n";

$email_message .= "Postcode: ".clean_string($postcode)."\n";

$email_message .= "Woonplaats: ".clean_string($woonplaats)."\n";

$email_message .= "Telefoon: ".clean_string($telefoon)."\n";

$email_message .= "GSM: ".clean_string($gsm)."\n";

$email_message .= "E-mail: ".clean_string($email_from)."\n";

$email_message .= "Geboorteplaats: ".clean_string($geboorteplaats)."\n";

$email_message .= "Geboortedatum: ".clean_string($geboortedatum)."\n";

$email_message .= "Hoogst behaalde opleiding: ".clean_string($opleiding)."\n";

$email_message .= "Naschoolse opleiding: ".clean_string($andereopleiding)."\n";

$email_message .= "Beroep: ".clean_string($beroep)."\n";

$email_message .= "Opmerkingen: ".clean_string($opmerkingen)."\n";

$email_message .= "Aanvaarden van Algeme voorwaarden: ".clean_string($Alg_voorwaarden)."\n";

$email_message .= "Bedrag in voorschot: ".clean_string($bedrag_voorschot)."\n";

$email_message .= "Datum van overschrijving: ".clean_string($overschrijving_datum)."\n";

$email_message .= "Naam van rekeninghouder: ".clean_string($overschrijving_naam)."\n\n\n\n";

 

$email_message .= "CursusID : ".clean_string($cursusid)."\n";

 

 

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

 

 

 

 

?>

<!-- include your own success html here -->

 

<p>Wij danken u voor uw inschrijving op één van onze cursussen van Naturopathica.

 

  <?

}

?>

 

<html>

<head>

<script type="text/javascript">

<!--

function delayer(){

    window.location = "http://www.naturopathica.be/"

}

//-->

</script>

</head>

<body onLoad="setTimeout('delayer()', 5000)">

<p>Deze pagina zal automatische terug keren naar de website van Naturopathica over 5 seconden!</p>

</p>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/168633-beginner-help-needed-select-from/
Share on other sites

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.