Update textarea after submit to SQL - php

I'm writting a page which has a 'Personal Notes' section using textarea. When I click at 'Save' it actually saves the content to an SQL server but then it displays the old notes information at textarea. What I need it to update the textarea whit the new information after submit.
Here is the code:
<?php
$userlevel = mysqli_query($db,"SELECT level FROM users WHERE username = '$user_check'");
$ar = mysqli_fetch_assoc($userlevel);
if ($ar['level'] == '0')
{
$level = "Utilizador";
}
else
{
$level = "Administrador";
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
$savenotes = mysqli_real_escape_string($db,$_POST['notes']);
mysqli_query($db,"UPDATE users SET notes = '$savenotes' WHERE username = '$username'");
$msg = "Notas pessoais guardadas no servidor.";
}
?>
<div style = "margin:30px">
<ul>
<li><a class="active" onClick="location.href='main.php?action=home'">Home</a></li>
<li><a onClick="location.href='main.php?action=servers'">Servidores</a></li>
<li><a onClick="location.href='main.php?action=users'">Utilizadores</a></li>
<li><a onClick="location.href='main.php?action=account'">Minha Conta</a></li>
<li style="float:right"><a onClick="location.href='logout.php'">Sair</a></li>
<li style="float:right"><a><b>Acesso:</b> <font color=red><?php echo $level; ?></font></a></li>
</ul>
<br><br>
<font size=5><b>Bem-vindo, <?php echo utf8_encode($login_session); ?><br /></b></font><br />
Por favor escolha uma das opções do painel para gerir este servidor. Pode adicionar/remover/alterar servidores de jogo e voz bem como utilizadores deste painel.<br />
Qualquer bug ou sugestão contactar mail#mail.com.<br /><br />
Notas Pessoais:<br />
<form action = "" method = "post">
<textarea rows="4" cols="50" type ="text" name ="notes" style="border-radius: 4px; border: solid 1px light-gray; box-shadow: inset 1px 1px 1px 0 #009AFC0; transition: box-shadow 0.3s;";/><?php echo htmlentities($notes);?></textarea><br /><br />
<button class="button" type = "submit" style="vertical-align:middle; width:100px;"><span>Gravar </span></button><br />
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $msg; ?></div>
</div>
Thank you in advance!

You should load $notes after insert.
Right now it's not clear where you load it, but it should be loaded after insert.

Related

wrong password <p> element always shown

Hello guys I am working on a freelance project and I faced with a problem I added some php codes in order to change paragraph elements visibility. the paragraph element which has to appear when user entered wrong username or password however paragraph element appears all the time
PHP SECTION
<?php
session_start();
require "db.php";
if ( !empty($_POST)) {
extract($_POST) ;
if ( checkUser($id, $pass) ) {
echo '<style>#wrong-password {display:none;margin-bottom: 5%;padding: 5%;width: 280px;font-family: "Montserrat", sans-serif;font-size: 1em;border-radius: 8px;border: 1px solid #ced4da;background-color: rgb(255, 23, 23);color: white;text-align: center;margin-top: 0;}</style>';
// you are authenticated
// session_start() creates a random id called session id.
// and stores in a cookie.
$_SESSION["user"] = getUser($id) ;
if($_SESSION["user"]["userType"]=='normal'){
header("Location: Analyzes.php?id=$id") ;
exit ;
}else {
header("Location: index.php") ;
exit ;
}
}
echo '<style> #wrong-password{visibility:visible; margin-bottom: 5%;padding: 5%;width: 280px;font-family: "Montserrat", sans-serif;font-size: 1em;border-radius: 8px;border: 1px solid #ced4da;background-color: rgb(255, 23, 23);color: white;text-align: center;margin-top: 0;}</style>';
}
HTML SECTION
<div id="form-container">
<h2>Hoşgeldiniz! 😺</h2>
<form action="?" method="POST">
<input type="number" name="id" placeholder="Kullanıcı Numarası">
<br>
<input type="password" name ="pass" placeholder="Parola">
<p id="wrong-password">Kullanıcı Adı veya Parola Hatalı :(</p>
<button type="submit" title="Giriş Yap">Giriş Yap</button>
</form>
</div>
Thanks in advance:)

Unable to POST form data when I add name tag to a particular input tag?

I have been struggling to figure out the mystery behind this.
Unable to POST form data when I add name to a particular input field. I been starring at the screen for hours to figure out what went wrong.
My Code goes as,
Form Page:
<form action="upload.php" method="POST">
<div class="customer_records">
<div class="customer_records_sub">
<input type="text" list="o_id" name="o_id[]" class="mb-2 mr-sm-2 o_id_input" placeholder="Order ID"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;background: none;">
<datalist id="o_id">
<?php
$sql_o_id = "SELECT DISTINCT(o_id) FROM quotes";
$result_o_id = $conn->query($sql_o_id);
if ($result_o_id->num_rows > 0) {
while($row_o_id = $result_o_id->fetch_assoc()) {
$o_id = $row_o_id["o_id"];
?>
<option value="<?= $o_id; ?>">
<?php } } else { } ?>
</datalist>
<div class="asins_visible_input mb-2 mr-sm-2"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;
background: none;height: 45px;min-width: 300px;" >
</div>
<br/>
<div class="asins_list" style="display:none;height: auto;overflow: auto;width: auto;
border: 1px solid lightgray;padding: 2%;border-radius: 5px;
margin-left: 24%;min-width: 400px;">
<?php
$sql_asin_id = "SELECT * FROM quotespos";
$result_asin_id = $conn->query($sql_asin_id);
if ($result_asin_id->num_rows > 0) {
while($row_asin_id = $result_asin_id->fetch_assoc()) {
$asin_id = $row_asin_id["id"];
$asin_p_id = $row_asin_id["p_id"];
$asin_o_id = $row_asin_id["o_id"];
if($asin_p_id == '' || $asin_p_id == NULL) {
$asin_p_id = '(BLANK)';
} else {
$asin_p_id = $asin_p_id;
}
?>
<div class="asin_id indi_asin_<?= $asin_o_id; ?>" style="display:none;padding-left:10px;">
<input type="checkbox" class="asins_input_checkbox" data-id="<?= $asin_id; ?>" data-pid="<?= $asin_p_id; ?>" style="display:inline-block;width: 20px;height: 20px;" />
<p style="display:inline-block;padding-top: 2px;font-size: 16px;vertical-align: super;"><?= $asin_p_id; ?></p>
<div class="asins_div_percentile"
style="diplay:inline-block;float:right;display:none;">
<i class="fa fa-chevron-right" aria-hidden="true"
style="margin-top: 9px;margin-left: 8px;font-size: 14px;"></i>
<input class="asins_div_percentile_input" name="tada"
style="width: 50px;margin-left: 30px;vertical-align: top;
border: 1px solid gray;font-size: 16px;
border-radius:5px;border:1px solid gray;text-align:center;"
type="text" placeholder="%" />
</div>
<br/>
</div>
<?php $sl++; } } else { } ?>
<input type="hidden" name="asins[]" class="asins_hidden_input" />
</div>
</div>
</div>
<input type="hidden" name="bywhom" value="0" />
<input type="hidden" name="date" value="06/12/201" />
<button type="submit" name="submit" class="btn btn-primary mb-2 expense_form_btn"
style="margin-top: 0.8%;font-size:16px;">Submit</button>
</form>
Upload.php page:
$date = $_POST["date"];
$bywhom = $_POST["bywhom"];
echo $bywhom;
In the above form page, forget the array and all, they all work perfectly fine the moment i remove the name tag from the input tag with class asins_div_percentile_input, But the moment I keep something inside the name tag of that asins_div_percentile_input input, form gets submitted but none of the values gets posted. not even the normal input tag values like date mentioned above.
I don't understand what went wrong. Hope I was clear.
Any help is greatly appreciated.
After thinking a bit, I found a way around. Instead of forcing it to send all the empty fields and then take only the fields which have values, I removed the empty fields from DOM at the time of submission.
$(".form_submit_btn").click(function() {
$(".form_submit_btn").prop("disabled", true);
$('.main_parent').find('.asins_input_checkbox').each(function () {
if($(this).prop("checked")) { } else {
$(this).parent().remove();
}
});
$("#add_expense_form").submit();
});
Works fine. Thanks to all who literally taught me a lot through this query. Appreciate your time.

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

IE8 Php header location opens a new window

I have a page dynamically filled with content from PHP and databases, the content is loaded into an iframe. Now when I make a custom search, the results are coming out fine on all browsers BUT IE8 (and maybe earlier versions). The browser sorts the results in a new window instead of filling the iframe!
my php search page:
<?php
if (isset($_REQUEST[searchname])) {
$searchname = $_REQUEST[searchname];
if (strlen($searchname) < 3) {
$location = "necrologies_iframe.php?action=tooshort";
header("Location: {$location}");
} else {
$location = "necrologies_iframe.php?action=search&nom={$searchname}";
header("Location: {$location}");
}
}
?>
Is there a way to fill the iframe with results instead of opening a new window?
Edit
The search form/button:
<form id="form1" name="form1" method="get" target="frame" action="http://www.cablevision.qc.ca/fr/code/necrologies_search.php">
<p><strong><a href="javascript:void(0);" onClick="necro_search('est');" >Abitibi-Est</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=est-->
<a href="javascript:void(0);" onClick="necro_search('ouest');" >Abitibi-Ouest</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=ouest"-->
<a href="javascript:void(0);" onClick="necro_search('rn');" >Rouyn-Noranda</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=rn"-->
Témiscamingue <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=temis"-->
</strong> |
<input name="searchname" type="text" id="searchname" value=<?php if (isset($_REQUEST[nom])) { echo '"' . $_REQUEST[nom] . '"'; } else { echo '"rechercher les archives"'; } ?> size="25" />
<input type="submit" name="submit" id="submit" value="Rechercher" />
The iframe part of the page
<iframe id="frame" "width="638px" frameborder="0" src="code/necrologies_iframe.php" scrolling="yes" horizontalscrolling="no" verticalscrolling="yes"></iframe>
the iframe page code
<style type="text/css">
<!--
table
{
line-height: 135%;
font-family: Arial, Helvetica, sans-serif;
font-size:13px;
}
.border {
border: 1px solid #000000;
}
.borderbas {
border-bottom: 1px solid #000000;
}
.padding {
padding: 5px;
}
-->
</style>
<?php
// fichier de connection a la DB
require_once("includes/connection.php");
require_once("includes/functions.php");
?>
<?php
$action = $_REQUEST[action];
$datedujour = date("Y-m-d");
switch ($action) {
case "search":
$searchname = utf8_decode(mysql_prep($_REQUEST[nom]));
$necroresult = mysql_query("SELECT * FROM necrologies WHERE nom LIKE '%{$searchname}%' AND approuve = '1' ORDER BY id DESC ");
if (mysql_affected_rows() == 0) {
// message que je fais afficher si il ne trouve rien (au lieu d'une page blanche qui ne veux rien dire
$message = "<br /><br /><br /><br /><h3>Aucun résultat trouvé </h3><br>Veuillez modifier le nom de la recherche...<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
} else {
// sinon on affiche le nombre de resultats trouvés
$necro_num_rows = mysql_num_rows($necroresult);
$message = $necro_num_rows . " résultat(s) trouvés...";
$affiche_liste = 1;
}
break;
case "tooshort":
echo "<br><br><center>Recherche trop courte, veuillez entrer plus de 4 caractères...</center><br><br><br><br><br><br><br><br><br><br><br><br><br>";
break;
case "est":
case "ouest":
case "rn":
case "temis":
$affiche_liste = 1; // pour faire afficher la liste des necro
$necroresult = mysql_query("SELECT * FROM necrologies WHERE datefin > '{$datedujour}' AND approuve = '1' AND region = '{$action}' ORDER BY id DESC ");
break;
default:
// default on vois toutes les necro de toute les regions
$necroresult = mysql_query("SELECT * FROM
necrologies WHERE datefin > '{$datedujour}' AND approuve = '1'
ORDER BY id DESC ");
$affiche_liste = 1;
}
?>
<br />
<?php
// affichage du message
if (isset($message)) {
echo "<br><strong><center>" . $message . "</strong></center><br>";
}
// liste des necro dans des tables
if ($affiche_liste == 1 || !isset($_REQUEST[action])) {
while ($row = mysql_fetch_array($necroresult)) {
?>
<!-- Debut de la table fancy round corner -->
<div align="center">
<table border="0" align="left" cellpadding="0" cellspacing="0" class="tb">
<tr>
<td width="16"><img src="/fr/images/roundtable/top_lef.gif" width="16" height="16"></td>
<td height="16" background="/fr/images/roundtable/top_mid.gif"><img src="/fr/images/roundtable/top_mid.gif" width="16" height="16"></td>
<td width="24"><img src="/fr/images/roundtable/top_rig.gif" width="24" height="16"></td>
</tr>
<tr>
<td width="16" background="/fr/images/roundtable/cen_lef.gif"><img src="/fr/images/roundtable/cen_lef.gif" width="16" height="11"></td>
<td align="center" valign="middle" bgcolor="#FFFFFF">
<!-- Debut du content de la table fancy round corner -->
<table width="576" border="0" cellspacing="0" cellpadding="0" class="border" >
<tr >
<td rowspan="2" valign="top"><img src="/fr/images/necrologies/<?php echo utf8_encode($row['photo']); ?>" alt="photo" /><br><img src="/fr/images/cnq/imprimable.gif" border="0" width="150" height="50"></td>
<td width="200" bgcolor="#DFEFFF" class="borderbas" style="border-left: 1px solid #000000; border-right: 1px solid #000000"><center><?php echo nl2br(mb_convert_encoding($row['nom'], "UTF-8", "Windows-1252")); ?></center></td>
<td bgcolor="#DFEFFF" class="borderbas">
<center>
<strong>
<?php
$maison = $row[maison];
if ($maison == "N/D") {
echo "(information non disponible)";
} else {
if (substr($maison, 0, 6) == "La dir") {
echo utf8_encode($maison);
} else {
echo "La direction des funérailles a été confiée à/aux <br>";
echo utf8_encode($maison);
}
}
?>
</strong></center></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;" colspan="2"><div class="padding" align="left"><?php echo nl2br(mb_convert_encoding($row['description'], "UTF-8", "Windows-1252")); ?></div></td>
</tr>
</table>
<!-- Fin du content de la table fancy round corner -->
</td>
<td width="24" background="/fr/images/roundtable/cen_rig.gif"><img src="/fr/images/roundtable/cen_rig.gif" width="24" height="11"></td>
</tr>
<tr>
<td width="16" height="16"><img src="/fr/images/roundtable/bot_lef.gif" width="16" height="16"></td>
<td height="16" background="/fr/images/roundtable/bot_mid.gif"><img src="/fr/images/roundtable/bot_mid.gif" width="16" height="16"></td>
<td width="24" height="16"><img src="/fr/images/roundtable/bot_rig.gif" width="24" height="16"></td>
</tr>
</table>
</div>
<!-- Fin de la table fancy round corner -->
<!--[if IE 8]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<!--[if IE 7]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<!--[if IE 6]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<br /><br />
<?php
}
}
?>
<?php
// close la connection
mysql_close($connection);
?>
Targets should be named frames or windows; older browsers do not use a frame's ID. So change:
<iframe id="frame" ...
To
<iframe name="frame" id="frame" ...

Can't clear the form after successful completion

Hi I have a "Sticky" form that after successful completion I want to clear the fields
I tried placing the $_POST = array(); in different sections of the IF statements,
This is the entire file, it is a form that get's sent to itself and records what you wrote in a file outside the webroot
Thanks for any help
<!-- BEGIN CHANGABLE CONTENT -->
<?php require('templates/header.html') ?>
<div id="main" role="main">
<h1>Welcome to the site</h1>
<h2>Please fill out the form</h2>
<p>Register and become a member!<br />Members enjoy newsletters and free swag courtesy of Tony Browns Design</p>
<form action="index.php" method='post' id='login_form'>
<legend><h2>Registration Form</h2></legend>
<fieldset>
<div>
<label for="fname">First Name: </label>
<input type="text" name='fname' id='fname' size='20'
value="<?php if (isset($_POST['fname'])){echo htmlspecialchars($_POST['fname']);} ?>" />
</div>
<div>
<label for="lname">Last Name: </label>
<input type="text" name='lname' id='lname' size='20'
value="<?php if(isset($_POST['lname'])){echo htmlspecialchars($_POST['lname']);} ?>" />
</div>
<div>
<label for="email">Email: </label>
<input type="text" name='email' id='email' size='20'
value="<?php if(isset($_POST['fname'])) {echo htmlspecialchars($_POST['email']);} ?>" />
</div>
<div>
<label for="quotes" class='move-top'>Quote: </label>
<textarea name="quotes" id="quote" cols="22" rows="8">Enter your quotation here.</textarea><br />
</div>
<div>
<input type="submit" value='submit' />
</div>
</fieldset>
</form>
<?php
$file = '../quotes_from_users.txt';
//Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['fname']) && (empty($_POST['lname']) && (empty($_POST['email'])))) {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;">You need to fill in the all the fields!</p>';
}
if (!empty($_POST['quotes']) && ($_POST['quotes'] != 'Enter your quotation here.') ) {
if (is_writable($file)) {
file_put_contents($file, $_POST['quotes'] . PHP_EOL, FILE_APPEND | LOCK_EX);
echo '<p style="color= #cf5 font-size: 1.4em;">Your quote has been stored.</p>';
$_POST = array();
} else {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200;">Your quote could not be stored due to a systems error, sorry about that!</p>';
}
} else {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;">Please enter a quote!</p>';
}
}
?>
<?php require('templates/footer.html'); ?>
</div>
<!-- END CHANGABLE CONTENT -->
Your logic seems flawed, if you only post a quote, it will get saved with this code.
It should be something like:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// the next line has changed
if (empty($_POST['fname']) || (empty($_POST['lname']) || (empty($_POST['email'])))) {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;">You need to fill in the all the fields!</p>';
}
else // added
{
if (!empty($_POST['quotes']) && ($_POST['quotes'] != 'Enter your quotation here.') ) {
if (is_writable($file)) {
file_put_contents($file, $_POST['quotes'] . PHP_EOL, FILE_APPEND);
echo '<p style="color= #cf5 font-size: 1.4em;">Your quote has been stored.</p>';
// only empty $_POST on a successful submission
$_POST = array();
} else {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200;">Your quote could not be stored due to a systems error, sorry about that!</p>';
}
} else {
echo '<p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;">Please enter a quote!</p>';
}
}
}
That is assuming that your form gets added in templates/footer.html

Categories