Can't send checklist to email from html - php

I need to do a simple script with two parts. First one is sending just name, phone number etc. and works perfectly already:
But after it i need to send a checklist to the same email, but still is nothing there.
My html:
<form action="contact.php" method="post" id="form" class="contact-form">
<table style="color: DEB441; font-size: 19px; margin-left: 60px; margin-top: 40px; float: left;">
<tr>
<td><font color="FFFFFF">Imie:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_imie" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Nazwisko:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_nazwisko" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Adres:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_adres" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Telefon</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_telefon" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">E-mail:</td>
<td style="padding:0px">
<textarea style="outline-color: FFFFFF; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_email" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td style="width: 150px;">
<p style="align: left; margin-top: 2px; margin-right: 10px;"><br>
<font style="font-size: 16px;" color="#FFFFFF" align="left">
Wybierz produkty:<br><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Herbatniki w pudelkach <br>
<hr align="left" width="110px"><bt>
<input type="checkbox" name="thenderese" value="thenderese" />Thenderese<br>
<input type="checkbox" name="petipa" value="petipa" />Petipa<br>
<input type="checkbox" name="biscripts" value="biscripts" />Biscripts<br>
</p>
</td>
<td style="width: 150px;">
<p style="width: 250px; align: left;"><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Herbatniki Pakowane pojedynczo<br>
<hr align="left" width="160px">
<input type="checkbox" name="6g" value="g6g" />6g
<input type="checkbox" name="150g" value="g150g" />150g
<input type="checkbox" name="300g" value="g300g" />300g
</p>
</td>
</tr>
<tr>
<td style="width: 200px; margin-right: 250px;">
<p align="left" style="align: left; margin-top:0px;"><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Inne
<hr align="left" width="150px">
<input type="checkbox" name="folia" value="folia">Biscripts opakowane w folie<br>
<input type="checkbox" name="speculoos1" value="speculoos1" />1,5 kg (proszek speculoos)<br>
<input type="checkbox" name="speculoos2" value="speculoos2" />1,1 kg (pokruszony speculoos)<br>
<input type="checkbox" name="krem" value="krem biscripts" />krem biscripts<br>
</p>
</td>
</tr>
</table>
</form>
and my PHP
<?php
$field_imie = $_POST['cf_imie'];
$field_nazwisko = $_POST['cf_nazwisko'];
$field_adres = $_POST['cf_adres'];
$field_telefon = $_POST['cf_telefon'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'serwis#reskomp.pl';
$subject = 'nowe zamowienie '.$field_imie;
$body_message = 'Od: '.$field_imie."\n";
$body_message .= 'Nazwisko: '.$field_nazwisko."\n";
$body_message .= 'Adres: '.$field_adres."\n";
$body_message .= 'Telefon: '.$field_telefon."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Szczegoly zamowienia: '.$field_message;
$thenderese = $_POST['thenderese'];
if ($thenderese != 'Yes') {
$thenderese = 'No';
}
$petipa = $_POST['petipa'];
if ($petipa != 'Yes') {
$petipa = 'No';
}
$biscripts = $_POST['biscripts'];
if ($biscripts != 'Yes') {
$biscripts = 'No';
}
$g6g = $_POST['6g'];
if ($g6g != 'Yes') {
$g6g = 'No';
}
$g150g = $_POST['150g'];
if ($g150g != 'Yes') {
$g150g = 'No';
}
$g300g = $_POST['300g'];
if ($g300g != 'Yes') {
$g300g = 'No';
}
$folia = $_POST['folia'];
if ($folia != 'Yes') {
$folia = 'No';
}
$speculoos1 = $_POST['speculoos1'];
if ($speculoos1 != 'Yes') {
$speculoos1 = 'No';
}
$speculoos2 = $_POST['speculoos2'];
if ($speculoos2 != 'Yes') {
$speculoos2 = 'No';
}
$krem = $_POST['krem'];
if ($krem != 'Yes') {
$krem = 'No';
}
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Zamowienie zostalo przyjete do realizacji.');
window.location = '../herbatniki/index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Blad wysylania wiadomosci. Prosimy o kontakt na adres: coo.maan#gmail.com');
window.location = 'Contacts.html';
</script>
<?php
}
?>
If somebody could help me...
I know that i should use more css, but this is not the reason.

It looks like you have no way to submit your form.
Further, to add your checkbox data to your email message, you can use something like the following.
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
var_dump($_POST);
$message = '';
$message .= sprintf("Name: %s\n", isset($_POST['name']) ? $_POST['name'] : '');
$message .= sprintf("Foo wanted: %s\n", isset($_POST['foo']) ? 'Yes' : 'No');
$message .= sprintf("Bar wanted: %s\n", isset($_POST['bar']) ? 'Yes' : 'No');
var_dump($message);
}
?>
<form method="POST">
Your Name:<input type="text" name="name" /><br />
<input type="checkbox" name="foo" />You want Foo?<br />
<input type="checkbox" name="bar" />You want Bar?<br />
<input type="submit">
</form>
However please research 'email injection in php'.

You need to add the content to $body_message.
Change
$thenderese = $_POST['thenderese'];
if ($thenderese != 'Yes') {
$thenderese = 'No';
}
to
$thenderese = $_POST['thenderese'];
$body_message .= 'thenderese';
if ($thenderese != 'Yes') {
$body_message .= 'No';
}
else {
$body_message .= 'Yes';
}
$body_message .= '/n';
and continue for the rest of your if statements.

Related

how to change php headers on respective website using ajax

contactfrm.php
<?php
// Server side validation
$name = $_POST['name'];
$surname = $_POST['surname'];
$bsubject = $_POST['subject'];
$email= $_POST['email'];
$message= $_POST['message'];
$to = "sample#email.com";
$subject = "Mail From sample 1";
$cc = "sample#email.com";
$txt ="";
$txt .="<html><body>";
$txt .= "<table style='border-collapse: collapse; width: 30%; background: #ddd7d769;'><tr>
<th style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>Name</th>";
$txt .= "<td style=' border: 1px solid #0000004f;text-align: left;padding: 8px;'>".$name."</td></tr>";
$txt .= "<tr><th style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>Surname</th>";
$txt .= "<td style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>".$surname."</td></tr>";
$txt .= "<tr><th style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>Subject</th>";
$txt .= "<td style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>".$bsubject."</td></tr>";
$txt .= "<tr style='background: lightgrey;'><th style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>Email</th>";
$txt .= "<td style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>".$email."</td></tr>";
$txt .= "<tr><th style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>Message</th>";
$txt .= "<td style='border: 1px solid #0000004f; text-align: left; padding: 8px;'>".$message."</td></tr>";
$txt .= "</table>";
$txt .="</body></html>";
$headers = "From: Sample 1 . "\r\n" ;
$headers .= 'Cc: '.$cc . "\r\n";
$headers .= "MIME-Version: 1.0'.PHP_EOL'\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if(!empty($email))
{
mail($to,$subject,$txt,$headers);
$success_output = "Your message sent successfully, We will contact you soon. Thank You";
}
else
{
$error_output = "Something went wrong. Please try again later";
}
$output = array(
'error' => $error_output,
'success' => $success_output
);
// Output needs to be in JSON format
echo json_encode($output);
?>
Contact Form.html
<section id="contact" class="contact">
<div class="container" data-aos="fade-up">
<div class="section-title">
<h2>Contact</h2>
<p>Feel Free to contact</p>
</div>
<div class="row">
<div class="col-lg-5 d-flex align-items-stretch">
<div class="info">
<div class="address">
<a class="skype" href="skype:live:.cid.123456789?chat" target = "_blank"><i class="fa fa-skype" aria-hidden="true"></i></a>
<a class="skype" href="skype:live:.cid.123456789?chat" target = "_blank"><h4>Skype</h4></a>
<p>Click here to message us directly on Skype</p>
</div>
<div class="address">
<a class="whatsapp" href="https://wa.me/+123456789" target="_blank"><i class="fa fa-whatsapp" aria-hidden="true"></i></a>
<a class="whatsapp" href="https://wa.me/+123456789" target="_blank"><h4>WhatsApp</h4></a>
<p>Click here to message us directly on WhatsApp </p>
</div>
<div class="email">
<i class="fas fa-envelope"></i>
<h4>Email:</h4>
<p>sample#email.com</p>
</div>
<div class="phone">
<i class="fa fa-phone" aria-hidden="true"></i>
<h4>Call:</h4>
<p>+123456789</p>
</div>
</div>
</div>
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-stretch">
<form id="contactfrm" onsubmit="validateCaptcha()" method = "POST" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">First Name</label>
<input type="text" name="name" placeholder="Enter Your First Name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" required />
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Surname</label>
<input type="text" class="form-control" placeholder="Enter Your Surname" name="surname" id="surname" data-rule="minlen:4" data-msg="Please enter a valid email" />
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Your Email</label>
<input type="email" class="form-control" name="email" placeholder="example#example.com" id="email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validate"></div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validate"></div>
</div>
<div class="form-group">
<label for="name">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please write something for us" required></textarea>
<div class="validate"></div>
</div>
<div id="captcha">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Captcha" data-rule="required" data-msg="Please Enter the Captcha" id="cpatchaTextBox"/>
</div>
<div class="text-center" id="btnSend"><button type="submit">Send Message</button></div>
<div id="alert"></div>
</form>
</div>
</div>
</div>
</section><!-- End Contact Section -->
ajax script
<script async = "true">
var code;
function createCaptcha() {
document.getElementById('captcha').innerHTML = "";
var charsArray =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#";
var lengthOtp = 6;
var captcha = [];
for (var i = 0; i < lengthOtp; i++) {
var index = Math.floor(Math.random() * charsArray.length + 1);
if (captcha.indexOf(charsArray[index]) == -1)
captcha.push(charsArray[index]);
else i--;
}
var canv = document.createElement("canvas");
canv.id = "captcha";
canv.width = 100;
canv.height = 50;
var ctx = canv.getContext("2d");
ctx.font = "25px Georgia";
ctx.strokeText(captcha.join(""), 0, 30);
code = captcha.join("");
document.getElementById("captcha").appendChild(canv);
}
function validateCaptcha() {
event.preventDefault();
debugger
if (document.getElementById("cpatchaTextBox").value == code) {
// alert("Valid Captcha")
readCap();
}else{
alert("Invalid Captcha. try Again");
createCaptcha();
}
}
function readCap(){
$.ajax({
url: 'contactfrm.php',
type: 'post',
data: $('#contactfrm').serialize(),
dataType: 'json',
success: function( _response ){
var error = _response.error;
var success = _response.success;
console.log(success);
if(error != null) {
$('#alert').html(error);
}
else {
$('#alert').html(success);
$('#btnSend').remove();
}
},
error: function(jqXhr, json, errorThrown){
var error = jqXhr.responseText;
$('#alert').html(error);
}
});
}
</script>
I have 30 different websites with this same contact form at the bottom.
As shown in the image, When I receive an email, it says "Mail From (website Name)"
So, if I have to upload same php for 30 different websites, I'll have to make 30 different php forms with different titles and headers.
How can I add if else loop where I can target respective website and only its header will be displayed. Because right now I have created 10 different 'contactfrm.php' in which I have changed headers to respective website.
Replace this variable
$subject = "Mail From sample 1";
Into this code you will get your solution .
$regexp = "/([\w]{0,}).([\w]{2,3}|[\w]{2,3}.[\w]{2,3})$/";
$url= $_SERVER['SERVER_NAME'];
$input = parse_url($url, PHP_URL_HOST);
preg_match($regexp, $input, $matches);
$subject = "Mail From ".$matches[1]; //out put domain name

Unknown column 'activation_code' in 'field list'

I have a problem with my website of a game called World of Warcraft. In the registration part when I want to register, I skip this error
Unknown column 'activation_code' in 'field list'
I created the account, I can enter the page, but at the time of entering the game it tells me that my account is blocked
Unknown column 'activation_code' in 'field list'
Here is my file Register.php... help me please
> <?php
require_once("".$_SERVER['DOCUMENT_ROOT']."/header.php");
/*generate the code for activate the acccount*/
function random_str($length, $keyspace = '_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$keyspace = str_shuffle($keyspace );
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces []= $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
}
$regcode = random_str(255);
/*
$a = random_str(32);
$b = random_str(8, 'abcdefghijklmnopqrstuvwxyz');
*/
/*END genetare code*/
function encryptpw($user, $pass) {
$user = strtoupper($user);
$pass = strtoupper($user);
return sha1($user.':'.$pass);
}
//store all results from query records
$results = array();
$accexist = 'SELECT * FROM battlenet_accounts WHERE email = "'.$_POST['email'].'"';
//SQL select query
$accexistresult = mysqli_query($dbh, $accexist)or die(mysqli_error($dbh));
//execute SQL statement
$accexistrows = mysqli_num_rows($accexistresult);
// get number of rows returned
if($accexistrows){
while($row = mysqli_fetch_array($accexistresult)){
$results["accexist"] = $row;
}
}
$emailexist = $results["accexist"]["email"];
if(isset($_POST['submit']) AND $emailexist == ""){
$email = strtoupper($_POST['email']);
$expansion = "7";
$bnetindex = "1";
$acclock = "1";
$accunlock = "0";
// Battlenet Password
$bnetpassword = strtoupper(bin2hex(strrev(hex2bin(strtoupper(hash("sha256",strtoupper(hash("sha256", strtoupper($email)).":".strtoupper($_POST['pass']))))))));
// Queries
if($insbnet = 'INSERT INTO battlenet_accounts (email, sha_pass_hash, locked) VALUES ("'.$email.'", "'.$bnetpassword.'", "'.$acclock.'");'){
$insbnetresult = mysqli_query($dbh, $insbnet);
$getaccid = 'SELECT * FROM battlenet_accounts WHERE email = "'.$email.'"';
//SQL select query
$getaccidresult = mysqli_query($dbh, $getaccid)or die(mysqli_error($dbh));
//execute SQL statement
$getaccidrows = mysqli_num_rows($getaccidresult);
// get number of rows returned
if($getaccidrows){
while($row = mysqli_fetch_array($getaccidresult)){
$results["id"] = $row;
}
}
$id = $results["id"]["id"];
$bnetacc = $id;
$username = $bnetacc."#".$bnetindex;
$accpassword = encryptpw($username, $_POST['pass']);
if($insacc = 'INSERT INTO account (username, sha_pass_hash, email, expansion, battlenet_account, battlenet_index, activation_code) VALUES ("'.$username.'", "'.$accpassword.'", "'.$email.'", "'.$expansion.'", "'.$bnetacc.'", "'.$bnetindex.'", "'.$regcode.'")'){
$insaccresult = mysqli_query($dbh, $insacc) or die(mysqli_error($dbh));
//execute SQL statement
$results = array();
$success = '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($email) . '</span>
was created successfully! An email was sent to you with informations on how to activate it.</h3>';
//start the mail() setup
$password = $_POST['pass'];
$youremail = 'noreply#shadowmelt.com';
$subject = 'ShadowMelt Register Confirm';
$message = '<html><head>';
$message .= '</head><body>';
$message .= '<p align="left">Greetings,</p>';
$message .= '<p align="left">You are receiving this email because you register on our Website platform with this email <b>( ' . strtolower($email) . ' )</b>. If you not did this action, please delete this message.</p>';
$message .= '<p align="left">Next, it follows the data for you to Login in-game, however you need to activate your account to be able to play. To activate your Account, please click on next link or copy paste on your browser:</p>';
$message .= '<p align="center"><a style="
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf));
background:-moz-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-webkit-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-o-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-ms-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ededed\', endColorstr=\'#dfdfdf\',GradientType=0);
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
cursor:pointer;
color:#777777;
font-family:Arial;
font-size:15px;
font-weight:bold;
padding:13px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #ffffff;
" href="https://www.shadowmelt.com/register?confreg=' . $regcode . '">Activate Account</a></p>';
$message .= '<p align="left"><b>Login:</b> ' . strtolower($email) . ' <br /><b>Password:</b> ' . $password . '</p>';
$message .= '<p align="left">For more information, how to connect, visit us on our website!</p>';
$message .= '</body></html>';
$headers = 'From: ' . $youremail . "\r\n";
$headers .= 'MIME-Version: 1.0' ."\r\n";
$headers .= 'Content-Type: text/HTML; charset=utf-8' . "\r\n";
$sendto = $email;
mail($sendto, $subject, $message, $headers);
}else{
echo "Insert account error...";
}
}else{
echo "Insert baccount error...";
}
}elseif(isset($_POST['submit']) AND $emailexist != ""){
$accexisterror = '<h3 style="color: red;" align="center">Your Account was not Created! That email <span style="color: white;">'.strtolower($email).'</span> already exists.</h3>';
}
?>
<div class="content">
<div class="container row">
<div id="left-content">
<div class="post_wrap">
<div class="news">
<br>
<br>
<br>
<!-- Main -->
<?php
if(isset($_GET["confreg"]) != ""){
$acclock = "1";
$accunlock = "0";
$confreg = htmlspecialchars($_GET["confreg"]);
$getaccemail = 'SELECT * FROM account WHERE activation_code = "'.$confreg.'"';
//SQL select query
$accemailresult = mysqli_query($dbh,$getaccemail) or die(mysqli_error($dbh));
//execute SQL statement
$accemailrows = mysqli_num_rows($accemailresult);
// get number of rows returned
if($accemailrows){
while($row = mysqli_fetch_array($accemailresult)){
$results["email"] = $row;
}
}
$idaccemail = $results["email"]["email"];
$getacccode = 'SELECT * FROM account WHERE email = "'.$idaccemail.'"';
//SQL select query
$acccoderesult = mysqli_query($dbh,$getacccode);
//execute SQL statement
$acccoderows = mysqli_num_rows($acccoderesult);
// get number of rows returned
if($acccoderows){
while($row = mysqli_fetch_array($acccoderesult)){
$results["storedcode"] = $row;
}
}
$storedcode = $results["storedcode"]["activation_code"];
$getacclock = 'SELECT * FROM battlenet_accounts WHERE email = "'.$idaccemail.'"';
//SQL select query
$acclockresult = mysqli_query($dbh,$getacclock);
//execute SQL statement
$acclockrows = mysqli_num_rows($acclockresult);
// get number of rows returned
if($acclockrows){
while($row = mysqli_fetch_array($acclockresult)){
$results["storedlock"] = $row;
}
}
$storedlock = $results["storedlock"]["locked"];
if(isset($confreg) == $storedcode AND $storedlock == $acclock){
$activacc = 'UPDATE battlenet_accounts SET locked = "'.$accunlock.'" WHERE email = "'.$idaccemail.'"';
//SQL select query
$activaccresult = mysqli_query($dbh,$activacc);
//execute SQL statement
if($activaccresult){
echo '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($idaccemail) . '
</span> was Activated! How to Connect?</h3>';
}else{
echo '<h3 align="center"><span style="color: red;">Your Account: </span><span style="color: white;">' . strtolower($idaccemail) . '
</span> was Not Activated. Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!</h3>';
echo '<script type="text/javascript">alert(" Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!");</script>';
}
}elseif(isset($confreg) == $storedcode AND $storedlock == $accunlock){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">Your account has already been activated.</i></h3>';
echo '<script type="text/javascript">alert("Your account has already been activated.");</script>';
}elseif(isset($confreg) != $storedcode){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">We can not identify this link!</i></h3>';
echo '<script type="text/javascript">alert("We can not identify this link!");</script>';
}else{
echo '<script type="text/javascript">alert("Something was wrong! We do not identify the issue, please contact us.");</script>';
}
}elseif(isset($success)){
echo $success;
}elseif(isset($accexisterror)){
echo $accexisterror;
}else{
?>
<h3 style="font-size:20px;font-weight:bold;text-transform:uppercase;" align="center">Sign-Up for Shadowmelt!</h3>
<hr />
<br />
<br />
<br />
<div style="width: 630px; margin-left: auto; margin-right: auto;"><form style="display: inline;" target="_blank" action=""><input type="hidden" name="shadowmelt" value="1" /><button class="upmenu">ShadowMelt [Legion]</button></form>
<form style="display: inline; margin-left: 20px;" target="_blank" action="http://www.rainandthunder.net/#register"><button class="upmenu">RainAndThunder [Vanilla]</button></form></div>
<br />
<br />
<br />
<hr />
<form action="" method="post" name="reg">
<table style="border-spacing: 30px; border-collapse: separate;" class="form">
<tr>
<td align="right">
E-mail Address:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="email" type="email" maxlength="254" placeholder="Please insert a valid email(1)" required />
</td>
</tr>
<tr>
<td align="right">
Password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass" type="password" maxlength="16" placeholder="Insert a password to use on login" required />
</td>
</tr>
<tr>
<td align="right">
Confirm password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass2" type="password" maxlength="16" placeholder="Insert again your password" required />
</td>
</tr>
<tr>
<td></td>
<td align="center">
<input type="submit" class="sbm" value="Register" name='submit' />
</td>
</tr>
</table>
</form>
<p align="center"><b>ยน</b> <i style="color: yellow;">Is required use a valid email, to activate your Account,
since our system will send you an email with details on how to activate your Account.</i></p>
<?php } ?>
</div>
</div>
</div>
<div id="right-content">
<br>
<img src="images/box.png">
</div>
</div>
</div>
<?php include_once("".$_SERVER['DOCUMENT_ROOT']."/footer.php"); ?>
You just have to add this not existing column:
ALTER TABLE account
ADD activation_code char(64);
either this table column is still missing or you have just spelled it wrong, if necessary check that before you create a new column for nothing

Avoid empty lines in php checkbox

I have html form wherein 7 check box are there. When all the boxes are checked, it is giving good result. Whereas any body gives 3 or 4 check, it shows the result with empty lines in between. It looks very indecent. Any body can suggest the corrective code for that.
the HTML code for the check box:
CONDITIONS: <br />
<input type="checkbox" name="c1" value="Invoice">Invoice <br />
<input type="checkbox" name="c2" value="LR copy">LR copy <br />
<input type="checkbox" name="c3" value="Test Reports">Test Reports<br />
<input type="checkbox" name="c4" value="Draft"> Draft<br />
<input type="checkbox" name="c5" value="Check-list">Check-List <br />
<input type="text" name="c6" placeholder=" Add any" maxlength="25" size="40"><br />
<input type="text" name="c7" placeholder=" Add any clause" maxlength="25" size="40">
the php code for the above check-box:
<html>
<head>
<style type="text/css">
table { margin: 1em 0 0 0; border-collapse: collapse; }
td {margin: 5px 0 0 0;padding: .4em ; border: 0px solid; height: 12px; }
tr td:first-child {font-weight: bold; width: 250px; color: black; height: 10px; font-size: 18px;}
tr td:last-child {width: 450px; color: blue;height: 10px; font-size: 18px; }
p {margin: 5px 0 0 20px; width: 700px; line height: 20px; text-align: justify; font-size:105%;
font-family: Arial, "Lucida Sans Unicode", Verdana, sans-serif;}
#trim {margin: 5px 0 0 20px; width: 700px; line height: 20px; text-align: center; font-size:150%;
font-family: Arial, "Lucida Sans Unicode", Verdana, sans-serif;}
.z{ margin: 5px 0 0 20px; width: 700px;}
.z1{ margin: 5px 0 0 20px; width: 700px;}
</style>
</head>
<body>
<div id="trim">
<b> FORMAT </b>
<hr size="2" noshade>
</div>
<?
$k1 = strtoupper($_REQUEST['k1']);
$k2 = strtoupper($_REQUEST['k2']);
$k3 = strtoupper($_REQUEST['k3']);
$k4 = strtoupper($_REQUEST['k4']);
$k5 = strtoupper($_REQUEST['k5']);
$k6 = strtoupper($_REQUEST['k6']);
$k7 = strtoupper($_REQUEST['k7']);
$k22 = strtoupper($_REQUEST['k22']);
$k23 = strtoupper($_REQUEST['k23']);
$k8 = strtoupper($_REQUEST['k8']);
$k9 = strtoupper($_REQUEST['k9']);
$k10 = strtoupper($_REQUEST['k10']);
$k11 = strtoupper($_REQUEST['k11']);
$k12 = strtoupper($_REQUEST['k12']);
$k13 = strtoupper($_REQUEST['k13']);
$k14 = strtoupper($_REQUEST['k14']);
$k15 = strtoupper($_REQUEST['k15']);
$k16 = strtoupper($_REQUEST['k16']);
$c6 = strtoupper($_REQUEST['c6']);
$c7 = strtoupper($_REQUEST['c7']);
$k19 = strtoupper($_REQUEST['k19']);
$k20 = strtoupper($_REQUEST['k20']);
$k21 = strtoupper($_REQUEST['k21']);
$r1 = strtoupper($_REQUEST['r1']);
$r2 = strtoupper($_REQUEST['r2']);
$r3 = strtoupper($_REQUEST['r3']);
$r4 = strtoupper($_REQUEST['r4']);
$r5 = strtoupper($_REQUEST['r5']);
$r6 = strtoupper($_REQUEST['r6']);
$r7 = strtoupper($_REQUEST['r7']);
$r8 = strtoupper($_REQUEST['r8']);
$r9 = strtoupper($_REQUEST['r9']);
$r10 = strtoupper($_REQUEST['r10']);
$c1 = strtoupper($_REQUEST['c1']);
$c2 = strtoupper($_REQUEST['c2']);
$c3 = strtoupper($_REQUEST['c3']);
$c4 = strtoupper($_REQUEST['c4']);
$c5 = strtoupper($_REQUEST['c5']);
$c8 = strtoupper($_REQUEST['c8']);
$c9 = strtoupper($_REQUEST['c9']);
$c10 = strtoupper($_REQUEST['c10']);
$c11 = strtoupper($_REQUEST['c11']);
$c12 = strtoupper($_REQUEST['c12']);
$c13 = strtoupper($_REQUEST['c13']);
$c14 = strtoupper($_REQUEST['c14']);
$c15 = strtoupper($_REQUEST['c15']);
$c16 = strtoupper($_REQUEST['c16']);
$c17 = strtoupper($_REQUEST['c17']);
$c18 = strtoupper($_REQUEST['c18']);
$c19 = strtoupper($_REQUEST['c19']);
$c20 = strtoupper($_REQUEST['c20']);
$c21 = strtoupper($_REQUEST['c21']);
$c22 = strtoupper($_REQUEST['c22']);
$c23 = strtoupper($_REQUEST['c23']);
$c24 = strtoupper($_REQUEST['c24']);
$c25 = strtoupper($_REQUEST['c25']);
$p1= strtoupper($_REQUEST['p1']);
$p2 = strtoupper($_REQUEST['p2']);
if(empty($k2)){$kk=" "; }else{$kk="(Code: $k2)";}
$html = "<p> <div class='z1'>
<b><u> PROJECT DETAILS </u></b>
<table>
<tr><td> Project Name: </td> <td > $k1 $kk</td></tr>
<tr><td> Purchase Order no:</td> <td > $k3 Dtd: $k4</td></tr>
<tr><td>Total Order Value:</td> <td >$k6 </td></tr>
<tr><td> Materials Ordered </td> <td >$k5 </td></tr>
<tr><td> Supplier Details: </td> <td >$k22 <br /> $k23</td></tr>
</table>
<br /><b><u> DISPATCH CONDITIONS </u></b>
<table>
<tr><td> Shipment from: </td> <td > $k11</td></tr>
<tr><td> Shipment to: </td> <td >$k12 </td></tr>
<tr><td> Dispatch starting date: </td> <td >$k9 </td></tr>
<tr><td> Last date of dispatch: </td> <td >$k10 </td></tr>
<tr><td> Part-Shipment: </td> <td >$r1 </td></tr>
<tr><td> Part-Transshipment: </td> <td > $r2</td></tr>
<tr><td> Transport Charges: </td> <td > $r4</td></tr>
<tr><td> Insurance Charges: </td> <td > $r3</td></tr>
<tr><td> Basis of price: </td> <td > $r5</td></tr>
</table>
<br /><b><u> BANK DETAILS </u></b>
<table>
<tr><td> L/C amount: </td> <td > $k8 <br /> Rs. $k30 </td></tr>
<tr><td> Usance period: </td> <td > $r9 Days from the date of dispatch.</td></tr>
<tr><td> Usance interest: </td> <td>$k15 Days to Supplier A/c. and $k16 Days to Buyer A/c.</td></tr>
<tr><td> Usance interest charges: </td> <td >Not more than $k14 % p.a </td></tr>
<tr><td> L/C Charges: </td> <td > Opening charges to $r7 and discount charges to $r8</td></tr>
<tr><td> Negotiation to be done: </td> <td > within $r10 Days from the date of dispatch.</td></tr>
<tr><td> Place of Expiry: </td> <td > $k21</td></tr>
</table>
<br /><b><u> DOCUMENTS REQUIRED:</u></b>
<ul><li>$c1
</li><li>$c2
</li><li>$c3
</li><li>$c4
</li><li>$c5
</li><li>$c6
</li><li>$c7
</li></ul>
<br /><b><u> L/C CONDITIONS </u></b>
<ul><li>
$c8 </li><li>
$c9 </li><li>
$c10</li><li>
$c11 </li><li>
$c12</li><li>
$c13 </li><li>
$c22 </li><li>
$c23 </li></ul>
<br /><b><u> ADDITIONAL CONDITIONS </u></b>
<ul><li>
$c14 </li><li>
$c15 </li><li>
$c16 </li><li>
$c17 </li><li>
$c18 </li><li>
$c19 </li><li>
$c20 </li><li>
$c21 </li><li>
$c24 </li><li>
$c25 </li><li>
$k19 </li><li>
$k20 </li></ul>
</div></p>";
$html .= "<div class='z'> <hr /> Place: <b>".$p1."</b></div>";
$html .= "<div class='z'> Date: $p2 <div style='float:right;font-size: 12pt'><i> (Authorized Signature ) </i></div></div>";
print($html);
?>
</body>
</html>
You are always echoing all the lines. when some values are empty, there will be just empty line (list item). So you have to check that the values exists. Little example:
<?
$html = '<p>CONDITIONS:</p><ul>';
function echoRow(&$html, $val) {
if (isset($val) && !empty($val))
$html .= '<li>' . $val . '</li>';
}
echoRow($c1);
echoRow($c2);
echoRow($c3);
echoRow($c4);
echoRow($c5);
echoRow($c6);
echoRow($c7);
$html .= '</ul>';
print($html);
?>
This is because when a checkbox is not checked, then its value is not send to server. For example if C1 is not checked, then it is not send in $_POST values. What you can do is check if each of checkbox is set and display only those whose value exits. If you want you can show alternative message for checkbox that is not set. You can do something like this
$html="<ul>";
if(isset($c1))
$html.="<li>$c1</li>"
else
{
//do nothing or show alternative message
$html.="<li>Invoice not selected</li>"
}
// do same for $c2....$c7
$html.="</ul>";
print($html);

Insert and update text into sql

I have a page that seems to work fine other than updating new text to the database. Everytime I hit submit it just takes it back to the original data. Please let me know what is missing for this to successfully query old data and update new data.
if (isset($_POST["submit"]) && $_POST["submit"] == "Update Load")
{
for ($count = 1; $count <= 6; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carriername = mysql_real_escape_string($_POST['carriername']);
$contact = mysql_real_escape_string($_POST['contact']);
$phone = mysql_real_escape_string($_POST['phone']);
$rating = mysql_real_escape_string($_POST['rating']);
$info = mysql_real_escape_string($_POST['info']);
$insert = "UPDATE carrierinfo Set `carriername` = '$carriername', `contact` = '$contact', `phone` = '$phone', `rating` = '$rating', `info` = '$info' WHERE `id` = '$id';";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`contact` ,`phone` ,`rating` ,`info` ,`id` FROM `carrierinfo` ORDER BY `carriername` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
if ($rating == "")
{
$rating = "3";
}
if (isset($_GET["id"]))
{
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$id = mysql_real_escape_string($_GET["id"]);
$select = "SELECT * FROM `carrierinfo` WHERE `id` = '$id'";
$result = mysql_query($select) or die(mysql_error());
$fields = mysql_fetch_array($result, MYSQL_BOTH);
mysql_close($con);
}
else
{
header("Location:board.php");
}
?>
</script>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 35%;">Carrier Name:</td><td><input id="carriername" name="carriername" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[carriername]; ?>">
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td><input id="contact" name="contact" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[contact]; ?>">
</tr>
<tr>
<td style="width: 35%;">Phone:</td><td><input id="phone" name="phone" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[phone]; ?>">
</tr>
<tr>
<td style="width: 10%;">Carrier Rating:</td><td>
<select id="rating" name="rating">
<option value=""></option>
<option <?php if($fields[rating] == "1") echo "selected"; ?> value="1">1</option>
<option <?php if($fields[rating] == "2") echo "selected"; ?> value="2">2</option>
<option <?php if($fields[rating] == "3") echo "selected"; ?> value="3">3</option>
<option <?php if($fields[rating] == "4") echo "selected"; ?> value="4">4</option>
<option <?php if($fields[rating] == "5") echo "selected"; ?> value="5">5</option>
</select>
</td>
</tr>
<tr>
<td style="width: 10%;">Carrier Info:</td><td style="text-align: center;" colspan="2"><textarea name="info" maxlength="65535" style="width: 100%; height: 4em;"><?php echo $fields[info]; ?></textarea></td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Update"
class="submit" type="submit"></p>
</div>
</form>
<input type="button" onclick="window.location.href='test3.php';" value="Back" />
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
$insert = "UPDATE carrierinfo Set `carriername` = '$carriername', `contact` = '$contact', `phone` = '$phone', `rating` = '$rating', `info` = '$info' **WHERE `id` = '$id';**";
You haven't declared what $id should be before running your UPDATE query so nothing is being updated.
You are looking for
$_POST["submit"] == "Update Load"
but the value of your submit button is "Update", not "Update Load".

Using MYSQL and dropdowns

Ok I almost got a dropdown pulling from my DB and posting to it as well to work. I got it to pull down the data and for it to submit to the DB. Still a stump. If I have example "ABC Trucking" as an option. It only posts "ABC" to table1. For whatever reason it doenst post two words? Any Ideas? See where the carriername dropdown is in the div.
My Code:
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("local", "user", "pass");
mysql_select_db("DB", $con);
$carriername = mysql_real_escape_string($_POST['carriername']);
$fromzip = mysql_real_escape_string($_POST['fromzip']);
$tozip = mysql_real_escape_string($_POST['tozip']);
$typeofequipment = mysql_real_escape_string($_POST['typeofequipment']);
$weight = mysql_real_escape_string($_POST['weight']);
$length = mysql_real_escape_string($_POST['length']);
$paymentamount = mysql_real_escape_string($_POST['paymentamount']);
$contactperson = mysql_real_escape_string($_POST['contactperson']);
$loadtype = mysql_real_escape_string($_POST['loadtype']);
$insert = "INSERT INTO table1 (`carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype`) VALUES('$carriername' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype');";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `table1` ORDER BY `paymentamount` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
?>
</script>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 10%;">Carrier:</td><td>
<?php
$con = mysql_connect("local", "user", "pass");
mysql_select_db("DB", $con);
$query=("SELECT * FROM table2");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name=carriername>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Load Type:</td><td> <input id="loadtype" name="loadtype" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50"
style="width: 100%;" type="text">
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"></p>
</div>
</form>
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
instead of :
echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>";
use this
echo "<OPTION VALUE='".$row['carriername']."'>".$row['carriername']."</OPTION>";
notice ' in ur value...concate '' to your value attr.. so that it makes it a string....
EDITED
echo "<select name='carriername'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>";
}
echo "</select>";

Categories