Unknown column 'activation_code' in 'field list' - php

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

Related

Undefined index: sessionName

Hello I have created a login page which is
<form method="POST" action="log.php">
<table border="1" cellpadding="4" cellspacing="0"
style="font-family: arial; font-size: 15px; border: 0px; text-align: left; margin-top: 5px; background-color: transparent;"
width="100%">
<thead>
<tr>
<td style="border: 0px; width: 20%; background-color: transparent;">
Username:</td>
<td style="border: 0px; width: 30%; background-color: transparent;">
<input type="text" name="email" id="email" class="form-control"
autocomplete="off" required="">
</td>
</tr>
</thead>
</table>
<table border="1" cellpadding="4" cellspacing="0"
style="font-family: arial; font-size: 15px; border: 0px; text-align: left; margin-top: 5px; background-color: transparent;"
width="100%">
<thead>
<tr>
<td style="border: 0px; width: 20%; background-color: transparent;">
Password:</td>
<td style="border: 0px; width: 30%; background-color: transparent;">
<input type="password" name="pass" id="pass" class="form-control"
autocomplete="off" required>
</td>
</tr>
</thead>
</table>
</div>
<div class="spacer-20"></div>
</div>
<!-- Social Signup -->
<div class="social-signup">
<span class="or-break"></span>
<center>
<button type="submit" name="login" class="btn btn-primary">
<span class="glyphicon glyphicon-log-in"></span> Login
</button>
No account? Sign up
</form>
and the login Processor is as follows
<?php
// Login Controller
// require('config/config.php');
include './config/config.php';
$userName = $passWord = $name = "";
if (isset ( $_POST ['login'] )) {
$userName = mysqli_real_escape_string ( $con, $_POST ['email'] );
$password = mysqli_real_escape_string ( $con, $_POST ['pass'] );
$pass = md5 ( $password );
// Block handles Doctor Login using the email
$get_doc = "SELECT * FROM doctor_registration WHERE email='$userName' AND password='$pass'";
$run_doc = mysqli_query ( $con, $get_doc );
$rows = mysqli_fetch_array ( $run_doc );
$docId = $rows ['doc_id'];
$docEmail = $rows ['email'];
$name = $rows ['first_name'] . " " . $rows ['last_name'];
if ($userName == $docEmail) {
$_SESSION ['sessionName'] = $name;
$_SESSION ['sessionId'] = $docId;
echo "<script>window.open('doctor_dashboard.php','_self')</script>";
} else {
// Block handles user Login using the username
$get_user = "SELECT * FROM users WHERE username='$userName' AND password='$pass'";
$run_user = mysqli_query ( $con, $get_user );
$rows = mysqli_fetch_array ( $run_user );
$userId = $rows ['user_id'];
$uname = $rows ['username'];
if ($userName == $uname) {
$_SESSION ['sessionName'] = $uname;
$_SESSION ['sessionId'] = $userId;
echo "<script>window.open('user_dashboard.php','_self')</script>";
} else {
echo "<script>alert('Passowrd or username is not correct!')</script>";
}
}
}
?>
and for the dashboard the processor checks the email or username and redirects to one of the dashboard.
i have two dashboards which have the code bellow for starting and storing a session
<?php
session_start ();
include './config/config.php';
include './updateFunction.php';
include './InsertFunction.php';
if (isset ( $_SESSION ['sessionName'] ) && ($_SESSION ['sessionId'])) {
header ( "location:index.php" );
}
?>
and each time i try to login in both dashboards i get the error:
Undefined index: sessionName
You should use session_start() before using $_SESSION['sessionName'] = $name
in the login processor.
So preferably you should use session_start() at the beginning of the page
Put session_start(); in your config.php after <?php
then call config.php on every page on after <?php
you are getting session error because you haven't use session_start(); in your file

Can't send checklist to email from html

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.

Form disappears after pressing SUBMIT button

I'm pretty new to html, php, mysql and i have to like learn the basics # my new workplace.
I'm having an annoying problem with my Form Validation. I'm using ubuntu server in combination with PuTTY
My problem is: that my 'Validation' and 'empty Field' check is not working propperly.
So when i go into my browser, my Form (Table) shows up as it should. When I hit the Submit button WITHOUT writing any stuff into the fields, the Form stays on the page and my Errors appear: ("Name is required, email, Nachname") That's right so far.
But when i fill in anything into the field(s), and then hit the Submit button, the form just disappears and i get like a blank page (but still having my CSS background n stuff).
No matter if comes up to the requirements, or not.
I'm trying to find out whats wrong since 3 whole days 9hrs/day # my workplace.
So hopefully anyone of you can help me finally get this thing work.
everything i post now is in the same order as i have it in my PuTTy
(nano)
My script starts like this:
CSS:
<html>
<head>
<title> Formular FINAL </title>
<style>
body {
background-image: url("http://fewpict.com/images/background-pictures/background-pictures-01.jpg");
}
.db_table {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
overflow: hidden;
overflow-y: auto;
position: fixed;
top: 80%;
left: 50%;
transform: translate(-50%, -50%);
width: 50%;
height: 100px;
}
.db_table td, tr {
color: white;
text-align: center;
}
.center_div {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.center_div td {
font-family: "Comic Sans", Comic Sans MS, cursive;
color: white;
text-align: left;
}
.error {color: #FF0000;}
</style>
</head>
<body>
PHP-Form Validation:
<?php
$VornameErr = "";
$emailErr = "";
$NachnameErr = "";
$Vorname = $_POST['Vorname'];
$email = $_POST['email'];
$Nachname = $_POST['Nachname'];
$allesok = "";
//input type hidden
if(isset($_POST['action'])){
//ÜBERPRÜFUNGSVARIABLE
$allesok = 1;
$errors = array();
if (empty($_POST) === false) {
$required_fields = array('Vorname', 'Nachname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true ){
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
}
//Vorname Überprüfen
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Vorname"])) {
$allesok = 0;$VornameErr = "Name is required";
} else {
$Vorname = test_input($_POST["Vorname"]);
if (!preg_match("/[a-zA-Z]{3,}/",$Vorname)) {
$allesok = 0;$VornameErr = "Only letters and atleast 3 alpha characters Allowed";
}
}
}
if (empty($_POST["email"])) {
$allesok = 0;$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$allesok = 0;$emailErr = "Invalid email format";
}
}
//Nachname Überprüfen
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Nachname"])) {
$allesok = 0; $NachnameErr = "Nachname is required";
} else {
$Nachname = test_input($_POST["Nachname"]);
if (!preg_match("/[a-zA-Z]{3,}/",$Nachname)) {
$allesok = 0;$NachameErr = "Only letters and atleast 3 alpha characters Allowed";
}
}
}
function check_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
}
MySQL:
if ($allesok) {
define('DB_NAME', 'formular');
define('DB_USER', 'David');
define('DB_PASSWORD', '****');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
if(isset($_POST['sent'])) {
$value1 = $_POST['Vorname'];
$value2 = $_POST['Nachname'];
$value3 = $_POST['email'];
$sql = "INSERT INTO formular (Vorname, Nachname, email) VALUES ('$value1', '$value2', '$value3')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
} else {
$msg1='<p> Your information was submitted successfully.</p>';
}
}
Echo Form:
if(isset($_POST['sent'])) {
?>
<div class="center_div">
<table>
<tr>
<td style="width: 200px;">Vorname: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['Vorname']; ?> </br></td>
</tr>
<tr>
<td style="width: 200px;">Nachname: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['Nachname']; ?> </br></td>
</tr>
<tr>
<td style="width: 200px;">E-Mail: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['email']; ?> </br> </td>
</tr>
</table>
<input type="button" value="Zurück" onClick="history.back();">
</div>
<?php
echo $msg1."<br /><br /><br />";
//Liste anzeigen
} elseif(isset($_POST['show_table'])) {
//fake formular <-----was made for still having the possibility to fill out stuff when i view the LIST
echo "<div class='center_div'>";
echo "<form action='toto2.php' method='POST'/>";
echo"<table>";
echo "<tr>";
echo "<th></th>";
echo "<th></th>";
echo "<th>span class='error'>* required field.</span></th>";
echo "<tr>";
echo "<td style= 'width: 200px;' > Vorname:* </td>";
echo "<td> <input type='text' name='Vorname' placeholder='Your Vorname...' /></td>";
echo "<td><span class='error'>*$VornameErr </span></td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 200px;'> Nachname:* </td>";
echo "<td> <input type='text' name='Nachname' placeholder='Your Nachname...' /></td>";
echo "<td><span class='error'>*$NachnameErr</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 200px;'> E-Mail:* </td>";
echo "<td><input type='email' name='email' placeholder='Your E-Mail address...' /></td>";
echo "<td><span class='error'>*$emailErr</span></td>";
echo "</tr>";
echo "</table>";
echo "<input type='submit' value='SEND' name='sent' />";
echo "<input type='submit' value='Einträge anzeigen' name='show_table' />";
echo "<input type='button' value='Einträge ausblenden' onClick='history.back();'>";
echo "</div>";
echo "</form>";
//DB Tabelle
$query = "SELECT * FROM formular;";
$result = mysql_query($query);
echo '<div class="db_table">';
echo '<table>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Vorname</th>';
echo '<th>Nachname</th>';
echo '<th>email</th>';
echo '</tr>';
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "</tr>";
}
echo '<tr>';
echo '<td>';
echo '<input type="button" value="Zurück" onClick="history.back();">';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
}
} else {
?>
HTML Form:
<div class="center_div">
<span class="error"></span>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr>
<th></th>
<th></th>
<th><span class="error">* required field.</span></th>
<tr>
<td style= "width: 200px;" > Vorname:* </td>
<td> <input type="text" name="Vorname" placeholder="Your Vorname..." /></td>
<td><span class="error">* <?php echo $VornameErr;?></span></td>
</tr>
<tr>
<td style="width: 200px;"> Nachname:* </td>
<td> <input type="text" name="Nachname" placeholder="Your Nachname..." /></td>
<td><span class="error">* <?php echo $NachnameErr;?></span></td>
</tr>
<tr>
<td style="width: 200px;"> E-Mail:* </td>
<td><input type="text" name="email" placeholder="Your E-Mail address..." /></td>
<td><span class="error">* <?php echo $emailErr;?></span></td>
</tr>
</table>
<input type="hidden" name="action" value="1">
<input type="submit" value="SEND" name="sent" />
<input type="submit" value="Einträge anzeigen" name="show_table" />
<input type="button" value="Einträge ausblenden" onClick="history.back();">
</form>
</div>
<?php
}
mysql_close();
?>
</body>
</html>

unable to receive email through contact form here is my code

I am unable to receive email.here is my code.and i am trying to find my error but i am unable to find.so plzz anybody help me to solve this one.i am doubtful too about my code.here is my code which i have in my php file.my mail()
functions return true and i have modified my xamp config files.
<?php
require("connection.php");
?>
<?php
if(isset($_REQUEST))
{
$first = $_REQUEST['firstname'];
$middle = $_REQUEST['middlename'];
$last = $_REQUEST['lastname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message =$_REQUEST['message'];
$query=" INSERT INTO `contact`(`id`,`first-name`, `middle-name`, `last-name`, `email`, `phone`, `message`) VALUES ('','$first','$middle','$last','$email','$phone','$message')";
$result = mysql_query($query);
if($result)
{
echo "data entered";
}
else
{
echo "data is not entered";
}
$to = "mehmood.asif31#gmail.com";
$subject = "Message From Contact Us Page";
$headers = "From:mehmood.asif31#gmail.com \r\n";
$headers .= "Bcc:mehmood.asif31#gmail.com \r\n";
$message = '<div style="margin:0 auto; padding:0px; width:800px">
<p style="font:bold 28px Arial, Helvetica, sans-serifl ; color:#006699; padding:0 0 0px 0; ">Feedback Message</p>
<div style=" margin:0 0 20px 0; font-family:Arial, Helvetica, sans-serif; font-size:15px; padding:10px; margin:0px; line-height:22px;">
<table>
<tr>
<td><strong>Name:</strong></td>
<td>'.$first.'</td>
</tr>
<tr>
<td><strong>Email ID:</strong></td>
<td>'.$email.'</td>
</tr>
<tr>
<td><strong>Phone No:</strong></td>
<td>'.$phone.'</td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td>'.$message.'</td>
</tr>
</table>
</div>
</div>';
//echo $message; exit;
mail($to, $subject, $message, $headers);
unset($_POST);
}
?>

While loop looping through data twice

So I have this code, and I've been fretting over it for several hours now and my friend and I can't find the solution. It display reviews based on a descending ID pulled from a database. This is an endless scroll type of script to eliminate pagination. For some reason when I hit the bottom of the page and run the script, the while loop is iterating through the data twice. So if its supposed to display reviews ID 5 - 10, it display 10, 9, 8, 7, 6, 5, 10, 9, 8, 7, 6, 5; instead of 10, 9, 8, 7, 6, 5. This is going to be a very large bit of code, But I hope you can help me with my problem.
Thanks in advance!!
<?php
include("../mysql_server/connect_to_mysql.php");
if($_GET['lastPost']) {
$mysqlQuery = mysql_query('SELECT * FROM `reviews` WHERE `review_id` < "' . $_GET['lastPost'] . '" ORDER BY `review_id` DESC LIMIT 0, 10');
while ($review_row = mysql_fetch_assoc($mysqlQuery)) {
$review_title = $review_row['review_title'];
$user_id = $review_row['user_id'];
$user_firstname = $review_row['user_firstname'];
$user_lastname = $review_row['user_lastname'];
$review_id = $review_row['review_id'];
$review_body = $review_row['review_body'];
$review_referral = $review_row['review_referral'];
// Code to append text for title
// strip tags to avoid breaking any html
$review_title = strip_tags($review_title);
if (strlen($review_title) > 30) {
// truncate string
$stringCut = substr($review_title, 0, 30);
// make sure it ends in a word so assassinate doesn't become ass...
$review_title = substr($stringCut, 0, strrpos($stringCut, ' ')).'...';
}
// Code to append text and add Read More
// strip tags to avoid breaking any html
$review_body = strip_tags($review_body);
if (strlen($review_body) > 230) {
// truncate string
$stringCut = substr($review_body, 0, 230);
// make sure it ends in a word so assassinate doesn't become ass...
$review_body = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a class="reviewContentLink" href="../../pages/home_page/post_content.php?id='. $review_id .'">See Full Post</a>';
} else {
$review_body .= '<a class="reviewContentLink" href="../../pages/home_page/post_content.php?id='. $review_id .'">See Full Post</a>';
}
$review_date = $review_row['review_date'];
$review_date = date_create($review_date);
$review_date = date_format($review_date, 'g:ia \o\n F jS\, Y');
$user_firstname = $review_row['user_firstname'];
$review_rating = $review_row['rating'];
/////// Mechanism to Display Pic. See if they have uploaded a pic or not //////////////////////////
$check_pic = "../members/$user_id/thumb_image01.jpg";
$default_pic = "../members/0/image01.jpg";
if (file_exists($check_pic)) {
$review_pic = "<img src=\"../$check_pic\" width=\"80px\" />";
} else {
$review_pic = "<img src=\"../$default_pic\" width=\"80px\" />";
}
include_once('../include/star_display.php');
//Pull the Review Category from the row
$review_category = "";
$review_category = $review_row['review_category'];
include_once('../include/review_category.php');
//Pull the Referral Category from the row
$referral_category = $review_row['referral_category'];
include_once('../include/referral_category.php');
//Code for URL for Each Review
$review_url = $review_row['review_url'];
if (!function_exists('remove_http')) {
function remove_http($url = '') {
return(str_replace(array('http://','https://'), '', $url));
}
}
//CODE TO DISTINGUISH REFERRALS FROM REVIEWS
//Final Output List
if($review_referral == 0) {
//Code for Displaying URL Link
$review_url = remove_http($review_url);
$review_url = "<a target='_BLANK' href='http://". $review_url ."'>Buy It Here!</a> ";
echo ''. $review_id .' '. $review_referral .'
<div class="display_newsfeed" id="'.$review_id.'">
<table id="'.$review_id.'" style="width:98.5%; border:#00B347 1px solid; margin:10px 0px 20px 10px;">
<td style="float:left; width:15%; border-right:1px solid #DDDDDD; margin:5px 0px 5px 0px;">
<div class="review_user_name">'. $user_firstname.' '. $user_lastname .'</div>
<div class="review_prof_pic">'. $review_pic .'</div>
<div class="bought_it_newsfeed">Bought It!</div>
</td>
<td style="float:right; width:82%;">
<div class="review_title_p">
<p><span class="review_title">'. $review_title .'</span><span class="review_date_p">'. $review_date .'</span><span class="review_stars">'. $review_stars .'</span></p>
</div>
<div class="review_read_more">
<p class="review_body_p">'. $review_body .'</p><br />
<div>
<div style="float:left;" class="review_black_font_link">Website:'.$review_url.'</div>
<div style="float:right; margin-right:20px;" class="review_black_font_link">Category: '.$review_category_post .'</div>
</div>
</div>
</td>
</table>
<hr style="margin:0px 20px 0px 20px;" />
</div>
';
} else if($review_referral == 1) {
//Code for Displaying URL Link
$review_url = remove_http($review_url);
$review_url = "<a target='_BLANK' href='http://". $review_url ."'>Click Here</a> ";
echo '
<div class="display_newsfeed" id="'.$review_id.'">
<table id="'.$review_id.'" style="width:98.5%; border:#0099FF 1px solid; margin:10px 0px 20px 10px;">
<td style="float:left; width:15%; border-right:1px solid #DDDDDD; margin:5px 0px 5px 0px;">
<div class="review_user_name">'. $user_firstname.' '. $user_lastname .'</div>
<div class="review_prof_pic">'. $review_pic .'</div>
<div class="referral_newsfeed">Referral</div>
</td>
<td style="float:right; width:82%;">
<div class="review_title_p">
<p>'. $review_title .'<span class="review_date_p">'. $review_date .'</span><span class="review_stars">'. $review_stars .'</span></p>
</div>
<div class="review_read_more">
<p class="review_body_p">'. $review_body .'</p><br />
<div>
<div style="float:left;" class="review_black_font_link">Business Website:'. $review_url .'</div>
<div style="float:right; margin-right:20px;" class="review_black_font_link">Category: '. $referral_category_post .'</div>
</div>
</div>
</td>
</table>
<hr style="margin:0px 20px 0px 20px;" />
</div>
';
}
}
} else {
echo "didn't work";
}
?>
Are you also sure there is no corruption in your database? you can try just
while ($review_row = mysql_fetch_assoc($mysqlQuery)) {
echo $review_row['review_title'] . "<br />";
}
Can you post the code that calls/posts to this script? As the others stated, it is quite possible this code is being called twice.
Also, if you run this query directly in the database, what is returned?
SELECT *
FROM `reviews`
WHERE `review_id` < (insert the id here)
ORDER BY `review_id` DESC
LIMIT 0, 10

Categories