PHP mail form not getting fields from html - php

I am working on a website and I am having trouble getting a PHP mail script to send the contents of my form to an email. It is for the registration of students for a club. The link where you can view the current form is http://trhs-snowriders.com/register.htm and I would appreciate any help from anyone with experience with mail scrips and making sure they get delivered.
I own the server so I can make any tweaks that may be necessary
The Mail is being sent but is usually in the spam folder. The other problem I am having is the php script is not getting the values from the html form... Here is the html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<html>
<head>
<title>Timberlane Snowriders Registration</title>
<META http-equiv="last-modified" content="Module 3-1, 2010-12-16"/>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"/>
<!--Begin Custom JavaScript Form Validator-->
<script type="text/javascript">
function valbutton(thisform)
{
var l=document.forms["registrationForm"]["lastName"].value;
var f=document.forms["registrationForm"]["firstName"].value;
if (l==null || l=="")
{
alert("Last Name must be filled out!");
return false;
}
if (f==null || f=="")
{
alert("First Name must be filled out!");
return false;
}
if (document.registrationForm.level.selectedIndex==0)
{
alert("Please select your Skiing/Boarding ability!");
document.registrationForm.level.focus();
return false;
}
myOption = -1;
for (i=thisform.emergency.length-1; i > -1; i--) {
if (thisform.emergency[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select Yes or No");
return false;
}
myOption2 = -1;
for (i=thisform.consent.length-1; i > -1; i--) {
if (thisform.consent[i].checked) {
myOption2 = i; i = -1;
}
}
if (myOption2 == -1) {
alert("You must select Yes or No");
return false;
}
myOption3 = -1;
for (i=thisform.procedure.length-1; i > -1; i--) {
if (thisform.procedure[i].checked) {
myOption3 = i; i = -1;
}
}
if (myOption3 == -1) {
alert("You must select Yes or No");
return false;
}
thisform.submit();
}
</script>
<!--End custom JavaScript Form Validator-->
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
image1 = new Image();
image1.src=images/return_dark.gif;
image3 = new Image();
image3.src=images/prices_dark.gif;
image4 = new Image();
image4.src=images/members_dark.gif;
image5 = new Image();
image5.src=images/gallery_dark.gif;
image6 = new Image();
image6.src=images/fitness_dark.gif;
image7 = new Image();
image7.src=images/contact_dark.gif;
image8 = new Image();
image8.src=images/calendar_dark.gif;
image9 = new Image();
image9.src =images/emergency_dark.gif;
// End -->
</script>
</head>
<body background="images/silver-diamond-plate.jpg" link="black" vlink="blue" alink="red" marginheight="0" marginwidth="0" topmargin="0" bottommargin="0">
<table border="0" cellspacing="0" cellpadding="0">
<tr><td width="1280" height="768">
<table align="center" width="1280" height="768" border="0" cellpadding="1" cellspacing="2" align="left">
<tr>
<td rowspan="10" width="250" height="760" align="center" valign="top" background="images/pats_sidebar.jpg" title="Night view of Pat's Peak">
<a href="index.htm" onmouseover="image1.src='images/return_dark.gif';" onmouseout="image1.src='images/return.gif';">
<img name="image1" src="images/return.gif" border="0"/ title="Return to Snowriders"></a>
<a href="register.htm" onmouseover="image2.src='images/registration_dark.gif';" onmouseout="image2.src='images/registration.gif';">
<img name="image2" src="images/registration.gif" border="0"/ title="Registration"></a>
<a href="prices.htm" onmouseover="image3.src='images/prices_dark.gif';" onmouseout="image3.src='images/prices.gif';">
<img name="image3" src="images/prices.gif" border="0"/ title="2010 Prices"></a>
<a href="members.htm" onmouseover="image4.src='images/members_dark.gif';" onmouseout="image4.src='images/members.gif';">
<img name="image4" src="images/members.gif" border="0"/ title="Members"></a>
<a href="gallery.htm" onmouseover="image5.src='images/gallery_dark.gif';" onmouseout="image5.src='images/gallery.gif';">
<img name="image5" src="images/gallery.gif" border="0"/ title="Photo Gallery"></a>
<a href="fitness.htm" onmouseover="image6.src='images/fitness_dark.gif';" onmouseout="image6.src='images/fitness.gif';">
<img name="image6" src="images/fitness.gif" border="0"/ title="Getting in Shape"></a>
<a href="contact.htm" onmouseover="image7.src='images/contact_dark.gif';" onmouseout="image7.src='images/contact.gif';">
<img name="image7" src="images/contact.gif" border="0"/ title="Contact Us"></a>
<a href="calendar.htm" onmouseover="image8.src='images/calendar_dark.gif';" onmouseout="image8.src='images/calendar.gif';">
<img name="image8" src="images/calendar.gif" border="0"/ title="Contact Us"></a>
<a href="faq.htm" onmouseover="image9.src='images/question_dark.gif';" onmouseout="image9.src='images/question.gif';">
<img name="image9" src="images/question.gif" border="0"/ title="Frequently Asked Questions"></a>
<a href="emergency.htm" onmouseover="image10.src='images/emergency_dark.gif';" onmouseout="image10.src='images/emergency.gif';">
<img name="image10" src="images/emergency.gif" border="0"/ title="Emergency"></a>
</tr></td>
<tr>
<td colspan="2" width="1030" height=226 rowspan="1" colspan="1" align="center" valign="top">
<img src="images/registration.jpg" title="Snowriders main banner"</td>
<tr>
<td bgcolor=silver colspan="2" width="1030" height="100" align="center" valign="middle">
<font face="arial" color=red size="6"><b>Status:</b></font></p>
<font face="arial" color=navy size="5"><b>We are currently registering members for 2011- 2012.<br/>Check the members listing here:</b></p></font>
</td>
</tr>
<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1" colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=7 color=black></p> <center>Registration is first-come, first-served.<br/>Complete the following SIX steps: </center></p></font>
<font face="Comic Sans MS" size=6 color=black>
<blockquote><ol type="decimal" start="1">
<li>Print and fill out the "Emergency Contact Form."</li>
<li>Read the "Warning and Consent Agreement."</li>
<li>Read the "Prices and Procedures sheet."</li>
<li>Fill in and submit the following form:<br/>
(This form will generate an e-mail, that will automatically be sent)</p></li>
</ol></blockquote>
</font></td>
</tr>
<td colspan="2" width="100%" rowspan="1" align="center" valign="top">
<form name="registrationForm" action="form2email.php" method="post" enctype="text/plain">
<input type="hidden" name="email" value="formsender#trhs-snowriders.com" />
<input type="hidden" name="redirect" value="http://trhs- snowriders.com/registercomplete.html#regcom" />
<center>
<table border="2" cellpadding="3" cellspacing="2" bgcolor="gray">
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Student's Last Name:</b></font> <input type="text" name="lastName" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Student's First Name:</b> <font> <input type="text" name="firstName" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Mother's Last Name (if different)</b></font> <input type="text" name="mother" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>Father's Last Name (if different)</b></font> <input type="text" name="father" align="left" size="50"/></td>
</tr>
<tr>
<td align="right"><font face="Comic Sans MS" size="4"><b>What is your skiing/boarding ability?</b></font>
<select name="level">
<option selected> (please choose)</option>
<option>I've never skied/boarded before</option>
<option>I've had a few lessons and I can stop and turn</option>
<option>I can ski/board on easy slopes</option>
<option>I can ski/board on more challenging slopes</option>
<option>I can do it all!!</option>
</select>
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have filled in, printed, and signed the "Emergency Contact" form.</b></font>
<input type="radio" name="emergency" value="Yes" /> Yes
<input type="radio" name="emergency" value="No" />No
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the "Warning and Consent Agreement."</b></font>
<input type="radio" name="consent" value="Yes" /> Yes
<input type="radio" name="consent" value="No" />No
</tr>
<tr>
<td align="right" ><font face="Comic Sans MS" size="4"><b>I have read and understand the "Prices and Procedures Sheet."</b></font>
<input type="radio" name="procedure" value="Yes" /> Yes
<input type="radio" name="procedure" value="No" />No
</tr>
<tr>
<td col span="2" align="center"><font face="Comic Sans MS" size="4">
<b>Is there something I need to know that isn't included in this form?</b></font>
<br>
<textarea name="extrastuff" rows="5" cols="60"></textarea></td></tr>
<tr><td colspan="2">
<center><input type="SUBMIT" value="Submit" onclick="valbutton(registrationForm);return false;" /></center>
</td></tr>
</table></form>
</td>
</tr>
<td background="images/opacity1.JPG" colspan="2" width="1030" height="300" rowspan="1" colspan="1" align="left" valign="top"><font face="Comic Sans MS" size=6 color=black></p>Once you have submitted the form online, please do the following:</p>
<blockquote><ol type="decimal" start="5">
<li>Write a check for $50 to <i><b>"Timberlane" or "TRHS"</b></i></p>
This check is <u>NON-REFUNDABLE</u> unless the bus is filled and we can replace your seat with someone from the waiting list.</p></li>
<li>Have your student bring the printed "Emergency Contact Form" and the signed check to Mr. Rugoletti in Room 114 or place it in his mailbox in the front office.</p>
Forms and checks may also be mailed to:
<blockquote><blockquote><blockquote><blockquote><blockquote>
Timberlane Regional High School<br/>
C/O Steven Rugoletti<br/>
36 Greenough Road<br/>
Plaistow, NH 03865
</blockquote>
</ol>
<font face="Comic Sans MS" size="4" color=navy>Snowriders is a Timberlane Regional High School sponsored activity. The National Ski Patrol "Resonsibility Code," in addition to school rules and polices, available in the Timberlane student handbook, will be in effect at all times. Failure to abide by these policies may result in loss of time on the slopes, removal of one's lift ticket, suspension from the group, and possibly removal from the group.
</font></td>
</tr>
</table>
<font face="Times New Roman" size="4" color=black><b>
<SCRIPT
LANGUAGE="JavaScript">
<!-- Javascripts resource by Hypergurl!!
http://www.hypergurl.com -->
<!-- hide script begin
var m = "Page updated " + document.lastModified;
var p = m.length-8; document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("</center>");
// End --> </SCRIPT>
</b></font>
</td></tr></table>
</body>
</html>
And here is the processReg.php file
<?php
//change settings here
$your_email = "formsender#trhs-snowriders.com";
$your_smtp = "mail.trhs-snowriders.com";
$your_smtp_user = "formsender+trhs-snowriders.com";
$your_smtp_pass = "passwordhere";
$your_website = "http://trhs-snowriders.com";
require("phpmailer/class.phpmailer.php");
//get contact form details
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$url = 'registercomplete.html#regcom';
//start phpmailer code
$ip = $_SERVER["REMOTE_ADDR"];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$response = "Date: " . date("d F, Y h:i:s A",time()+ 16 * 3600 - 600);
$response .= "IP Address: " . $ip;
$response .= "User-agent:" . $user_agent;
$response .= "----------------------";
$response .= "\n\n";
$response .= "Last Name: " . $_REQUEST["lastName"] . "\n";
$response .= "First Name: " . $_REQUEST["firstName"] . "\n";
$response .= "Mothers Last Name: " . $_REQUEST["mother"] . "\n";
$response .= "Fathers Last Name: " . $_REQUEST["father"] . "\n";
$response .= "Riding Ability: " . $_REQUEST["level"] . "\n";
$response .= "Emergency: " . $_REQUEST["emergency"] . "\n";
$response .= "Consent: " . $_REQUEST["consent"] . "\n";
$response .= "Procedure: " . $_REQUEST["procedure"] . "\n";
$response .= "Extra Stuff: \n";
$response .= $_REQUEST["extrastuff"];
$mail = new PHPmailer();
$mail->SetLanguage("en", "phpmailer/language");
$mail->From = $your_email;
$mail->FromName = $your_website;
$mail->Host = $your_smtp;
$mail->Mailer = "smtp";
$mail->Password = $your_smtp_pass;
$mail->Username = $your_smtp_user;
$mail->Subject = "New Snowriders Registration";
$mail->SMTPAuth = "true";
$mail->Body = $response;
$mail->AddAddress($your_email,"$your_website");
$mail->AddReplyTo($email,$name);
if (!$mail->Send()) {
echo "<p>There was an error in sending mail, please try again at a later time</p>";
echo "<p>".$mail->ErrorInfo."</p>";
} else {
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
$mail->ClearAddresses();
$mail->ClearAttachments();
?>
Thanks in advance for all help that can be contributed.

You can't do anything in your script to solve this. In this day and age, you need a properly configured mailserver. This entails implementing (at least) the following correctly:
Proper reverse DNS entry for the mail server
SPF
Domainkeys & DKIM
Also make sure that the mailserver disables open relay, isn't listed in any of the DNSBLs and doesn't host any "spamming" lists. Once your mailserver is configured correctly, it'll take a few days (weeks?) for the major email providers to realize that you aren't an evil spammer.
OTOH, if the mailserver config isn't in your hands, move to a setup that has all these.

Your mail script isnt the problem unless it is not sending it at all. what you should check is the IP address it is sending it from. there are alot of IP addresses that have been blacklisted. therefore they treat your email as spam.
Check here-> http://network-tools.com/default.asp?prog=sbl
or here-> http://whatismyipaddress.com/blacklist-check

As said above, change the headers you send with the email. You may have to set it as your website. By default it could be something random like
s12290318823-host112390823#host.com
this will definitely get your mail sent into the spam folder

Related

$_POST return an array

I have a recent issue with a $_POST.
When I write :
print_r($_POST['nb_acces']);
I get :
1
Which is the value I wrote in the form.
But if I write :
$nb_acces = $_POST['nb_acces'];
print_r($nb_acces )
I get :
Array ( [nb] => 0 )
It was working before, and now I don't understand what happens. Could it be from a server configuration or something ?
EDIT :
My input :
<form id='sous_paiement' name='sous_paiement' method='post' action='commande_enregistre_test.php?ecole=<?php echo $id_ecole; ?>'>
<input id='nb_acces' name='nb_acces' style='width:90px;border:1px solid black;padding-left:4px;text-align:center;' />
Yes if I use $_POST['nb_acces'] I can echo the value. Though I wish to check the value to have an integer and avoid injection.
The way I get this array is the point I don't understand. I have only one input.
Could it come from my checking JavaScript function (sorry for french words, I remove here any non digit characters and calculate some prices) :
function filtre_saisie() {
var input_acces = document.getElementById("nb_acces");
var nb_acces = input_acces.value.replace(/[^0-9]/g, '');
input_acces.value = nb_acces;
var prix_unitaire = calcul_prix_unitaire(nb_acces);
var prix_total = calcul_prix_total(nb_acces);
document.getElementById("div_prix_unitaire").innerHTML = prix_unitaire;
document.getElementById("div_prix_total").innerHTML = prix_total;
}
Could it be this replace ?
EDIT 2 ----------------------------------
Well the whole form :
<form id='sous_paiement' name='sous_paiement' method='post' action='commande_enregistre_test.php?ecole=<?php echo $id_ecole; ?>'>
<div class="div_categories">
<p style='margin:0;padding:3px;padding-left:60px;'>Indiquez le <strong>nombre d'accès</strong> que vous souhaitez acheter :</p>
</div>
<br />
<div id="erreur_nb_acces" style="color:red;"><br /></div>
<table style='border-collapse:collapse;'>
<tr style='font-weight:bold;border:1px solid #eee;background-color:white;'>
<td style='width:200px;padding-left:10px;'>Nombre d'accès</td>
<td style='width:100px;padding-left:10px;padding-right:10px;'><input id='nb_acces' name='nb_acces' type="text" style='width:90px;border:1px solid black;padding-left:4px;text-align:center;' /></td>
</tr>
</table>
<br />
<table style='border-collapse:collapse;'>
<tr style='border:1px solid #eee;background-color:white;border-bottom:1px solid #999;'>
<td style='width:200px;padding-left:10px;'>Prix par accès</td>
<td style='width:100px;padding-left:10px;padding-right:10px;text-align:right;'><div id='div_prix_unitaire' style='display:inline;'>-</div> €</td>
</tr>
<tr style='font-weight:bold;border:1px solid #999;background-color:white;'>
<td style='width:200px;padding-left:10px;'>PRIX TOTAL</td>
<td style='width:100px;padding-left:10px;padding-right:10px;text-align:right;'><div id='div_prix_total' style='display:inline;'>-</div> €</td>
</tr>
</table>
<div style='width:190px;margin-top:5px;'>
Consulter les tarifs</span>
</div>
<div style="clear:both;"></div>
<br /><br />
<div class="div_categories">
<p style='margin:0;padding:3px;padding-left:60px;'>Choisissez votre <strong>mode de paiement</strong> :</p>
</div>
<br /><br />
<table class="tab_mode_paiement" style="border-collapse:collapse;">
<tr>
<td>
<input id='paiement_cb' name='mode_paiement' value='5' class='eleves' type='radio' checked="checked" style="cursor:pointer" />
</td>
<td style="font-weight:bold;padding-right:80px;border-right:1px solid #999;">
<label for='paiement_cb' style="cursor:pointer">
<img src="../images/ic_cb.jpg" style="float:left;display:inline;padding-right:10px;" /> Carte bancaire
</label>
</td>
<td style="padding-left:40px;">
<!--<input id='paiement_paypal' name='mode_paiement' value='3' class='eleves' type='radio' style="cursor:pointer" />-->
</td>
<td style="font-family:arial;font-size:20px;padding-right:120px;">
<!--<label for='paiement_paypal' style="cursor:pointer">
<span style="color:rgba(0,3,128,1)">Pay</span><span style="color:rgba(0,158,210,1)">Pal</span>
</label>-->
</td>
<td>
<input id='paiement_virement' name='mode_paiement' value='1' class='eleves' type='radio' style="cursor:pointer" />
</td>
<td style="font-weight:bold;">
<label for='paiement_virement' style="cursor:pointer">
Par virement bancaire
</label>
</td>
</tr>
<tr>
<td colspan="2" style="border-right:1px solid #999;">Recevez vos accès immédiatement</td>
<td colspan="4" style="padding-left:90px;">Accès disponibles après réception du paiement</td>
</tr>
</table>
<br /><br /><br />
<input id='enregistrer' name='enregistrer' value='Enregistrer la commande' type='button' onclick='verif_sous_paiement();' style='width:300px;height:40px;' />
<br /><br />
<br />
</form>
And my Javascript :
<script>
function ouvrirPopUp_tarifs() {
window.open ('tarifs.php', 'tarifs', config='height=370, width=760, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}
var tab_responsables = new Array();
var tab_acces_responsables = new Array();
var nb_responsables = 0;
function initialiser_filtre_saisie() {
setInterval("filtre_saisie()", 200);
}
function filtre_saisie() {
var input_acces = document.getElementById("nb_acces");
var nb_acces = input_acces.value.replace(/[^0-9]/g, '');
input_acces.value = nb_acces;
var prix_unitaire = calcul_prix_unitaire(nb_acces);
var prix_total = calcul_prix_total(nb_acces);
document.getElementById("div_prix_unitaire").innerHTML = prix_unitaire;
document.getElementById("div_prix_total").innerHTML = prix_total;
}
function verif_sous_paiement() {
filtre_saisie();
var nb_acces = document.getElementById("nb_acces").value;
if (nb_acces == 0) {
document.getElementById("erreur_nb_acces").innerHTML = "Veuillez indiquer un <strong>nombre d'accès</strong>.";
document.getElementById('nb_acces').focus();
}
else {
document.getElementById('sous_paiement').submit();
}
}
</script>
Seems my whole code afraid everybody -.-
You are missing the type="text" attribute in your input, even the browser asumes that's a text, this might cause you some problems;
<input type="text" id='nb_acces' name='nb_acces' .......... />
Also, seems like you're replace anything that starts with a number, like 1 with a empty value, that's why you get a 0:
var nb_acces = input_acces.value.replace(/\d/g, '')
Well, I saw the message of someone who told me to check with var_dump, and it helped me to figure now why there is this issue. I don't know why this message has been erased as it helped me a lot. Thanks to who posted it.
If someone has the same issue, but I know it comes from an old and probably bad server configuration, to use $nb_acces and $_POST['nb_acces'] generates a conflict. Don't use the same name. That's all -.-

php/ajax form not sending info

I almost have it but I am missing something. The form is being sent and the row is being created but there is not data. It is blank (both the email and the database). I know it is something simple I am missing but I cannot figure it out.
There is no errors, the form disappears like it is supposed to. I am getting an email but there is no userdata in it. It creates a row in the database, but again there is no data being put in the row.
If anyone can look at my code below and tell me what I am missing to make the inputed info be seen, I would sure appreciate it.
I have searched and searched and tried different things but I cannot get it to send the info.
AJAX_Quote.php
<?php
include_once('class/class_email.php');
$connect = mysqli_connect("localhost","admin","password","database");
$FName = $_POST['Form_FName'];
$LName = $_POST['Form_LName'];
$Email = $_POST['Form_Email'];
$Company = $_POST['Form_Company'];
$Number = $_POST['Form_Number'];
$Comments = $_POST['Form_Comments'];
$EID = $_POST['eid'];
//$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;";
//$R_GetEquipment = mysql_query($SQL_GetEquipment, $Link);
//$row = mysql_fetch_assoc($R_GetEquipment);
$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;";
$result = mysqli_query($connect,$SQL_GetEquipment);
$row = mysqli_fetch_assoc($result);
$EmailBody = "$FName $LName has requested a quote from NAPE on Item $EID\n
Information on quote request: \n
Name: $FName $LName \n
Email: $Email \n
Company: $Company \n
Number: $Number \n
Comments: $Comments \n
\n
Information Requested for: {$row['itemname']}\n
The URL to {$row['itemname']} is: http://www.domain.com/new-product.php?Item=$EID
\n
Click to send a quote now:\n
http://www.domain.com/Admin/send-quote.php?id=$EID ";
$e = new email();
//First value is the URL of your server, the second the port number
$e->set_server( 'mail.domain.com', 26);
//First value is your username, then your password
$e->set_auth('noreply#domain.com', 'nape112233');
//Set the "From" setting for your e-mail. The Name will be base64 encoded
$e->set_sender( 'Quote Requested', 'noreply#domain.com' );
//for one recipient
$send_to = array('email#gmail.com');
//you may also specify multiple recipients by creating an array like this:
//$send_to = array('foo1#localhost.local', 'foo2#localhost.local', 'foo3#localhost.local');
$subject = 'Quote Request from NAPE';
$body = "$EmailBody";
if( $e->mail($send_to, $subject, $body, $headers) == true )
{
//message was received by the smtp server
//['last'] tends to contain the queue id so I like to save that string in the database
echo 'last: '.htmlspecialchars($e->srv_ret['last']).'';
}else{
//something went wrong
echo 'all: '.nl2br(htmlspecialchars($e->srv_ret['all'])).'';
echo 'full:'.nl2br(htmlspecialchars($e->srv_ret['full'])).'';
}
mysqli_query($connect,"INSERT INTO users (`fname`,`lname`,`email`,`company`,`number`)
VALUES ('$FName','$LName','$Email','$Company','$Number')");
?>
My form code
<form id="contact" name="contact" action="#" method="post" style="width:600px">
<br />
<table width="80%">
<tr>
<td width="36%">*First Name:</td>
<td width="3%"> </td>
<td width="61%">
<input type="text" id="Form_FName" name="Form_FName" />
</td>
</tr>
<tr>
<td width="36%">*Last Name:</td>
<td width="3%"> </td>
<td width="61%">
<input type="text" id="Form_LName" name="Form_LName" />
</td>
</tr>
<tr>
<td width="36%">Company Name:</td>
<td width="3%"> </td>
<td width="61%">
<input type="text" id="Form_Company" name="Form_Company" />
</td>
</tr>
<tr>
<td>*Your E-Mail:</td>
<td> </td>
<td>
<input type="text" id="Form_Email" name="Form_Email" />
</td>
</tr>
<tr>
<td width="36%">*Phone Number:</td>
<td width="3%"> </td>
<td width="61%">
<input type="text" id="Form_Number" name="Form_Number" />
</td>
</tr>
<tr>
<td width="36%" h>Comments:</td>
<td width="3%"> </td>
<td width="61%">
<textarea id="Form_Comments" name="Form_Comments" cols="25" rows="3"></textarea>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="36%" align="center" colspan="3">
<button id="send">Request Quote</button>
</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td width="100%" colospan="3">
<b><?php echo $itemname; ?></b>
<br />
<br /> Manufacturer: <?php echo $manufactuer;?>
<br /> Model: <?php echo $model;?>
<br /> Category: <?php echo $category;?>
<br />
</td>
</tr>
</table>
</form>
</div>
<!-- basic fancybox setup -->
<script type="text/javascript">
$(document)
.ready(function () {
$(".modalbox").fancybox();
$("#contact").submit(function () {
return false;
});
$("#send").on("click", function () {
{
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>Your request has been sent...</em>");
$.ajax({
type: "POST",
url: "AJAX_Quote.php",
data: $("#idForm").serialize(),
success: setTimeout(function () { parent.$.fancybox.close(); }, 2000)
});
}
});
});
</script>
The name of your form inputs is of the format name="Form_FName" but in your PHP you refer to them as $FName = $_POST['fname'];. The correct PHP would be $FName = $_POST['Form_FName'];
Also I suggest escaping your input fields to avoid SQL injection. Check out mysqli_real_escape_string.
http://php.net/manual/en/mysqli.real-escape-string.php

Error when inserting data into table in sql using php form

i'm creating asset database system (just an offline system, not connected to internet) that will show all assets list. on the list, i can click on any asset to view the details. also i'm manage to update the details or delete the asset. but when it goes to asset record parts, it give an error on inserting record to asset using a form.
here is my record add form. and i'm also wanna make machine id visible under MACHINE ID field in the form, but i did't know yet how to put the data there.
for inserting record, its will capture machine id on rekod_add.php ( record add) url address from asset table to passing into rekod_tab table.
here is my record add page ( rekod_add.php )
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<?php
$con=mysqli_connect("localhost","root","admin","exa");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin = $_POST['id_mesin'];
$query = "SELECT * FROM asset WHERE id_mesin ='".$id_mesin."'";
$result = mysqli_query($con,$query);
$rows = mysqli_fetch_array($result);
?>
<table width="733" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="rekod_add_ac.php">
<table width="709" border="0" align="center">
<tr>
<th width="23" scope="col">MACHINE ID</th>
<th colspan="2" scope="col">DATE</th>
<th width="68" scope="col">TIME</th>
<th width="175" scope="col">RECEIVE CALL BY</th>
<th width="97" scope="col">CURRENT METER</th>
<th width="90" scope="col">LAST METER</th>
<th width="136" scope="col">J.SHEET NO</th>
</tr>
<tr>
<td> </td>
<td colspan="2"><input name="tarikh_rekod" type="text" id="tarikh_rekod" size="15" /></td>
<td><input name="time" type="text" id="time" size="10" maxlength="9" /></td>
<td><input type="text" name="call_by" id="call_by" /></td>
<td><input name="meter_semasa" type="text" id="meter_semasa" size="15" /></td>
<td><input name="meter_last" type="text" id="meter_last" size="15" /></td>
<td><input name="rujukan" type="text" id="rujukan" size="10" /></td>
</tr>
<tr>
<td> </td>
<th width="81">PROBLEM</th>
<th width="5">:</th>
<td colspan="3"><textarea name="masalah" id="masalah" cols="55" rows="5"></textarea></td>
<th colspan="2" rowspan="2"><p>REMARK</p>
<p>
<textarea name="remark" cols="30" rows="6" id="remark"></textarea>
</p></th>
</tr>
<tr>
<td> </td>
<th>SOLUTION</th>
<th>:</th>
<td colspan="3"><textarea name="solution" id="solution" cols="55" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="8" align="right"><?php echo "<input type='hidden' value='" . $rows['id_mesin'] . "' name='id_mesin'>"; echo "<input type='submit' value='Add Record'>";?></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
mysqli_close($con);
?>
</body>
</html>
here is my rekod_add_ac.php
<?php
session_start();
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
print_r($_POST);
$id_mesin=$_POST['id_mesin'];
$tarikh_rekod=$_POST['tarikh_rekod'];
$time=$_POST['time'];
$call_by=$_POST['call_by'];
$meter_semasa=$_POST['meter_semasa'];
$meter_last=$_POST['meter_last'];
$rujukan=$_POST['rujukan'];
$masalah=$_POST['masalah'];
$solution=$_POST['solution'];
$remark=$_POST['remark'];
$rekod_in="INSERT INTO rekod_tab ( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last, rujukan, masalah, solution, remark) VALUES ( $'id_mesin', $'tarikh_rekod', $'time', $'call_by', $'meter_semasa', $'meter_last', $'rujukan', $'masalah', $'solution', $'remark')";
$result=mysqli_query($con, $rekod_in);
if($result){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL' align='middle'>";
echo "</form></th>";
}
else {
echo "Data error, please recheck before submit.";
echo "<BR>";
echo "Click back to add record.";
echo "<BR>";
echo "<form action='rekod_add.php?id=$id_mesin' method='post'>";
echo "<td><input type='hidden' value='$id_mesin' name='id_mesin'>";
echo "<input type='submit' value='Back'></td>";
echo "</form>";
echo "<th><form>";
}
mysqli_close($con);
?>
</body>
</html>
after user done inserting record details, the form will add the record on rekod_tab table including machine id ( id_mesin ) which automatically capture from url like i said before.
but the result is error. when inserting detail manual in sql, its work. can anyone help me?
here my error result.
sorry for my bad english.
Try INSERT query like this
$rekod_in="INSERT INTO rekod_tab
( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last,
rujukan, masalah, solution, remark)
VALUES ( '$id_mesin', '$tarikh_rekod', '$time', '$call_by', '$meter_semasa',
'$meter_last', '$rujukan', '$masalah', '$solution', '$remark')";

Dynamically enable and disable DIV via MySQL

Last night I was trying to figure out how I can how I can dynamically enable and disable span#txtCaptchaDiv on my contact form at the very bottom, above the submit button.
So I added a new field to MySQL, called captcha where I wanted to 1 to show and 0 to hide
So if I add 1 to field captcha the following code will show on my form.php
<label for="code">Write code below > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label><!-- this is where the script will place a copy of the code for validation: this is a hidden field -->
<input type="text" name="txtInput" id="txtInput" size="30" />
If I add 0 to field captcha the captcha area will be blank on my form.php.
Can you guy help me out please?
here is my index.php code I currently have:
<?php
require_once("/config/database.php");
$con = mysql_connect($config["db_server"],$config["db_user"],$config["db_pass"]);
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email FORM</title>
</head>
<body>
<div style="width: 550px; text-align: center;">
<span style="filter:alpha(opacity=60); opacity:.6; padding-left: 10px;"><br />
<?php
$data = mysql_query("SELECT * FROM formrelated")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
Print " ".$info['welcomemsg'] . "";
?>
</span></div>
<form id="form1" name="form1" method="post" action="submit.php" onsubmit="return checkform(this);">
<table width="454" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="123">Name</td>
<td width="325">
<input name="name" type="text" />
</td>
</tr>
<tr>
<td height="21">Address</td>
<td><input name="adress" type="text" /></td>
</tr>
<tr>
<td height="21"> </td>
<td><input name="address2" type="text" /></td>
</tr>
<tr>
<td height="21">Email</td>
<td><input name="email" type="text" /></td>
</tr>
<tr>
<td height="21">Tel</td>
<td><input name="email" type="text" /></td>
</tr>
</table>
<!--- captcha code here--->
<center>
<table width="454" height="122" border="0" cellspacing="0" cellpadding="0" background="reCAPbg.png">
<tr>
<td height="73" colspan="2" align="center" valign="middle"><label for="code"><span id="txtCaptchaDiv" style="color:#333; font-size:18px;"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label></td>
<td width="136" rowspan="2"> </td>
</tr>
<tr>
<td width="145"> type the code here:</td>
<td width="173" height="47" align="center"><input type="text" name="txtInput" id="txtInput" size="20" /></td>
</tr>
</table>
</center>
<!--- captcha code ends here--->
<input name="Submit" type="button" value="submit" />
</form>
<script type="text/javascript">
//Generates the captcha function
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("txtCaptchaDiv").innerHTML = code;
</script>
<script type="text/javascript">
function checkform(theform){
var why = "";
if(theform.txtInput.value == ""){
why += "- Security code should not be empty.\n";
}
if(theform.txtInput.value != ""){
if(ValidCaptcha(theform.txtInput.value) == false){
why += "- Security code did not match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>
</body>
</html>
This will work for you... enjoy!
<?PHP
$query = mysql_query("SELECT captcha FROM formrelated WHERE id = '1'");
while ($row = mysql_fetch_assoc($query)) {
$captchathis = $row['captcha'];
if ($captchathis == "1") {
echo "YOUR HTML CODE HERE";
}
else {
echo "BLANK";
}
}
?>
Try it like this
<?PHP
if($mysqlResult['captcha'] === 1)
{
echo $myHtml;
}
?>
Where $mysqlResult is an array with the result from the query, $mysqlResult['captcha']is the value of the row captcha from your query and $myHtml is that HTML code you just showed on your answer.
Good luck! ;)
Reffer to
http://php.net/manual/en/
EDIT:
http://www.php.net/manual/en/language.types.array.php ( Array type on the manual )
http://www.php.net/manual/en/control-structures.if.php ( If control structure on the manual )
http://www.php.net/manual/en/ref.mysql.php ( MySQL native functions. deprecated. Preffer MySQLi )
http://www.php.net/manual/en/book.mysqli.php ( MySQLi extension )
http://www.php.net/manual/en/book.pdo.php ( PDO native php class )
Another answer to explain the basic construct of IF logic.
Suppose i have some condition i want to meet to do something; in this case, the following logic
SHOW my form with the basic inputs
IF condition 'captcha = 1' is met, SHOW input2 (captcha)
SHOW rest of the HTML
it would be like this in PHP
<?PHP
echo $myFormWithBasicInputs;
if($captcha === 1)
{
echo $input2;
}
echo $restOfHTML;
?>
In your case, $myFormWithBasicInput and $restOfHTML is already outputed as HTML. All you want to do is inject an PHP code in it to check if some condition is matched. It will be like this
<html>
<!-- MY FORM WITH BASIC INPUTS -->
<?PHP
$captcha = $mySQLresult['captchaRow'];
if($captcha === 1)
{
?>
<!-- CAPTCHA INPUT HERE -->
<?PHP
}
?>
<!-- REST OF HTML -->
</html>
be aware that this is an workaround with example code.
<?PHP
$mysql_query = "SELECT captcha FROM formrelated";
$captcha = $mySQLresult['captchaRow'];
if($captcha === 1)
{
?>
<!--- CODE---->
<table width="454" height="122" border="0" cellspacing="0" cellpadding="0" background="reCAPbg.png">
<tr>
<td height="73" colspan="2" align="center" valign="middle"><label for="code"><span id="txtCaptchaDiv" style="color:#333; font-size:18px;"></span><!-- this is where the script will place the generated code -->
<input type="hidden" id="txtCaptcha" /></label></td>
<td width="136" rowspan="2"> </td>
</tr>
<tr>
<td width="145"> type the code here:</td>
<td width="173" height="47" align="center"><input type="text" name="txtInput" id="txtInput" size="20" /></td>
</tr>
</table>
<?PHP
}
?>
<!-- REST OF HTML -->

Javascript add MySQL data when checkbox is ticked

I am currently using this javscript and PHP code
<script>
function add(total)
{
form2.thetotal.value = document.forms["form1" + total].total.value;
}
</script>
<form name="form2">
<table width="800" border="0" cellspacing="0" cellpadding="10" style="position:fixed; z-index:-999; background-color:#FFF;">
<tr bgcolor="#eeeeee">
<td> </td>
<td colspan="2" width="50%"><strong>Total: </strong><input type="text" name="thetotal" id="thetotal" size="20" value="0" /></td>
<td colspan="2" width="50%"><strong>VAT:</strong> </td>
</tr>
<tr bgcolor="#eeeeee">
<td width="5%"> </td>
<td width="20%"><strong>Invoice Number</strong></td>
<td width="35%"><strong>Company</strong></td>
<td width="20%"><strong>Date</strong></td>
<td width="20%"><strong>Total</strong></td>
</tr>
</table>
</form>
<form name="form1">
<table width="800" border="0" cellspacing="0" cellpadding="10">
<?php
$sql="SELECT * from billing_pdf_archive order by invoice_number ASC ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
$counter++;
$sql2="SELECT * from customer where sequence = '".$result["customer_sequence"]."' ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
$result2=mysql_fetch_array($rs2);
$sql3="SELECT * from reseller where sequence = '".$result["reseller_sequence"]."' ";
$rs3=mysql_query($sql3,$conn) or die(mysql_error());
$result3=mysql_fetch_array($rs3);
if($result["customer_sequence"] != '0')
{
$company = $result2["company"];
}
elseif($result["reseller_sequence"] != '0')
{
$company = '<strong>Reseller: </strong>'.$result3["company"];
}
$total = $result["total"];
echo '<tr>
<td width="5%"><input type="checkbox" name="check" id="check" onclick=\'add('.$total.');\' /></td>
<td width="20%">'.$result["invoice_number"].'</td>
<td width="35%">'.$company.'</td>
<td width="20%">'.$result["datetime"].'</td>
<td width="20%">£'.$result["total"].'</td>
</tr>';
}
?>
</table>
</form>
so as you can see it is selecting from the MySQL database and i am trying to make it so when one of the checkboxes is ticked it adds the total into the "thetotal" text field (in form 2) but it is just leaving that box as zero - any ideas on what i could do?
You did not specify the total field for form 1, then it raised javascript error, it wont work.
Check it out
<script>
function add(total)
{
form2.thetotal.value = total + parseFloat(document.form1.formtotal.value);
}
</script>
<form name="form1">
<!-- replace field name formtotal with anything that you want-->
<!-- replace field value with anything that you get from your mysql result-->
<input type="text" name="formtotal" id="formtotal" value="10" />
</form>
Here is how you can do it (assuming total is int and not float):
<script>
function add(total, this_chk_bx)
{
//(if its float, use `parseFloat` instead of `parseInt`)
if(this_chk_bx.checked==true){
//add if its checked
var tot_1 = parseInt(form2.thetotal.value);
form2.thetotal.value = tot_1+parseInt(total);
}
else{
//subtract if its unchecked
}
}
</script>
.
in your php, you have to send the checkbox like this:
onclick=\'add('.$total.', this);\'
.

Categories