/    Sign up×
Community /Pin to ProfileBookmark

Tutorials – Application Form with Php MySQL

Hi there,

I was wondering if any of you knows any good tutorial on how to create an application form with PHP & MySQL.

I did a google search and I found only one that really helped me with my application ([url]http://www.princeton.edu/~daveh/dwphpclass_guide/mysql.html[/url]), but I need some more details (like sending email notification after someone has submitted my application… etc).

Thanks in advance.

P.S. Also, Dreamweaver CS4 Dynamic Development – Lynda.com help me a lot with my application.

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperFeb 16.2010 — What do ya mean by "application form" ? Too generic/vague from my perspective, example would be nice.

But as to email being sent after a form submit (whatever the form) here is a nice tutorial from W3C schools for PHP. After the form is submitted, data from the form lives in $_POST super global associatibe array and use print_r($_POST) to view its contents. Then use the tutorial to send mail, and plugin the proper values. If you want a more advanced email form processing script then use this one and adapt to your code.

If you meant something else, please specify.

-jim
Copy linkTweet thisAlerts:
@rrezeauthorFeb 18.2010 — Dear SrWebDeveloper,

Thanks. You are right... this is what I need:

I have created an application form (apply.php) for the students who registers online and a database (MySQL) which is connected with it.

My application form has fileds like:

Name, Surname, Date of Birth, High School... Write an essay... etc

I want to email automatically (after a student submits the form) two persons - only these fields: Name, Surname and Date of registration.

Also, I tried to put a code in thanks.php file (like this one from W3C):

<?php

if (isset($_REQUEST['email']))

//if "email" is filled out, send email

{

//send email

$email = $_
REQUEST['email'] ;

$subject = $_REQUEST['subject'] ;

$message = $_
REQUEST['message'] ;

mail( "[email protected]", "Subject: $subject",

$message, "From: $email" );

echo "Thank you for using our mail form";

}

else

//if "email" is not filled out, display the form

{

echo "<form method='post' action='mailform.php'>

Email: <input name='email' type='text' /><br />

Subject: <input name='subject' type='text' /><br />

Message:<br />

<textarea name='message' rows='15' cols='40'>

</textarea><br />

<input type='submit' />

</form>";

}

?>

but it didn't work ?

I don't know if I'm clear enough!

Thanks in advance.
Copy linkTweet thisAlerts:
@SrWebDeveloperFeb 18.2010 — "It didn't work" isn't clear either. Need to know what happened, error information and line number if possible. I've already included a tutorial and a commercial script both of which you can view source if you get stuck.

All you did was copy the exact code from the tutorial without making *any* changes at all - it's just example code! You didn't even change the email address to yours to check if you got email. Might want to also switch to $_POST in the production version as $_REQUEST contains cookie, post and get data which might lead to confusion and thus a bit of a security hole. Yes I know its in the tutorial, but the point of the tutorial is not to demonstrate form processing but email.

-jim
Copy linkTweet thisAlerts:
@rrezeauthorFeb 23.2010 — Hi Jim,

Thanks again for your reply.

I tried using PHP Mailer and it works now (thanks God!) with this code:


-------------------------
<?php

require_once("phpMailer/class.phpmailer.php");
require_once("phpMailer/class.smtp.php");
require_once("phpMailer/language/phpmailer.lang-en.php");

$to_name = "Name Surname";
$to = "[email protected]";
$subject = "New user has submitted the application form at ".strftime("%T", time());
$message = "This is a test.";
$message = wordwrap($message,70);
$from_name = "My Name";
$from = "[email protected]";

//PHP SMTP version
$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "mail.mydomain.com";
$mail->Port =25;
$mail->SMTPAuth = false;
$mail->Username = "test";
$mail->Password = "XXXX";

$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body =<<<EMAILBODY


A user named {$name}{$surname} has been registered to MYWEBSITE at {$created}.

EMAILBODY;

$result = $mail->Send();
echo $result ? 'Thanks for your registering... Your information has been recorded in our database.' : 'Error';


?>


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

The only problem is with the fields that are missing in my email notification (name, surname, date).

What do I need to change here in my code to make this work fine:

A user named {$name}{$surname} has been registered to MYWEBSITE at {$created}.

Best.
Copy linkTweet thisAlerts:
@rrezeauthorMar 02.2010 — I still can't figure out how to solve this issue with the email that I'm receiving after someone submits my form.

The email that I'm receiving should have person's name and surname and date of registration. That's all what I need! Why do you think my code is not working on this? Should I put the connection link in thanks.php file or what?

As I described, I have www.domain.com/apply.php form which ridirects users to www.domain.com/thanks.php page (and then I receive automatically an email).
Copy linkTweet thisAlerts:
@rrezeauthorMar 16.2010 — Some help pleaseee...
Copy linkTweet thisAlerts:
@NogDogMar 16.2010 — Where do you define those variables used in the message body? Perhaps you should be using $_POST['name'], $_POST['surname'], etc.?
Copy linkTweet thisAlerts:
@rrezeauthorMar 17.2010 — I tried and this is the result:

parse error, expecting T_STRING' or T_VARIABLE' or `T_NUM_STRING' in C:xampphtdocsserthanks.php on line 35

?
Copy linkTweet thisAlerts:
@NogDogMar 17.2010 — I tried and this is the result:

parse error, expecting T_STRING' or T_VARIABLE' or `T_NUM_STRING' in C:xampphtdocsserthanks.php on line 35

?[/QUOTE]


It's difficult to debug without seeing the offending code.
Copy linkTweet thisAlerts:
@rrezeauthorMar 18.2010 — Here is my [B]apply.php[/B] code:


------------------------------
<?php require_once('Connections/test.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;


case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_
SERVER['QUERY_STRING'])) {

$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

$insertSQL = sprintf("INSERT INTO apply (firstname, lastname, gender, street, city, country, telephone, email) VALUES (&#37;s, %s, %s, %s, %s, %s, %s, %s)",

GetSQLValueString($_POST['firstname'], "text"),

GetSQLValueString($_
POST['lastname'], "text"),

GetSQLValueString($_POST['gender'], "text"),

GetSQLValueString($_
POST['street'], "text"),

GetSQLValueString($_POST['city'], "text"),

GetSQLValueString($_
POST['country'], "text"),

GetSQLValueString($_POST['telephone'], "text"),

GetSQLValueString($_
POST['email'], "text"),

mysql_select_db($database_test, $test);

$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());

$insertGoTo = "thanks.php";

if (isset($_SERVER['QUERY_STRING'])) {

$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

$insertGoTo .= $_
SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $insertGoTo));

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main_template.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>Apply Online</title>

<script src="jquery.ui-1.5.2/jquery-1.2.6.js" type="text/javascript"></script>

<script src="jquery.ui-1.5.2/ui/ui.datepicker.js" type="text/javascript"></script>

<script type="text/javascript">

<!--

function MM_validateForm() { //v4.0

if (document.getElementById){

var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);

if (val) { nm=val.name; if ((val=val.value)!="") {

if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.n';

} else if (test!='R') { num = parseFloat(val);

if (isNaN(val)) errors+='- '+nm+' must contain a number.n';

if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

min=test.substring(8,p); max=test.substring(p+1);

if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.n';

} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.n'; }

} if (errors) alert('The following error(s) occurred:n'+errors);

document.MM_returnValue = (errors == '');

} }

//-->

</script>

<link href="jquery.ui-1.5.2/themes/ui.datepicker.css" rel="stylesheet" type="text/css" />

<!-- InstanceEndEditable -->

<link href="css/all.css" rel="stylesheet" type="text/css" media="all"/>

<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen"/><![endif]-->

<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0

eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

if (restore) selObj.selectedIndex=0;

}

//-->

</script>

</head>

<body>

<?php include("header.php"); ?>

<div id="content-inner">

<div class="side-bar">

<div class="side-nav"><!-- InstanceBeginEditable name="submenu" -->

<ul> </ul>

<!-- InstanceEndEditable --></div>

<div class="text-box">

<h2><!-- InstanceBeginEditable name="title" -->Apply Online<!-- InstanceEndEditable --></h2>

<h3><!-- InstanceBeginEditable name="subtitle" --><!-- InstanceEndEditable --></h3>

<div class="text-holder"><!-- InstanceBeginEditable name="text here" -->

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" onsubmit="MM_validateForm('firstname','','R','lastname','','R','city','','R','telephone','','RisNum','email','R',);return document.MM_returnValue">

<table align="left">

<tr valign="baseline">

<td colspan="2" align="left" nowrap="nowrap"><label>

<h1>Apply Now</h1>

<div align="left">

<input name="app_sort" type="radio" id="app_sort" value="Regular application" checked="checked" />

Regular application

<br />

<input type="radio" name="app_sort" id="app_sort2" value="Transfer application" />

Transfer application<br />

</div>

</label></td>

</tr>

<tr valign="baseline">

<td width="121" align="left" nowrap="nowrap"><strong>First Name:</strong></td>

<td width="493"><input name="firstname" type="text" id="firstname" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>Last Name:</strong></td>

<td><input name="lastname" type="text" id="lastname" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>Gender:</strong></td>

<td><input type="radio" name="gender" id="gender" value="Male" />Male

<input type="radio" name="gender" id="gender2" value="Female" />Female</td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>Street:</strong></td>

<td><input name="street" type="text" id="street" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>City:</strong></td>

<td><input name="city" type="text" id="city" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>Country:</strong></td>

<td><select style="width:195px;" id="country" name="country"><br/>

<option value="">Please choose a country</option>

<option value="Afganistan">Afghanistan</option>

<option value="Algeria">Algeria</option>

<option value="American Samoa">American Samoa</option>

<option value="Andorra">Andorra</option>

<option value="Angola">Angola</option>

<option value="Anguilla">Anguilla</option>

</select></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>Telephone:</strong></td>

<td><input name="telephone" type="text" id="telephone" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left"><strong>E-mail address:</strong></td>

<td><input name="email" type="text" id="email" value="" size="32" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left">&nbsp;</td>

<td><input name="Submit" type="submit" id="Submit" value="Submit" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="left">&nbsp;</td>

<td>&nbsp;</td>

</tr>

</table>

<input type="hidden" name="MM_insert" value="form1" />

</form>

<p>&nbsp;</p>

<!-- InstanceEndEditable --></div>

</div>

</div>

<?php include("footer.php"); ?>

</body>

<!-- InstanceEnd --></html>
-------------------------------------------------





Which directs users to [B]thanks.php[/B] page



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

<?php



require_once("phpMailer/class.phpmailer.php");

require_once("phpMailer/class.smtp.php");

require_once("phpMailer/language/phpmailer.lang-en.php");



$to_name = "Name Surname";

$to = "[email protected]";

$subject = "New user has submitted the application form at ".strftime("%T", time());

$message = "This is a test.";

$message = wordwrap($message,70);

$from_name = "My Name";

$from = "[email protected]";



//PHP SMTP version

$mail = new PHPMailer();



$mail->IsSMTP();

$mail->Host = "mail.mydomain.com";

$mail->Port =25;

$mail->SMTPAuth = false;

$mail->Username = "test";

$mail->Password = "XXXX";



$mail->FromName = $from_name;

$mail->From = $from;

$mail->AddAddress($to, $to_name);

$mail->Subject = $subject;

$mail->Body =<<<EMAILBODY



A user named {$name}{$surname} has been registered to MYWEBSITE at {$created}.



EMAILBODY;



$result = $mail->Send();

echo $result ? 'Thanks for your registering... Your information has been recorded in our database.' : 'Error';



?>
---------------------------------------------------------



Now, everything works fine, except the notification email... I want to receive an email like: A user named [B]Chris Colman[/B] from [B]New York[/B] has been to registered to my website at [B]5:05 pm on Thursday[/B]. and in the body message, how can I receive something like:

Name & Surname: Chris Colman

City: New York

Country: US

Email address: [email][email protected][/email]
Copy linkTweet thisAlerts:
@rrezeauthorApr 02.2010 — Do I have to put <?php require_once('Connections/test.php'); ?> in the beginning of my thanks.php file?

What else, do I need to add?

Many thanks.
Copy linkTweet thisAlerts:
@rrezeauthorApr 14.2010 — I've put this code:

<?php $section = 'myapplication'; ?>

<?php require_once('Connections/test.php'); ?>

in the beginning of my thanks.php page and when I receive notification email ... it still says: "A new user named 'firstname' 'lastname' has been registered...." which means that it's still not working ?

Some help please.
Copy linkTweet thisAlerts:
@barnabaApr 22.2010 — As I understand you need forms which would send contact information and it must be in php and mysql, right? I can suggest you php tutorials. I think this is exactly what you need.
×

Success!

Help @rreze spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...