This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Avoiding form resubmit in php when pressing f5
I need help on how to prevent the DOUBLE DATA SUBMISSION to mysql database.
This usually occurs when after the submit, user hits REFRESH button.
Whenever I send data using html web forms to handle them in sever side I'd better omit action attribute of a form which explains that the file will be processed by itself and starting from the first line i place server side php scripts. Before sending data I sctrictly check if all fields are filled correctly and then send that data to future processing. Using php script I'll check if web form button which was clicked is not null and then via established connection to mysql execute manipulation queries.
Is using header function to redirect to itself is an optimal way to prevent Double Data Submission???
Haven't you any ideas?
In addition I'll include the code
<?php
include_once '../config.php';
include_once '../functions.php';
if (isset($_POST['bDep'])){
$flt=$_POST['flt'];
$num=$_POST['fltNum'];
$acr=$_POST['acr'];
$city=$_POST['city'];
$fTime=$_POST['fTime'];
$bReg=$_POST['bReg'];
$eReg=$_POST['eReg'];
$acomp=$_POST['aircomp'];
$gate=$_POST['gate'];
$dte=$_POST['data'];
$tm=explode(":",$fTime);
if ($tm[0]<3) $p=1;
else $p=0;
$otmena=$_POST['cancel'];
if ($otmena==1) $stat=4;
else $stat=7;
$sql="INSERT INTO fltdep(FID, FLT, NUM, DEP, TO_FROM, IN_OUT, dte, Stat, BReg, EReg, Gate, AType, ALn, Cir, Hide ) VALUES (0, '$flt', '$num','$fTime', $city,1, '$dte',$stat,'$bReg','$eReg','$gate',$acr,$acomp,$p,0)";
if (mysql_query($sql)){
echo "<p style='text-color:red;text-align:center;'>Успешно добавлена запись № </p>";
}else {
echo "<p style='text-color:red;text-align:center;'>Ощибка при добавлении к базе</p>";
}
unset($_POST['bDep']);
unset($_POST['flt']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Заполнение вылетов</title>
<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="../css/template.css" type="text/css"/>
<link rel="stylesheet" href="../themes/base/jquery.ui.all.css" type="text/css">
<link rel="stylesheet" href="../themes/base/flts.css" type="text/css">
<link rel="stylesheet" href="../themes/base/tipsy.css" type="text/css" />
<link rel="stylesheet" href="../themes/base/tipsy-main.css" type="text/css" />
<link href="../themes/base/table.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="../js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery.maskedinput-1.3.js" type="text/javascript"></script>
<script src="../ui/jquery.ui.core.js"></script>
<script src="../ui/jquery.ui.widget.js"></script>
<script src="../ui/jquery.ui.button.js"></script>
<script src="../ui/jquery.ui.tabs.js"></script>
<script src="../ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
$("#data").datepicker({ numberOfMonths: 1, dateFormat: 'yy-mm-dd' });
jQuery("#Departures").validationEngine();
});
$(function(){
$('#fTime').mask('99:99',{placeholder:"_"});
$('#bReg').mask('99:99',{placeholder: "_"});
$('#eReg').mask('99:99',{placeholder: "_"});
});
function SetAline()
{
var fl=new String($('#flt').val());
if (fl.substr(0,2)=='TD' || fl.substr(0,2)=='td' ) { $('#aircomp').val(1); $('#gate').val(2);}
else if (fl.substr(0,2)=='TJ' || fl.substr(0,2)=='tj' ) { $('#aircomp').val(1); $('#gate').val(1);}
else if (fl.substr(0,2)=='SM' || fl.substr(0,2)=='sm' ) { $('#aircomp').val(2); $('#gate').val(1);}
else if (fl.substr(0,2)=='SB' || fl.substr(0,2)=='sb' ) { $('#aircomp').val(3); $('#gate').val(1);}
else if (fl.substr(0,2)=='OR' || fl.substr(0,2)=='or' ) { $('#aircomp').val(4); $('#gate').val(1);}
else if (fl.substr(0,2)=='TA' || fl.substr(0,2)=='ta' ) { $('#aircomp').val(5); $('#gate').val(1);}
else if (fl.substr(0,2)=='SV' || fl.substr(0,2)=='sv' ) { $('#aircomp').val(6); $('#gate').val(1);}
else if (fl.substr(0,2)=='UT' || fl.substr(0,2)=='ut' ) { $('#aircomp').val(7); $('#gate').val(1);}
else if (fl.substr(0,2)=='SD' || fl.substr(0,2)=='sd' ) { $('#aircomp').val(8); $('#gate').val(1);}
else if (fl.substr(0,2)=='YA' || fl.substr(0,2)=='ya' ) { $('#aircomp').val(9); $('#gate').val(1);}
else if (fl.substr(0,2)=='CS' || fl.substr(0,2)=='cs' ) { $('#aircomp').val(10);$('#gate').val(1);}
else if (fl.substr(0,2)=='D9' || fl.substr(0,2)=='d9' ) { $('#aircomp').val(11);$('#gate').val(1);}
}
function SetRegTime()
{
var depTime=$('#fTime').val();
var fl=new String($('#flt').val());
var start,end;
if (fl.substr(0,2)=='TD' || fl.substr(0,2)=='td'){
start='01:30';
end='00:20';
}else {
start='03:00';
end='00:40';
}
$('#bReg').val(TimeDiff(depTime,start));
$('#eReg').val(TimeDiff(depTime,end));
}
function TimeDiff(a,b)
{
var first = a.split(":")
var second = b.split(":")
var xx;
var yy;
if(parseInt(first[0]) < parseInt(second[0])){
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - parseInt(second[0])
}
}else if(parseInt(first[0]) == parseInt(second[0])){
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) - parseInt(second[0])
}
}else{
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) - parseInt(second[0])
}
}
if(xx < 10)
xx = "0" + xx
if(yy < 10)
yy = "0" + yy
return (xx + ":" + yy);
}
</script>
</head>
<body>
<form id="Departures" class="formular" method="post" action="">
<fieldset>
<legend>
ЗАПОЛНЕНИЕ ВЫЛЕТОВ <i>Прилет</i>
</legend>
<label>
<span>Дата : </span>
<input class="validate[required] text-input" type="text" name="data" id="data" maxlength="12" value="<? (isset($_POST['data']))?($_POST['data']): date('Y-m-d') ;?>" />
</label>
<label>
<span>Рейс : </span>
<input value="" class="validate[required] text-input" type="text" name="flt" id="flt" maxlength="5" onkeyup="SetAline();"/>
</label>
<label>
<label>
<span>№ рейса : </span>
<input value="" class="validate[required] text-input" type="text" name="fltNum" id="fltNum" maxlength="5"/>
</label>
<label>
<span>Тип ВС :</span>
<select name="acr" id="acr" class="validate[required]">
<option value="">Выберите</option>
<?php
$AC= & getAC();
while ($rowAC=mysql_fetch_array($AC)){
$i++;
echo "<option value='".$rowAC['acode']."'>".$rowAC['name_ru']."</option>";
}
?>
</select>
</label>
<label>
<span>А/П прибт :</span>
<select name="city" id="city" class="validate[required]">
<option value="">Выберите</option>
<?php
$city= & getCity();
while ($rowCi=mysql_fetch_array($city)){
$i++;
echo "<option value='".$rowCi['code']."'>".$rowCi['abbr_ru']."</option>";
}
?>
</select>
</label>
<label>
<label>
<span>Время отправления : </span>
<input value="" class="validate[required] text-input" type="text" name="fTime" id="fTime" maxlength="5" onBlur="SetRegTime();"/>
</label>
<label>
<label>
<span>Начало регистрации : </span>
<input value="" class="validate[required] text-input" type="text" name="bReg" id="bReg" maxlength="5" readonly="readonly" />
</label>
<label>
<label>
<span>Конец регистрации : </span>
<input value="" class="validate[required] text-input" type="text" name="eReg" id="eReg" maxlength="5" readonly="readonly"/>
</label>
<label>
<span>Авиакомпания :</span>
<select name="aircomp" id="aircomp" class="validate[required]">
<option value="">Выберите авиакомпанию</option>
<option value="option1">Таджик Эйр</option>
<?php
$Aline= & getAComp();
while ($rowAline=mysql_fetch_array($Aline)){
$i++;
echo "<option value='".$rowAline['acode']."'>".$rowAline['name_ru']."</option>";
}
?>
</select>
</label>
<label>
<span>Терминал :</span>
<select name="gate" id="gate" class="validate[required]">
<option value="">Выберите</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</label>
<label>
<span>Отмена</span>
<input class="checkbox" type="checkbox" name="cancel" id="cancel" value="1"/>
</label>
</fieldset>
<input name="bDep" class="submit" type="submit" value="Заполнить"/><hr/>
</form>
</body>
</html>
Your method (Header redirect after post) is necessary, but insufficient.
Some users press links twice (doubleclick). And your code sometimes might insert the same record twice in this case. You need to write a JavaScript that would disable submit button after first click.
Related
I have 3 textboxes and i can't get it value with $_GET and $_POST options. I need something like this:
-I fill textboxes with text
-I click button
-I activate function when clicking button
-In this function I recieve text from textboxes
-I save it to file (saving to file works ;) )
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>One Hit Point</title>
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="test.css" rel="stylesheet">
</head>
<body>
<form action="<?php $_PHP_SELF ?>" method="GET">
<label for="" id="Label1" style="position:absolute;left:67px;top:16px;width:194px;height:31px;line-height:31px;z-index:0;">Imię</label>
<input type="text" id="x11" name="x1" style="position:absolute;left:158px;top:23px;width:196px;height:16px;z-index:1;" value="">
<label for="" id="Label2" style="position:absolute;left:67px;top:63px;width:289px;height:31px;line-height:31px;z-index:2;">Nazwisko</label>
<input type="text" id="x22" name="x2" style="position:absolute;left:158px;top:70px;width:196px;height:16px;z-index:3;" value="">
<label for="" id="Label3" style="position:absolute;left:67px;top:111px;width:194px;height:31px;line-height:31px;z-index:5;">Telefon</label>
<input type="text" id="x33" name="x3" style="position:absolute;left:158px;top:118px;width:196px;height:16px;z-index:6;" value="+48 ">
<input type="button" id="Button1" onclick="<?php costam() ?>;" name="" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
</form>
</body>
<body>
<?php
//window.location.href='./niespodzianka.html';return false;
function costam(){
$imie= $_GET['x1'];
$Nazwisko=$_GET['x2'];
$Numer= $_GET['x3'];
//łączenie
$dane=$imie.", ".$Nazwisko.", ".$Numer;
//dodawanie nowej linii
$popr=$dane." k\n";
//otwieranie, zapisanie, zamknięcie
$plik=fopen("zap.txt", "a");
fputs($plik, $popr);
fclose($plik);
}
?>
</body>
</html>
EDIT:
new code (now there are 2 files):
File 1 (dz.php):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>One Hit Point</title>
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="test.css" rel="stylesheet">
</head>
<body>
<form action="pliki.php" method="GET">
<label for="" id="Label1" style="position:absolute;left:67px;top:16px;width:194px;height:31px;line-height:31px;z-index:0;">Imię</label>
<input type="text" id="x11" name="x1" style="position:absolute;left:158px;top:23px;width:196px;height:16px;z-index:1;" value="">
<label for="" id="Label2" style="position:absolute;left:67px;top:63px;width:289px;height:31px;line-height:31px;z-index:2;">Nazwisko</label>
<input type="text" id="x22" name="x2" style="position:absolute;left:158px;top:70px;width:196px;height:16px;z-index:3;" value="">
<label for="" id="Label3" style="position:absolute;left:67px;top:111px;width:194px;height:31px;line-height:31px;z-index:5;">Telefon</label>
<input type="text" id="x33" name="x3" style="position:absolute;left:158px;top:118px;width:196px;height:16px;z-index:6;" value="+48 ">
<input type="button" id="Button1" onclick="location.href='pliki.php'" name="" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
</form>
</body>
</html>
File 2 (pliki.php):
<?php
//window.location.href='./niespodzianka.html';return false;
$imie= $_GET['x1'];
$Nazwisko=$_GET['x2'];
$Numer= $_GET['x3'];
//łączenie
$dane=$imie.", ".$Nazwisko.", ".$Numer;
//dodawanie nowej linii
$popr=$dane." k\n";
//otwieranie, zapisanie, zamknięcie
$plik=fopen("zap.txt", "a");
fputs($plik, $popr);
fclose($plik);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bez nazwy</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="niespodzianka.css" rel="stylesheet">
</head>
<body>
<div id="wb_TextArt1" style="position:absolute;left:16px;top:13px;width:867px;height:470px;z-index:0;">
<img src="images/img0001.png" id="TextArt1" alt="Bede dzownić xd" title="Bede dzownić xd" style="width:867px;height:470px;"></div>
</body>
</html>
That code can't works. You can't call PHP function using javascript onclick.
For your clarification this code would execute costam() function everytime page is loaded.
Try to change Button1 with:
<input type="submit" id="Button1" name="submit" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
Then change php code in:
<?php
if($_GET['submit']){
$imie= $_GET['x1'];
$Nazwisko=$_GET['x2'];
$Numer= $_GET['x3'];
//łączenie
$dane=$imie.", ".$Nazwisko.", ".$Numer;
//dodawanie nowej linii
$popr=$dane." k\n";
//otwieranie, zapisanie, zamknięcie
$plik=fopen("zap.txt", "a");
fputs($plik, $popr);
fclose($plik);
}
This should works, but is not a good approch. Also the page will refresh.
If you're familiar with jQuery:
jQuery.ajax({
type: "POST",
url: 'your_functions_address.php',
dataType: 'json',
data: {functionname: 'add', arguments: [1, 2]},
success: function (obj, textstatus) {
if( !('error' in obj) ) {
yourVariable = obj.result;
}
else {
console.log(obj.error);
}
}
});
This may help you: Call php function from JavaScript
I'm trying to make a quiz that will show the person who take it the average of the number of answer they got right. For example: if they have 2 right it would display 66%. Can someone please explain to me how I can do something like this.
<!DOCTYPE html>
<html>
<head>
<title>Question</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="background-color:lightblue">
<h1 style="text-align:center;color:white"> Answer these Questions</h1>
<div class="container" style="margin-top: 50px">
<?php
$numcorrect=0;
// If the submit button has been pressed
if(isset($_POST['submit']))
{
// Check answer
if($_POST['answer'] == 21)
{
$numcorrect= ($numcorrect + 1);
}
if($_POST['answer1'] == 46)
{
$numcorrect= ($numcorrect + 1);
}
if($_POST['answer2'] == 2468)
{
$numcorrect= ($numcorrect + 1);
}
$average=$numcorrect/count ($numcorrect);
echo "<h1>Your Average is {$_POST['$Average']}</h1>";
}
?>
<!-- Quiz Form -->
<form method="post" action="questionassign1.php">
<ol>
<div class="form-group">
<h3><li>How old am I ?</li></h3>
<input name="answer" type="text" class="form-control" />
<h3><li>How old is my Mom?</li></h3>
<input name="answer1" type="text" class="form-control" />
<h3><li>What is my favorite number?</li></h3>
<input name="answer2" type="text" class="form-control" />
</li>
</div>
</ol>
<input name="submit" type="submit" value="Check answer" class="btn btn-primary" />
</form>
</div>
</body>
</html>
Use this code:
<?php
$numcorrect = 0;
// If the submit button has been pressed
if (isset($_POST['submit'])) {
// Check answer
if ($_POST['answer'] == 21) { {
$numcorrect++;
}
if ($_POST['answer1'] == 46) {
$numcorrect++;
}
if ($_POST['answer2'] == 2468) {
$numcorrect++;
}
$average = ($numcorrect/3)*100;
echo "<h1>Your Average is $average %</h1>";
}
}
?>
:)
$average=$numcorrect/count ($numcorrect);
echo "<h1>Your Average is ".$average."%</h1>";
You already calculated the average, so put it in the string with the . string concat operator. Additional hint: Check your code, what happens if I don't know any answer?
I have this code to pull values and labels from a MySQL DB and populate a drop down box, on change it put the value in a text field, but I want the label not the value.
Any pointers would be good..
<select name="CompanyInternalID" autofocus class="textBox" id="CompanyInternalID" style="width:300px" onchange="document.form1.CompName.value=this.value">
<?php
do {
?>
<option value="<?php echo $row_rsCustomerList['AKA']?>"><?php echo $row_rsCustomerList['CustomerName']?></option>
<?php
} while ($row_rsCustomerList = mysql_fetch_assoc($rsCustomerList));
$rows = mysql_num_rows($rsCustomerList);
if($rows > 0) {
mysql_data_seek($rsCustomerList, 0);
$row_rsCustomerList = mysql_fetch_assoc($rsCustomerList);
}
?>
</select>
<input type="text" name="CompName" class="textBox" style="width:180px" id="CompName" />
Thanks
You can use jQuery to get the selected value and put in the required text field.
Suppose the id of dropdown is "drop" and id of text field is "txt_id" . Now you can use below code:
$("#drop").change(function () {
$("#txt_id").val($(this).val());
});
You can use below code:
You can also learn jQuery at http://www.w3schools.com/jquery/
<!doctype html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-1.8.2.min.js"></script>
</head>
<body>
<select name="CompanyInternalID" autofocus class="textBox" id="CompanyInternalID" style="width:300px" > <?php do { ?> <option value="<?php echo $row_rsCustomerList['AKA']?>"><?php echo $row_rsCustomerList['CustomerName']?></option> <?php } while ($row_rsCustomerList = mysql_fetch_assoc($rsCustomerList)); $rows = mysql_num_rows($rsCustomerList); if($rows > 0) { mysql_data_seek($rsCustomerList, 0); $row_rsCustomerList = mysql_fetch_assoc($rsCustomerList); } ?> </select> <input type="text" name="CompName" class="textBox" style="width:180px" id="CompName" />
<script>
$("#CompanyInternalID").change(function () { $("#CompName").val($(this).val());
}
);
</script>
</body>
</html>
I am having an issue with storing $_SESSION variables, i am a little new at PHP and I like it to the extent of my current knowledge.
first my creds:
Win 7 Pro 64
PHP 5
Remote Server(not sure of its config)
So what I am trying to do is set up a Login Page that contains a hardcoded username and password for testing purposes.
I want to display the username on a successor page to confirm it.
Login.php
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>Login</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="en-gb" />
<script type="text/javascript">
// Perform Client side validation of Username and Password
function redirect() {
var username = document.getElementById("username");
var password = (document.getElementById("password"));
if (!username.value == " ") {
if (!password.value == " ") {
if (username.value == "aknight") {
if (password.value == "00226291") {
window.location = "Home.php";
exit();
} else
alert("Username or Password Invalid");
}
} else
alert("Password is required");
} else
alert("Username is required");
}
</script>
</head>
<body>
<div id="header">
<h1>Product Order System</h1>
<br/>
<h2>The most expensive crap youll ever find...</h2>
</div>
<div id="content">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$_SESSION['username'] = $_POST['username'];
}else{
?>
<form action="" method="POST">
<fieldset>
<legend>Login Information</legend>
<p>
<label for="Username">Username:</label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="Password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="button" name="login" value="Login" onclick="redirect();"/>
<input type="button" name="cancel" value="Cancel" />
</fieldset>
</form>
<?php }
include ('includes/footer.html');
?>
home.php
<?php
session_start();
$page_title = 'Home';
include ('includes/header.php');
if(isset($_SESSION['username'])) { $name = $_SESSION['username'];}else{echo "<p>error</p>";}
echo "<h3>Welcome ".$name."!</h3>" ;
?>
I have tried printing out the $_SESSION values and they are coming up empty.
producing this result
<?php
echo "<pre>".print_r($_SESSION)."</pre>";
?>
Array {
[username] =>
}
Please do not mind the JS, it is preschool client validation just to move forward.
Any help would be greatly appreciated.
Give your login form a name, and then in your JavaScript validation function, instead of window.location, do a document.forms['yourformname'].submit().
I think your Javascript validation is actually what's causing the issue.
You're setting the session variable in Login.php using the POST request, but no POST is actually being sent to Login.php since your Javascript is redirecting to Home.php once the form is considered valid. You need to submit the form at some point in the process, so you actually get some POST values which you'll use to populate your SESSION variables.
If you want to keep your Javascript validation, maybe have a look at submit() : http://www.w3schools.com/jsref/met_form_submit.asp
You'll have to set a correct action property on your form before submitting it.
So heres a fix that seems to be working
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>Login</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="en-gb" />
<script type="text/javascript">
// Perform Client side validation of Username and Password
function redirect() {
var username = document.getElementById("username");
var password = (document.getElementById("password"));
if (!username.value == " ") {
if (!password.value == " ") {
if (username.value == "aknight") {
if (password.value == "00226291") {
document.forms[0].submit();
exit();
} else
alert("Username or Password Invalid");
}
} else
alert("Password is required");
} else
alert("Username is required");
}
</script>
</head>
<body>
<div id="header">
<h1>Product Order System</h1>
<br/>
<h2>The most expensive crap youll ever find...</h2>
</div>
<div id="content">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$_SESSION['username'] = $_POST['username'];
header('Location : ../Home.php');
}else{
?>
<form action="Home.php" name="login" method="POST">
<fieldset>
<legend>Login Information</legend>
<p>
<label for="Username">Username:</label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="Password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="button" name="login" value="Login" onclick=" redirect();"/>
<input type="button" name="cancel" value="Cancel" />
</fieldset>
</form>
<?php }
include ('includes/footer.html');
?>
Will post again if the nex series of pages has a similiar issue
Thanks
Im trying to figure this out but its really getting to me 2nd all day on trying code and searching ...
Trying to see guidance if i am getting to the right direction with ajax and autosaving when a user performs an action on the button (BUT i do need to have a config.txt)
Because its more of an Active running application for enabling/disabling an action with custom options needed on the fly.
Trying to (ON page load ) read file config.txt (and auto change the values on the form to what was read from config.txt like a 2 way async (Without reloading the page)
config.txt
active=1
email=1
markets=chi,nyc,orl,sfo
timer=15
emailaddress=test#gmail.com
logviewer=1
so Being that markets has option to add 1 or more i need to post with commas ...
Thus when active=1 is enabled theres a bash script in the background that will be executed based on the selection of the active (when the user checks the box IN REALTIME) ... (onclick)
MAIN HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>....Tools....</title>
<script src="js/ajaxsbmt.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/ui-darkness/jquery-ui.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.filter.js"></script>
<script type="text/javascript" src="assets/prettify.js"></script>
<link rel="stylesheet" type="text/css" href="../jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="assets/style.css" />
<link rel="stylesheet" type="text/css" href="assets/prettify.css" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript">
$(function(){
$("select").multiselect({
selectedList: 4
});
$("select").multiselect().multiselectfilter();
});
</script>
<script type="text/javascript">
function autosave()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","save.php?data="+data,true);
if (multiple_id == "marketlist")
{
xmlhttp.send($value1","$value2","$value3","$value4",")
// NEED TO FIGURE OUT HOW TO POST it as CHI,ATL,NYC or however many selected with comma seperated values as the line item Hmmmmmmmmm
}
}
</script>
</head>
<body>
<div id="TESTING">
<h3>ENABLE Debug LOG VIEWER</h3>
<form>
Yes:
<input type="radio" id="logger" name="logviewer" value="logger=1" onclick="autosave(this.value)" />
<br />No:
<input type="radio" id="logger" name="logviewer" value="logger=0" onclick="autosave(this.value)" />
</form>
</div>
<div id="page">
<ul>
<li><label for="ch_effects">ENABLE Diaster Script:</label><input type="checkbox" id="ch_enable" name="ch_enable" data-on="Enable" data-off="Disable" onclick="autosave(this.value)" /></li>
Select Markets To be monitored
<form>
<form name="mkts" method="post" action="save.php">
<select name="marketlist" multiple="multiple" style="width:600px">
<option value="CHI">Chicago-CHI</option>
<option value="CHI">Baltimore-BAL</option>
<option value="NYC">New York-NYC</option>
<option value="BDR">Bridgeport-BDR</option>
<option value="PHL">Philadelphia-PHL</option>
<option value="PHL">Pittsburgh-PIT</option>
<option value="ORL">Orlando-ORL</option>
</select>
<input type="submit" id="marketlist" value="what is selected Seperate by Commas" name="submit" onclick="autosave(this.value)" />
</p>
<li><label for="ch_location">Email notifications</label><input type="checkbox" id="ch_emailnotify" name="ch_emailnotify" data-on="ON" data-off="OFF" onchange="autosave(this.value)"/></li>
<li><label for="ch_emails">Realtime log view</label><input type="checkbox" id="ch_logview" name="ch_logview" data-on="Show" data-off="Hide" onchange="autosave(this.value)"/></li>
</ul>
<p>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value="" onchange="autosave(this.value)"/>
</div>
<li class="buttons">
<input type="hidden" name="form_id" value="CONFIG" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</body>
</html>
SAVE.PHP
<?php
$logger = $_REQUEST["logger"];
$active = $_REQUEST["ch_enable"];
$marketlist = $_REQUEST["marketlist"];
$emailnotify = $_REQUEST["ch_emailnotify"];
$filename="config.txt";
$act = "active='$active'";
$log = "logger='$logger'";
$mkt = "markets='$marketlist'";
$eml = "email='$emailnotify'";
$fin=fopen($filename,"w");
fwrite($fin,$content);
if ( $act = "" ) {
$cmd = "grep 'active=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $log != "" ) {
$cmd = "grep 'logger=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $mkt != "" ) {
$cmd = "grep 'markets=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $eml != "" ) {
$cmd = "grep 'email=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
fclose($fin);
echo "Data saved";
?>