I was tasked on making simple i-Prepaid Reload programming.So far, I have problem with validations not working on reload.php page. As if there were no validations set at all and it went to result.php after pressing Buy button. I couldn't figure it out what's the cause of this error.
There should be some errors appear is I put alphabets or less than 10 numbers or ignore all of those options in reload.php.
login.php
form action="" method="post" name="Login_Form">
<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table">
<?php if(isset($msg)){?>
<tr>
<td colspan ="2" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" align="left" valign="top"><h3>Login</h3></td>
</tr>
<tr>
<td align="right" valign="top">Username</td>
<td><input name="Username" type="text" class="Input"><td>
</tr>
<tr>
<td align="right">Password</td>
<td><input name="Password" type="password" class="Input"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Login" class="Button3"></td>
</tr>
</table>
</form>
<?php session_start();
if(isset($_POST['Submit']))
{
$logins = array(
['username' =>'Fadzli', 'password' => '11111'],
['username' =>'user2', 'password' => '22222'],
['username' =>'user3', 'password' => '33333'],
['username' =>'user4', 'password' => '44444'],
);
$log_username = isset($_POST['Username']) ? $_POST['Username'] :'';
$log_password = isset($_POST['Password']) ? $_POST['Password'] :'';
$key = FALSE;
$key = array_search($log_username, array_column($logins, 'username'));
$password = '';
echo $key;
var_dump($key);
if(!is_bool($key)){
$password = $logins[$key]['password'];
}
if($log_password == $password){
$_SESSION['Userdata'] = ['username' => $log_username];
header("location:reload.php");
exit;
}else{
$msg="<span style='color:red'>Invalid Login Information</span>";
}
}
?>
reload.php
<?php session_start();
$phonenumber = $Telco = $Reload ='';
$numberError = $telcoError = $ReloadError = '';
if(isset($_POST['Submit']))
{
$phonenumber=$_POST['phonenumber'];
if(array_key_exists('phonenumber',$_POST) && trim($_POST['phonenumber']) === '')
{
$numberError = "Error, insert phone number";
}
else
{
if(!preg_match('/^([0-9]*)$/', $phonenumber))
{
$numberError = "Numbers only";
}
elseif(strlen($phonenumber)<10)
{
$numberError = "Numbers have to be 10 or longer";
}
}
$Telco=$_POST['Telco'];
if(array_key_exists('Telco',$_POST) && trim($_POST['Telco']) == "")
{
$telcoError = "Error! Select your telco!";
}
$Reload=$_POST['ReloadCredit'];
if(array_key_exists('ReloadCredit',$_POST) && trim($_POST['ReloadCredit']) == "")
{
$ReloadError = "Error! Select the amount you wish to reload!";
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
if($numberError=="" && $telcoError=="" && $ReloadError=="")
{
$_SESSION['data'] = ['phonenumber' => $_POST['phonenumber'] ,
'Telco' => $_POST['Telco'] ,
'ReloadCredit' => $_POST['ReloadCredit'] ];
}
}
?>
<?php
$title = "i-PREPAID RELOAD";
?>
<html>
<style>
.topup_form{
max-width: 700px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
margin-right:auto;
margin-left:auto;
}
.topup_form label{
display:block;
margin-bottom: 10px;
text-align:left;
}
.note1{
margin-top:5px;
font-size: 17px;
}
.topup_form label > span{
float: left;
width: 170px;
color: #F072A9;
font-weight: bold;
font-size: 17px;
text-shadow: 1px 1px 1px #fff;
}
.topup_form fieldset{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
margin: 0px 0px 10px 0px;
border: 1px solid #FFD2D2;
padding: 20px;
background: #FFF4F4;
box-shadow: inset 0px 0px 15px #FFE5E5;
-moz-box-shadow: inset 0px 0px 15px #FFE5E5;
-webkit-box-shadow: inset 0px 0px 15px #FFE5E5;
}
.topup_form fieldset legend{
color: #FFA0C9;
border-top: 1px solid #FFD2D2;
border-left: 1px solid #FFD2D2;
border-right: 1px solid #FFD2D2;
border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
background: #FFF4F4;
padding: 0px 8px 3px 8px;
box-shadow: -0px -1px 2px #F1F1F1;
-moz-box-shadow:-0px -1px 2px #F1F1F1;
-webkit-box-shadow:-0px -1px 2px #F1F1F1;
font-weight: normal;
font-size: 25px;
}
.topup_form button,
.topup_form input[type=reset],
.topup_form input[type=button]{
background: #EB3B88;
border: 1px solid #C94A81;
padding: 5px 15px 5px 15px;
color: #FFCBE2;
box-shadow: inset -1px -1px 3px #FF62A7;
-moz-box-shadow: inset -1px -1px 3px #FF62A7;
-webkit-box-shadow: inset -1px -1px 3px #FF62A7;
border-radius: 3px;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
font-weight: bold;
}
.Button
{
width: 170px;
margin-right:auto;
margin-left:auto;
}
#warning{text-align:left;}
</style>
<div class="topup_form">
<form name="Topup" action="result.php" method="post" onsubmit="return confirm('Are you sure?')" >
<fieldset><legend><?php echo $title ?></legend>
Welcome <?php echo $_SESSION['Userdata']['username'];?>
<label for="phonenumber"><span>Phone Number <span>*</span></span><input type="text" name="phonenumber"/></label>
<div id = "warning" style="color: red;"><?php echo $numberError ?? '';?></div><br>
<label for="Telco"><span>Telco</span><select name="Telco">
<option value=""></option>
<option value="Maxis">Maxis</option>
<option value="Celcom">Celcom</option>
<option value="Digi">Digi</option>
<option value="TuneTalk">TuneTalk</option>
<option value="Unifi">Unifi</option>
</select></label>
<span class="note1">(Example:Maxis, Celcom, Digi)</span>
<div id = "warning" style="color: red;"><?php echo $telcoError ?? '';?></div><br>
<label for="Reload"><span>Reload Credit </span><select name="ReloadCredit">
<option value=""></option>
<option value="5">RM5</option>
<option value="10">RM10</option>
<option value="20">RM20</option>
<option value="30">RM30</option>
<option value="50">RM50</option>
</select></label>
<span class="note1">(Example:RM5,RM10,RM20)</span>
<div id = "warning" style="color: red;"><?php echo $ReloadError ?? '';?></div><br>
</fieldset>
<fieldset class="Button">
<button type="submit" value="Submit" name='Submit' >Buy</button>
<input type="reset" value="Reset" />
</fieldset>
</form>
</html>
'result.php'
<html>
<?php session_start()?>
<form name="result" action="">
Hi <?php echo $_SESSION['Userdata']['username'];?>
<br>
<p>Successfully reloaded</p>
<label for="phonenumber"><span>Phone Number : </span><?php echo $_POST['phonenumber']?></label><br>
<label for="telco"><span>Telco : </span><?php echo $_POST['Telco'] ?><br>
<label for="reloadcredit"><span>Reload Credit : RM </span><?php echo $_POST['ReloadCredit']?>
<p>Thank you for using i-Prepaid Reload</p>
</form>
</html>
Please note that array_search, if fails to find any record, will return false in normal circumstances.
However, array_search may return Boolean false, but may also return a non-Boolean value which evaluates to false
(See official documentation: https://www.php.net/manual/en/function.array-search.php)
On the other hand, if the match is on the 1st record, the return result will be 0 (1st record matches).
Hence, to cover all the cases, you may change your login.php to :
login.php
<?php session_start();
if(isset($_POST['Submit']))
{
$logins = array(
['username' =>'Fadzli', 'password' => '11111'],
['username' =>'user2', 'password' => '22222'],
['username' =>'user3', 'password' => '33333'],
['username' =>'user4', 'password' => '44444'],
);
$log_username = isset($_POST['Username']) ? $_POST['Username'] :'';
$log_password = isset($_POST['Password']) ? $_POST['Password'] :'';
$key= "";
$key = array_search($log_username, array_column($logins, 'username'));
if(trim($key) !=""){
$password = $logins[$key]['password'];
}
if (trim($key)!=""){
if($log_password == $password){
$_SESSION['Userdata'] = ['username' => $log_username];
header("location:reload.php");
exit;
}else{
$msg="<span style='color:red'>Invalid Login Information</span>";
}
}else
{
$msg="<span style='color:red'>Please input login username and password</span>";
}
}
?>
<form action="#" method="post" name="Login_Form">
<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table">
<?php if(isset($msg)){?>
<tr>
<td colspan ="2" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" align="left" valign="top"><h3>Login</h3></td>
</tr>
<tr>
<td align="right" valign="top">Username</td>
<td><input name="Username" type="text" class="Input"><td>
</tr>
<tr>
<td align="right">Password</td>
<td><input name="Password" type="password" class="Input"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Login" class="Button3"></td>
</tr>
</table>
</form>
For reload.php, please
amend your original code so that the submit it to itself (otherwise the validation will never happen)
If all data are validated to be correct, store the submitted data as session variable (namely $_SESSION['phonenumber'], $_SESSION['Telco'] and
$_SESSION['ReloadCredit']), then redirect to result.php
reload.php
<?php session_start();
$phonenumber = $Telco = $Reload ='';
$numberError = $telcoError = $ReloadError = '';
$_SESSION['phonenumber']="";
$_SESSION['Telco']="";
$_SESSION['ReloadCredit']="";
if(isset($_POST['Submit']))
{
$phonenumber=$_POST['phonenumber'];
if(array_key_exists('phonenumber',$_POST) && trim($_POST['phonenumber']) === '')
{
$numberError = "Error, insert phone number";
}
else
{
if(!preg_match('/^([0-9]*)$/', $phonenumber))
{
$numberError = "Numbers only";
}
elseif(strlen($phonenumber)<10)
{
$numberError = "Numbers have to be 10 or longer";
}
}
$Telco=$_POST['Telco'];
if(array_key_exists('Telco',$_POST) && trim($_POST['Telco']) == "")
{
$telcoError = "Error! Select your telco!";
}
$Reload=$_POST['ReloadCredit'];
if(array_key_exists('ReloadCredit',$_POST) && trim($_POST['ReloadCredit']) == "")
{
$ReloadError = "Error! Select the amount you wish to reload!";
}
if ($ReloadError=="" && $telcoError=="" && $numberError=="")
{
$_SESSION['phonenumber']=$_POST['phonenumber'];
$_SESSION['Telco']=$_POST['Telco'];
$_SESSION['ReloadCredit']=$_POST['ReloadCredit'];
header("location:result.php");
exit;
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
if($numberError=="" && $telcoError=="" && $ReloadError=="")
{
$_SESSION['data'] = ['phonenumber' => $_POST['phonenumber'] ,
'Telco' => $_POST['Telco'] ,
'ReloadCredit' => $_POST['ReloadCredit'] ];
}
}
?>
<?php
$title = "i-PREPAID RELOAD";
?>
<html>
<style>
.topup_form{
max-width: 700px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
margin-right:auto;
margin-left:auto;
}
.topup_form label{
display:block;
margin-bottom: 10px;
text-align:left;
}
.note1{
margin-top:5px;
font-size: 17px;
}
.topup_form label > span{
float: left;
width: 170px;
color: #F072A9;
font-weight: bold;
font-size: 17px;
text-shadow: 1px 1px 1px #fff;
}
.topup_form fieldset{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
margin: 0px 0px 10px 0px;
border: 1px solid #FFD2D2;
padding: 20px;
background: #FFF4F4;
box-shadow: inset 0px 0px 15px #FFE5E5;
-moz-box-shadow: inset 0px 0px 15px #FFE5E5;
-webkit-box-shadow: inset 0px 0px 15px #FFE5E5;
}
.topup_form fieldset legend{
color: #FFA0C9;
border-top: 1px solid #FFD2D2;
border-left: 1px solid #FFD2D2;
border-right: 1px solid #FFD2D2;
border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
background: #FFF4F4;
padding: 0px 8px 3px 8px;
box-shadow: -0px -1px 2px #F1F1F1;
-moz-box-shadow:-0px -1px 2px #F1F1F1;
-webkit-box-shadow:-0px -1px 2px #F1F1F1;
font-weight: normal;
font-size: 25px;
}
.topup_form button,
.topup_form input[type=reset],
.topup_form input[type=button]{
background: #EB3B88;
border: 1px solid #C94A81;
padding: 5px 15px 5px 15px;
color: #FFCBE2;
box-shadow: inset -1px -1px 3px #FF62A7;
-moz-box-shadow: inset -1px -1px 3px #FF62A7;
-webkit-box-shadow: inset -1px -1px 3px #FF62A7;
border-radius: 3px;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
font-weight: bold;
}
.Button
{
width: 170px;
margin-right:auto;
margin-left:auto;
}
#warning{text-align:left;}
</style>
<div class="topup_form">
<form name="Topup" action="#" method="post" onsubmit="return confirm('Are you sure?')" >
<fieldset><legend><?php echo $title ?></legend>
Welcome <?php echo $_SESSION['Userdata']['username'];?>
<label for="phonenumber"><span>Phone Number <span>*</span></span><input type="text" name="phonenumber"/></label>
<div id = "warning" style="color: red;"><?php echo $numberError ?? '';?></div><br>
<label for="Telco"><span>Telco</span><select name="Telco">
<option value=""></option>
<option value="Maxis">Maxis</option>
<option value="Celcom">Celcom</option>
<option value="Digi">Digi</option>
<option value="TuneTalk">TuneTalk</option>
<option value="Unifi">Unifi</option>
</select></label>
<span class="note1">(Example:Maxis, Celcom, Digi)</span>
<div id = "warning" style="color: red;"><?php echo $telcoError ?? '';?></div><br>
<label for="Reload"><span>Reload Credit </span><select name="ReloadCredit">
<option value=""></option>
<option value="5">RM5</option>
<option value="10">RM10</option>
<option value="20">RM20</option>
<option value="30">RM30</option>
<option value="50">RM50</option>
</select></label>
<span class="note1">(Example:RM5,RM10,RM20)</span>
<div id = "warning" style="color: red;"><?php echo $ReloadError ?? '';?></div><br>
</fieldset>
<fieldset class="Button">
<button type="submit" value="Submit" name='Submit' >Buy</button>
<input type="reset" value="Reset" />
</fieldset>
</form>
</html>
For result.php, just display the submitted data thru the session variables:
result.php
<html>
<?php session_start()?>
<form name="result" action="">
Hi <?php echo $_SESSION['Userdata']['username'];?>
<br>
<p>Successfully reloaded</p>
<label for="phonenumber"><span>Phone Number : </span><?php echo $_SESSION['phonenumber']?></label><br>
<label for="telco"><span>Telco : </span><?php echo $_SESSION['Telco'] ?><br>
<label for="reloadcredit"><span>Reload Credit : RM </span><?php echo $_SESSION['ReloadCredit']?>
<p>Thank you for using i-Prepaid Reload</p>
</form>
</html>
However, in future, please consider using a database approach to manage the users' credentials. Otherwise you need to update the PHP array list everytime you have new / changed username and/or passwords.
Related
I made a web page for my project, where I need to change a button background color based on value from database.Like if the value below 10 then it will be green, 10~20 then yellow, 20++ then turns into red. Is it possible to do?
already the button works to fetch data from data base.enter image description here
You don't give enough information. Maybe, you can create a color column in your sql table, then with jinja or other you can do somethings like this:
Jinja:
<div style="background-color:{{ data['color_ref'] }};">Hello World</div>
PHP:
<div style="background-color:<?=$color_ref?>;">Hello World</div>
Javascript:
if (qtt <= 10) {
result = document.getElementById("happyday")
result.style.backgroundColor = red;
}
<table class="center">
<?php
if(array_key_exists('test', $_POST))
{button();}
function button()
{
$conn = mysqli_connect('localhost','root','','asimdb');
$sql= "SELECT * FROM atmdata WHERE atm_id = 'ATM_01'";
$result = mysqli_query($conn,$sql);
While ($row =mysqli_fetch_assoc($result))
{
echo "
<tr><th>ATM ID</th> <td>".$row["atm_id"]."</td></tr>
<tr><th>ATM Name</th><td>".$row["ATM_Name"]."</td></tr>
<tr><th>ATM Location</th><td>".$row["ATM_Location"]."</td></tr>
<tr><th>Contact No.</th><td>".$row["Contact_No"]."</td></tr>
<tr><th>View CCTV</th><td>".$row["CCTV"]."</td></tr>
<tr><th>Current Temerature</th><td>N/A</td></tr>";
}
echo"</table>";
}
?>
<style>
.button {
border: none;
color: #2F4F4F;
padding: 12px 30px;
border-radius: 20px;
text-align: center;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 5px 5px;
cursor: pointer;
transition: transform .2s;
box-shadow:
0 1px 2px rgba(0,0,0,0.07),
0 2px 4px rgba(0,0,0,0.07),
0 4px 8px rgba(0,0,0,0.07),
0 8px 16px rgba(0,0,0,0.07),
0 16px 32px rgba(0,0,0,0.07),
0 32px 64px rgba(0,0,0,0.07);}
.button:hover {
transform: scale(1.1);
border: 1px solid black}
</style>
<form method="post">
<input type="submit"class= "button" name="test" value="ATM 01">
</form>
After submitting the buttons, it doesn't redirect to another page. Can someone please help to find the error in this code and why my buttons typ1 and cod does not redirect to the location which I already given.
<?php
include("connect.php");
include("common.php");?>
<html>
<head>
<script>
function cd()
{
document.getElementById('credit').style.display='block';
document.getElementById('debit').style.display='none';
document.getElementById('net').style.display='none';
document.getElementById('cash').style.display='none';
}
function db()
{
document.getElementById('debit').style.display='block';
document.getElementById('credit').style.display='none';
document.getElementById('net').style.display='none';
document.getElementById('cash').style.display='none';
}
function ns()
{
document.getElementById('net').style.display='block';
document.getElementById('debit').style.display='none';
document.getElementById('credit').style.display='none';
document.getElementById('cash').style.display='none';
}
function cs()
{
document.getElementById('cash').style.display='block';
document.getElementById('debit').style.display='none';
document.getElementById('credit').style.display='none';
document.getElementById('net').style.display='none';
}
function validate(inputtxt)
{
var card1 = /^(?:3[47][0-9]{13})$/;
if(inputtxt.value.match(card1))
{
return true;
}
else
{
alert("Not a credit card number!");
return false;
}
if(card1.length!=16)
{
alert("Only 16 digits are allowed");
return false;
}
}
</script>
<style>
.d2
{
border: 1px solid black;
font-size: 30px;
color: white;
background-color: #242222;
padding: 15px 15px 15px 50px;
font-family: Arial;
font-style:;
}
.tab{
width:100%;
height: 400px;
padding:25px 10px 10px 25px;
font-size: 25px;
padding:15px;
border:1px solid black;
border-collapse:collapse;
}
#credit
{
width: 80%;
height: 100%;
padding :25px 15px 15px 15px;
font-size: 20px;
}
#debit{
width: 80%;
height: 100%;
padding :25px 15px 15px 15px;
font-size: 20px;
}
#net{
width: 80%;
height: 100%;
padding :25px 15px 15px 15px;
font-size: 20px;
}
#cash{
width:600px;
height:100%;
padding :25px 15px 15px 15px;
font-size: 20px;
float: left;
}
.card{
border: 1px solid black;
}
</style>
</head><body>
<form method="post">
<?php
if(isset($_SESSION['sum']))
{
$s1=$_SESSION['sum'];
echo "
<div class='d2'> Make Payment</div>
<div>
<table class='tab'><tr><td><button name='cr' style='padding: 14px 20px 14px 20px;font-size:15px;color:white;width:300px;background-color:#373535;cursor:pointer;border-radius:5px;border-color:#363434;border-collapse:collapse;font-weight:inherit;' class= 'c1' onclick='cd()'>Credit Card</button>
<br/>
<button name='dr' class='d1' style='padding: 14px 20px 14px 20px;font-size:15px;color:white;width:300px;background-color:#373535;cursor:pointer;border-radius:5px;border-color:#363434;border-collapse:collapse;font-weight:inherit;' onclick='db()'>Debit Card</button>
<br/>
<button name='nb' class='n1' style='padding: 14px 20px 14px 20px;font-size:15px;color:white; width:300px; background-color:#373535;cursor:pointer;border-radius:5px;border-color:#363434;border-collapse:collapse;font-weight:inherit;' onclick='ns()'>Net Banking</button>
<br/>
<button name='cash' style='padding: 14px 20px 14px 20px;font-size:15px;color:white;background-color:#373535;width:300px; cursor:pointer;border-radius:5px;border-color:#363434;border-collapse:collapse;font-weight:inherit;'onclick='cs()'>Cash On Delivery</button>
</td>
<td ><div id='credit' > <h2>Pay using Credit</h2>
<hr>
<label>Card number :</label> <span class='card'><input type='text' name='cardno' placeholder='Card number' required='true'/></span>
<br/>
<br/>
<label>Expiry Date:</label> <input type'text' name='month' placeholder='MM' required='true'/>
<input type'text' name='year' placeholder='YY' required='true'> <input type'text' name='cvv' placeholder='CVV' required='true'/>
<br/>
<br/>
<button type='submit' name='typ1' style='padding: 14px 35px 14px 35px;font-size:15px;color:white;background-color:#ED0C5B;cursor:pointer;
border-radius:5px;border-color:#ED0C5B;border-collapse:collapse;font-weight:inherit;'>
<center>Pay Rs. $s1</center></button>
<br/>
<br/>
<label>This card will be save for faster payment.</label>
</div>
<div id='debit' style='display:none' > <h2>Pay using Debit Card</h2>
<hr>
<label>Card number :</label> <input type='text' name='cardno' placeholder='Card number' required='true'/>
<br/>
<br/>
<label>Expiry Date:</label> <input type'text' name='mm' placeholder='MM' required='true'>
<input type'text' name='yy' placeholder='YY' required='true'> <input type'text' name='cvv' placeholder='CVV' required='true'>
<br/>
<br/>
<button type='submit' style='padding: 14px 35px 14px 35px;font-size:15px;color:white;background-color:#ED0C5B;cursor:pointer;border-radius:5px;border-color:#ED0C5B;border-collapse:collapse;font-weight:inherit;'><center>Pay Rs. $s1</center></button>
<br/>
<br/>
<label>This card will be save for faster payment.</label>
</div>
<div id='net' style='display:none'> <h2>Pay using Net Banking</h2>
<hr/>
<label>Select Bank:</label><input type='radio' value='ICICI'>ICICI <input type='radio' value='HDFC'>
HDFC <input type='radio' value='Axis'>Axis
<br/>
<br/>
<label>Account number :</label> <span class='card'>
<input type='text' name='cardno' placeholder='Enter your Account number' required='true'/>
</span>
<br/>
<br/>
<button type='submit' style='padding: 14px 35px 14px 35px;font-size:15px;color:white;background-color:#ED0C5B;cursor:pointer;
border-radius:5px;border-color:#ED0C5B;border-collapse:collapse;font-weight:inherit;'><center>Pay Rs. $s1</center></button>
<br/>
<br/>
<label>This card will be save for faster payment.</label>
</div>
<div id='cash' style='display:none'> <h2>Pay using Cash On Delivery</h2>
<hr width=100%/>
<button name='cod' type='submit' style='padding: 14px 35px 14px 35px;font-size:15px;color:white;background-color:#ED0C5B;cursor:pointer;
border-radius:5px;border-color:#ED0C5B;border-collapse:collapse;font-weight:inherit;'>
Place COD Order</button>
<br/>
<br/>
<br/>
<label>This card will be save for faster payment.</label>
</div>
</td>
</tr>
</table>
</div>
";
}
?>
</form></body></html>
<?php
if(isset($_POST['typ1']))
{
$_SESSION['s2']=$_SESSION['sum'];
$card=$_POST['cardno'];
$mon=$_POST['month'];
$yr=$_POST['year'];
$cv=$_POST['cvv'];
$_SESSION['card']=$card;
$q7="select * from bank where card_no=$card";
$qry6= mysql_query($q7);
while($r7=mysql_fetch_array($qry6))
{
$m=$r7[3];
$y=$r7[4];
$c=$r7[5];
$money=$r7[6];
if($mon==$m && $yr==$y && $cv==$c)
{
header("location:redirect.php");
}
else{
echo "<script>alert('Your details doesnot match');</script>";
}
}
}
if(isset($_POST['cod']))
{
header("location:cod.php");
}
?>
you didn't write which page form submit.
<form method="post"><!-- action="isWhere" -->
Also you can write your code like this. I think this way is better than your wrote.
<?php
if(isset($_SESSION['sum']))
{
$s1=$_SESSION['sum'];
?>
<form method="post" action="isWhere">...</form>
<?php
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 6 different input-fields and I want to do so you have to fill in all of them, else a alert message will pop-up. Any tips on how to do this?
I also have problems with option for different font-styles. When you click on the different options for the font-style, the text that you wrote in the input-filed should change and also the text infront "förtag" and so on.
This is my code:
function SkrivUt() {
var el = document.getElementById('f');
el.style.color = document.getElementById('textColor').value;
el.style.fontStyle = document.getElementById('selectedFont').value;
el.style.backgroundColor = document.getElementById('backGroundColour').value;
$("#area1").html($("#foretagText").val());
$("#area2").html($("#efternamnText").val());
$("#area3").html($("#fornamnNamnText").val());
$("#area4").html($("#titleText").val());
$("#area5").html($("#telefonText").val());
$("#area6").html($("#epostText").val());
$("#visitkort").hide();
$("#visitkortsDemo").show();
}
function reset() {
document.getElementById('foretagText').value = "";
document.getElementById('efternamnText').value = "";
document.getElementById('fornamnNamnText').value = "";
document.getElementById('titleText').value = "";
document.getElementById('telefonText').value = "";
document.getElementById('epostText').value = "";
}
.form-style-3 {
max-width: 400px;
max-height 400px;
font-family: "Comic Sans MS", cursive, sans-serif;
}
.form-style-3 label {
display: block;
margin-bottom: 10px;
}
.form-style-3 label span {
float: left;
width: 150px;
font-weight: bold;
font-size: 13px;
text-shadow: 1px 1px 1px #fff;
}
.form-style-3 fieldset {
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
margin: 0px 0px 10px 0px;
border: 1px solid #FFD2D2;
padding: 20px;
background: lightblue;
box-shadow: inset 0px 0px 15px #FFE5E5;
-moz-box-shadow: inset 0px 0px 15px #FFE5E5;
-webkit-box-shadow: inset 0px 0px 15px #FFE5E5;
}
/*Format legent inom ett fieldset*/
.form-style-3 fieldset legend {
color: #FFA0C9;
border-top: 1px solid #FFD2D2;
border-left: 1px solid #FFD2D2;
border-right: 1px solid #FFD2D2;
border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
background: #FFF4F4;
padding: 0px 8px 3px 8px;
box-shadow: -0px -1px 2px #F1F1F1;
-moz-box-shadow: -0px -1px 2px #F1F1F1;
-webkit-box-shadow: -0px -1px 2px #F1F1F1;
font-weight: normal;
font-size: 12px;
}
.select-field {
background: gray;
color: white;
border-radius: 5px 5px 5px 5px;
}
.input-field {
font-family: "Comic Sans MS", cursive, sans-serif;
color: red
}
<!DOCTYPE html>
<html>
<head>
<title>Visitkort</title>
<link rel='stylesheet' type='text/css' href='Style.css' />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div class="form-style-3">
<div id="visitkort" style='display:block'>
<fieldset>
<legend>Visitkort</legend>
<label><span>Företaget</span>
<input type="text" id="foretagText" />
</label>
<label><span>Efternamn </span>
<input type="text" id="efternamnText" />
</label>
<label><span>Förnamn </span>
<input type="text" id="fornamnNamnText" />
</label>
<label><span>Titel </span>
<input type="text" id="titleText" />
</label>
<label><span>Telefon </span>
<input type="text" id="telefonText" />
</label>
<label><span>Epost </span>
<input type="text" id="epostText" />
</label>
<label>
<span>Välj bakgrundsfärg</span>
<select class="select-field" id="backGroundColour">
<option value="RoyalBlue">Blå</option>
<option value="Yellow">gul</option>
<option value="Crimson">Röd</option>
</select>
</label>
<label>
<span>Välj Textfärg</span>
<select class="select-field" id="textColor">
<option value="RoyalBlue">Blå</option>
<option value="Yellow">Gul</option>
<option value="Crimson">röd</option>
</select>
</label>
<label>
<span>Välj typsnitt</span>
<select class="select-field" id="selectedFont">
<option value="Verdana">Verdana</option>
<option value="Ariel">Ariel</option>
<option value="Impact">Impact</option>
<option value="Tahoma">Tahoma</option>
</select>
</label>
<label><span><button type="button" onclick="reset()">Nollställ</button></span><span><button type="button" onclick="SkrivUt()">Skriv ut</button></span>
</label>
</fieldset>
</div>
<div id="visitkortsDemo" style='display:none'>
<fieldset id="f">
<legend>Förgranskning av visitkort</legend>
n>Företaget </span>
<p id="area1"></p>
</label>
<label><span>Efternamn </span>
<p id="area2"></p>
</label>
<label><span>Förnamn </span>
<p id="area3"></p>
</label>
<label><span>Titel </span>
<p id="area4"></p>
</label>
<label><span>Telefon </span>
<p id="area5"></p>
</label>
<label><span>Epost </span>
<p id="area6"></p>
</label>
</fieldset>
</div>
</div>
</body>
</html>
A simple and quick way would be to use HTML5's required attribute!
Example:
<input type="text" id="foretagText" required />
This will produce browser alerts, when an input field is empty. No need for difficult custom Javascript.
You haven't tried much, so im not just going to give answer, but here is an idea, in raw javascript. You will want a better way of collecting the input Ids obviously, thats up to you.
<script>
var inputs = ["inputid1", "inputid2", "inputid3"];
var notFilled = "";
for (var i in inputs){
element = document.getElementById(i);
if(element.value==""){
notFilled = i;
break;
}
}
if(notFilled!=""){
alert("you must fill" + notFilled);
}
</script>
// create your err array
var err = [];
//test if values are a blank string
if($("#foretagText").val() === ""){
//add the error message to your error array
err.push("Foretag not entered");
}
// be sure you only have if statements and they aren't nested like this
if($("#idOfNextValue").val() === ""){
//add the error message to your error array
err.push("Foretag not entered");
}
//alert all messages in your error array.
alert (err.length + " Errors:<br>" +err.join("<br>"));//join
In HTML5 you can use required attribute as follow;
<input type="text" required>
Or in jQuery:
Let's say HTML:
<input type="text" id="input-1">
<input type="text" id="input-2">
<input type="text" id="input-3">
<input type="text" id="input-4">
and so on..
Now jQuery
if($("[id^=input]").val()=="")
{
alert("error");
return;
}
HTML way : Use required attribute
<input type="text" id="somename" required>
Javascript way:
if ($('#foretagText').val() == '' || $('#efternamnText').val() != ' ...) {
alert("Fields empty");
}
For your first question. To require the user to select a value in a select you have to add the atributte required like this
<select class="select-field" id="backGroundColour" required>
<option value="RoyalBlue">Blå</option>
<option value="Yellow">gul</option>
<option value="Crimson">Röd</option>
</select></label>
For your second question I'm not completely sure about this but I think that the problem resides in that you are trying to change the label style directly without change the associated css.
This is a page code that shows attendance report of student.I want checkbox in colored if checked green else red.please help me to do this.I tried it but didn't work.Now i can click only on one checkbox that change color.check this image: http://i.stack.imgur.com/JgICk.png
<style>
.checkbox {
margin: 0 0 2em 2em;
}
.checkbox .tag {
color: #595959;
display: block;
float: left;
font-weight: bold;
position: relative;
width: 120px;
}
.checkbox label {
display: inline;
}
.checkbox .input {
display: none;
}
.input + label {
-webkit-appearance: none;
background-color: red;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 9px;
display: inline-block;
position: relative;
}
.input:checked + label:after {
background-color: green;
color: #595959;
content: '\2714';
font-size: 10px;
left: 0px;
padding: 2px 8px 2px 2px;
position: absolute;
top: 0px;
}
</style>
<?php
if(isset($_POST["submit"]))
{
//Here goes array
for($i=0;$i<count($_POST['student']);$i++)
{
$name=$_POST['student'][$i];
echo $name;
}
}
?>
</head>
<body >
Report Attendance
<form name="myform" action="" method="post">
<div class="checkbox">
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php while ($row = mysql_fetch_assoc($res)){?>
<tr><td> <input type="checkbox" class="input" id="input" name="student[]" value="<?php echo $row['stu_id']; ?>" checked="checked" > <?php echo $row['stu_name'] ; ?> <label for="input"></label>
<br/></td></tr>
<?php }?>
</table>
<input type="submit" name="submit" value="submit"/>
</div>
</form>
</body>
</html>
You just need to make id as unique and labels should point to unique id. Here is the jsfiddle with static HTML https://jsfiddle.net/sua2wsm1/
below changes required in your HTML page
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php while ($row = mysql_fetch_assoc($res)){?>
<tr><td> <input type="checkbox" class="input" id="input<?php echo $row['stu_id']; ?>" name="student[]" value="<?php echo $row['stu_id']; ?>" checked="checked" > <?php echo $row['stu_name'] ; ?> <label for="input<?php echo $row['stu_id']; ?>"></label>
<br/></td></tr>
<?php }?>
Actually, duplicates ID can be the problem. A label is link to an input with the for attribute. So, if you click on the label, it'll be the same as clicking on the input. Your css is hiding the inputs, and using label:after as a box. So, if all inputs have the same id, clicking on a label will not work as expected
I'm trying to append an result from a database PHP insert using echo json_encode($results).
I'm, getting all the values from the post back in the JSON but the appending is not working.
Here's the jQuery side:
$('#postsubmit').click(function(){
error = 0;
// get form data
post = $('#comments').val();
topicname = $('#topicName').val();
topicid = $('#topicID').val();
pageid = $('#pageID').val();
page = $('#page').val();
sendmail = $('#sendmail').val();
galleria_pointer = $('#galleria_pointer').val();
showstatus = $('#showstatus').val();
$(this).attr('disabled','disabled');
if ($("#comments").val() == ''){
$("#comments").css({ "border": "1px solid red"});
$('.hideAdd').show();
$(this).attr('enabled','enabled');
}
$.ajax({
type: "POST",
url: "../foorumi/AjaxPost.php",
dataType: 'text',
data: "topicid="+topicid+"&pageid="+pageid+"&topicname="+topicname+"&page="+page+"&post="+encodeURIComponent(post)+"&sendmail="+sendmail+"&galleria_pointer="+galleria_pointer+
"&showstatus="+showstatus,
beforeSend : function(){
$("#loading_image").show();
$("body").css("cursor", "wait");
},
error : function(XMLHttpRequest, textStatus, errorThrown){
error = 1;
},
success : function(data) {
$("#loading_image").hide();
$("body").css("cursor", "default");
//alert(data);
dataobject = $.parseJSON(data);
var json_post_result = dataobject.post_result;
var json_error_code = dataobject.errors;
var json_topicname = dataobject.topicname;
var json_postid = dataobject.postid;
var json_topicid = dataobject.topicid;
var json_pageid = dataobject.pageid;
var url = dataobject.url;
var json_showstatus= dataobject.showstatus;
var json_post = dataobject.post;
var json_dateNow = dataobject.sentNow;
var json_galleria_pointer = dataobject.sentNow;
var json_data_html = dataobject.data_html;
var decoded = $("<div/>").html(json_data_html).text();
//alert(decoded);
if(json_post_result == true){
url_to = url;
//window.location.replace(url_to);
$(".hideAdd").fadeOut("fast",function(){
$('#ShowNew').show();
$(".divWrapperAppend").append(decoded);
});
}
}
});
});
And here's the PHP side:
$user_ = ($_SESSION['users_id']);
$post_single = utf8_decode($_POST['post']);
$pageid = $_POST['pageid'];
$topicid_ = $_POST['topicid'];
$topicname = $_POST['topicname'];
$page = $_POST['page'];
$galleria_pointer = ($_POST['galleria_pointer']);
$sendmail = ($_POST['sendmail']);
$showstatus = ($_POST['showstatus']);
$microseconds_ = ((double) microtime()) * 1000000;
$results = array();
$errors = '';
$data = array();
$sqluserinfo = "select u.username as username, u.userlevel, (SELECT 1 FROM userphotos up WHERE up.user_= '$user_' and defaultphoto = '1') as photonum
,(SELECT count(1) FROM posts p1 WHERE u.users_id = p1.user_) as usermessagecount FROM users u WHERE u.users_id = '$user_'";
$sqlusersql = mysql_query($sqluserinfo);
$username = mysql_result($sqlusersql, 0, username);
$count_posts = mysql_result($sqlusersql, 0, usermessagecount);
$ulevel = mysql_result($sqlusersql, 0, userlevel);
$photonum = mysql_result($sqlusersql, 0, photonum);
$userSendMailSQL = "select *, (SELECT 1 from mail_topic where sendmail = '1' and user_ = '$user_' and theader_ = '$topicid_') as sendmail1 FROM mail_topic WHERE user_='$user_' and theader_ = '$topicid_' order by id";
$resultsqlquery = mysql_query($userSendMailSQL)or die(mysql_error());
$sendMailto = mysql_result($resultsqlquery, 0, sendmail1);
if ($post_single == "" || strlen(preg_replace('/\W/', '', $post_single)) < 5)
{
$errors = 1;
}
if (!empty($errors)){
$data['errors'] = $errors;
$data['post_success'] = false;
$results = array("errors"=>$errors, "post_result" => $data['post_success']);
}
else{
$data['post_success'] = true;
$new_post = htmlspecialchars($post_single, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
$insert="insert into posts (topicID, user_, Post, editdate_, updatedmicrosec) values ('$topicid_','$user_','$new_post','editdate_','$microseconds_')";
$timetoday = date("d.m.Y H:i:s");
$dateNow = date_diff_as_text($timetoday,"now") . " sitten";
//Insert data to db
mysql_query($insert);
$postid_ = mysql_insert_id();
if ($sendmail > 0){
sendmail($topicid_,$topicname,$user_,$postid_,$page);
}
updatelastread($topicid_);
$tableStyle_ajax = 'postStyleThisDay';
$tableStyleUser_ajax = 'postStyleThisDayUser';
$tableStyleNoBorder_ajax = 'postStyleThisDayNoBorder';
$styleBorder_ajax = 'style="min-height: 100%; border-right: 2px solid #87b1c8;"';
$aid_ajax = '<a name="'.$postid_.'"></a>';
$idcolor_ajax = 'color: #e82020; font-weight: bold;';
$borderbottom_ajax = 'border-bottom: 2px solid #e82020;';
$bordertop_ajax = 'border-top: 2px solid #e82020;';
if ($photonum > 0)
{
$photodiv = ('<div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><img src="../profiili/userAlbums/'.$folder.'/'.$thumbnail.'"" style="width: 85px; height: 55px; border: none; padding: 2px;"/></div>');
}
$data_html = ('
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; '.$bordertop_ajax.'>
<div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">
<div class="forumPostUser" style="float: left; width: 145px;"><a href="../kayttajat/index.php?id='.$user_.'>'.$username.'</a></div>
<div style="float: left; padding-left: 5px; width: 640px;">Lähetetty: '.$dateNow.'</div>
<div style="float: left; padding-left: 5px; '.$idcolor_ajax.'">ID: '.$postid_.'</div>
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">
'.$photodiv.'
<div style="font-size: 11px;">Viestejä: '.$count_posts.' kpl</div>
<div style="font-size: 11px; padding-top: 3px;">Taso: '.$showstatus.'
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">
<div> </div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">
<span style="font-size: 16px; line-height: 130%;">'.$new_post.'</span>
</div>
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; '.$borderbottom_ajax.'">
<div style="padding: 8px 5px 3px 0px; min-height: 20px;">
<div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser">alkuun</div>
<div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;"> </div>
<div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_ .'&page='.$page.'#quoted"><input type="hidden" name="postID" value="'.$postid_.'" />
<input type="hidden" name="lainaa" value="Lainaa" />
<input type="image" src="../png/lainaa.png" /></form>
</div>
<div style="float: left;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'"><input type="hidden" name="postID" value="'.$postid_.'" /><input type="hidden" name="muokkaa" value="submit" />
<input type="hidden" name="edited" value="edited" />
<input type="image" src="../png/muokkaa.png" /></form></div>
</div>
</div>
<div style="clear: both;"></div>
</div>
</div>
<div style="clear: both;"></div>');
$data_html = htmlspecialchars($data_html, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
if (mysql_error() != ""){
echo ('<br><p><center><b><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">There was a MySQL Error -- '.mysql_error().'</b></center></p>');
exit;
}
$url = 'http://intra.tobiasfransman.net/foorumi/index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'';
$results = array(
"data_html" => $data_html,
"url" => $url,
"post_result" => $data['post_success']
);
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
//header('Content-type: application/x-www-form-urlencoded, charset=UTF-8');
echo json_encode($results);
It's the $data_html that I want to append, but it wont append.
Can anyone see what I'm doing wrong?
console log ouput:
{"data_html":"\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; border-top: 2px solid #e82020;>\r\n <div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">\r\n <div class="forumPostUser" style="float: left; width: 145px;"><a href="..\/kayttajat\/index.php?id=0>Tobba<\/a><\/div>\r\n <div style="float: left; padding-left: 5px; width: 640px;">Lähetetty: < 1 minuutti sitten<\/div>\r\n <div style="float: left; padding-left: 5px; color: #e82020; font-weight: bold;">ID: 0<\/div>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><a href="..\/kayttajat\/index.php?id=0&album=1&img=2"><img src="..\/profiili\/userAlbums\/\/"" style="width: 85px; height: 55px; border: none; padding: 2px;"\/><\/a><\/div>\r\n <div style="font-size: 11px;">Viestejä: 1104 kpl<\/div>\r\n <div style="font-size: 11px; padding-top: 3px;">Taso: <span>LIFE.IS.A..<\/span>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div> <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <span style="font-size: 16px; line-height: 130%;">Testing testing<\/span>\r\n <\/div>\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; border-bottom: 2px solid #e82020;">\r\n <div style="padding: 8px 5px 3px 0px; min-height: 20px;">\r\n <div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser"><a href="#alkuun">alkuun<\/a><\/div>\r\n <div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;"> <\/div>\r\n <div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">\r\n <form method="post" action="index.php?id=1&show=41&page=9#quoted"><input type="hidden" name="postID" value="0" \/>\r\n <input type="hidden" name="lainaa" value="Lainaa" \/>\r\n <input type="image" src="..\/png\/lainaa.png" \/><\/form>\r\n <\/div>\r\n <div style="float: left;">\r\n <form method="post" action="index.php?id=1&show=41&page=9&postid=0&tag=#0"><input type="hidden" name="postID" value="0" \/><input type="hidden" name="muokkaa" value="submit" \/>\r\n <input type="hidden" name="edited" value="edited" \/>\r\n <input type="image" src="..\/png\/muokkaa.png" \/><\/form><\/div>\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>\r\n\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>","url":"http:\/\/intra.tobiasfransman.net\/foorumi\/index.php?id=1&show=41&page=9&postid=0&tag=#0","post_result":true,"errors":null}
Added $data_html = utf8_decode($data_html) to the php post and now the append works as is :)