my code is not working on action method - php

This code use for display report on front end and in csv file also displa this code running properly and this code is redirect on same page document.frmmonthly.action ="test2.php"; but second code is not working properly the code is not redirect to other page what is reason or what's the problem in my code......
document.frmmonthly.action ="csv.php";
action method is not working on csv.php.....my code is not working plz help me...
<head>
<script language="text/javascript">
function OnSubmitForm(value) {
if(value == 'Generate') {
document.frmmonthly.action ="test2.php";
} else if(value == 'Download') {
document.frmmonthly.action ="csv.php";
}
return true;
}
</script>
</head>
<form method="POST" onSubmit="return OnSubmitForm();">
</tr>
<tr>
<td><input type="submit" name="submit"
onSubmit="OnSubmitForm(this.value)"
value="Generate"></tr>
<tr>
<td><input type="submit" name="submit1"
onSubmit="OnSubmitForm(this.value)"
value="Download" action="csv.php">
</tr>
</form>

Try this:
<form method="POST" name="frmmonthly" onSubmit="return OnSubmitForm();">
[Edit:] Also you have to rename onSubmit e.g. to onClick

Try this
function OnSubmitForm(value)
{
if(value == 'Generate')
{
document.frmmonthly.action ="test2.php";
}
else if(value == 'Download')
{
document.frmmonthly.action ="csv.php";
}
return true;
}
</script>
</head>
<form method="POST" name="frmmonthly" onSubmit="return OnSubmitForm();">
</tr>
<tr>
<td><input type="submit" name="submit" onSubmit="OnSubmitForm(this.value)" value="Generate"></tr>
<tr>
<td><input type="submit" name="submit1" onSubmit="OnSubmitForm(this.value)" value="Download">
</tr>
</form>
I remove action=".." from input type

Ypu should name your form:
<form method="POST" onSubmit="return OnSubmitForm();" name="frmmonthly">
Since the form doesn't have a name, your method can't set it's action.

Related

How to exit the application on 3 wrong attempts

I have made a login page where the No. of attempts is checked. The problem right now is it locks the user but keeps the counter for No. of Attempts increasing. I want to exit stop the counter to be increment. Please Help!
<html>
<head><title>Meeting Room Application</title>
<script type="text/javascript">
function validation()
{
var uname=document.forms["Login"]["txtuid"].value;
var pwd=document.forms["Login"]["txtpwd"].value;
if((uname==null || uname=="") && (pwd==null || pwd==""))
{
alert("Please fill all the details");
return false;
}
if(uname==null || uname=="")
{
alert("Please enter username");
return false;
}
if(pwd==null || pwd=="")
{
alert("Please enter password");
return false;
}
if(noofattempt>=3)
return false;
}
</script>
</head>
<body background="a6.jpg">
<?php
session_start();
if(isset($_SESSION['loginattempt']))
$NoOfAttempt=(int) $_SESSION['loginattempt'];
else
$NoOfAttempt=0;
?>
<table align="center" cellpadding="5" cellspacing="5">
<tr><td colspan="2" align="center"><img src="LOGO.jpg" width="275px;"> </td></tr>
<tr><th align="center" colspan="2">Kindly provide Login Details</th</tr>
<form method="post" name="Login" action="checkdb.php" onsubmit="return validation()" >
<tr><td align="right"><b>UserId : </td><td><input type="text" name="txtuid" placeholder="user"></td></tr>
<tr><td align="right"><b>Password : </td><td><input type="password" name="txtpwd" placeholder="*****"></td></tr>
<tr><td></td>
<td><font color="red">
<?php
if(isset($_SESSION['error']))
{
echo $_SESSION['error']."<br>";
echo "No Of Attempt ". $NoOfAttempt;
}
if($NoOfAttempt>=3)
echo "<br>Your Account Has been Locked..Contact Admin";
?> </font></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Sign in">
<input type="reset" value="Reset"><input type="hidden" name='NoOfAttempt' value= <?php echo $NoOfAttempt; ?> /></td>
</tr>
</form>
</div>
</div>
</table>
</body>
</html>
You are not retrieving the hidden form value NoOfAttempt in your validation() function.
var noofattempt=document.forms["Login"]["NoOfAttempt"].value;
Note that this will stop the user from accidentally submitting the form additional times after the limit has been reached, however as a previous commenter said, this can be easily overridden by someone who is trying to do so, or even possibly just by having Javascript disabled. So the limit should be enforced somewhere else in your PHP code.

need popup window inside a mysql table

i have a simple website which is written by php and mysql code. i have a detect button on my my sql table query page and given below code is writen for this function but my problem is i need a popup window when the detect link is clicked. i have tired to set a code in my created code but i am not able .kindly please help me solve this problem.
<?php $sezione="home_admin"; if(isset($_POST['messaggio']))
$messaggio=$_POST['messaggio'];
include("control_admin..php");
$canc_id=$_GET['canc_id'];
$idcorsocanc=$_POST['idcorsocanc'];
$action=$_REQUEST['action'];?>
<?php
/*echo "permessi".$permessi;
echo "<br>id".$id_nome;*/
if($action=='canc'){?>
<h1>are you sure want to delect the course?</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
<input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="Si,cancella" class="puls_invia">
</form>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="NO" class="puls_invia">
</form>
<?php
}
ok i want to update my question cause i follow one answer and here the code is-
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?php
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
//the form has been sent, do something
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
</form>
<? } ?>
</body>
</html>
but till now my problem is i alreday have link name delect and if i click that link i saw another delete button cause now i use the following code which i just update then if i click there i saw the pop up window but if i click ok that course is not delete cause i guess something is missing.
my actual need is i alreday have delect link and i need something that if i click on that i saw one opoup window.just this is my need.
You need a client-side script to manage this. I'd recommend something in jQuery.
<script type="text/javascript">
$(document).ready(function(){
$(".myButton").click(triggerPopup);
})
function triggerPopup(){
//do popup stuff
}
</script>
an example in more details can be found by googling. something like this http://istockphp.com/jquery/creating-popup-div-with-jquery/
You should do this in javascript. Especially with jquery library
This should look like this :
<?php
include("control_admin.php");
$sezione = "home_admin";
$canc_id = $_GET['canc_id']; //i'm gessing this is the ID to delete ?
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
$id = $_POST['id'];
$sql = "delete from table_name where column_id = ".$id;
mysql_query($sql);
echo $canc_id . ' has been deleted!';
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
<input type="hidden" id="id" name="id" value="<?=$canc_id?>">
</form>
<? } ?>
</body>
</html>

Get elRTE Content Via POST Method PHP

I am trying to store a content of elRTE into the database using PHP,
<script type="text/javascript" charset="utf-8">
// elRTE with elFinder on a textarea
$().ready(function() {
var opts = {
cssClass : 'el-rte',
$('#editor').elrte(opts);
})
</script>
<div id="finder"></div>
<form name="feedback" method="post">
<textarea id="editor" name="acontent" cols="50" rows="4"><?=$abt_content?></textarea>
<input type="submit" name="updabt" value="Submit"></td></tr>
</form>
<?php
if(isset($_POST['updabt']))
{
extract($_POST);
$q1=mysql_query(...);
if($q1==true)
{...}
else
{...}
}
?>
But I always get error "Undefined variable acontent"..
Any solution on this??
<form name="feedback" method="post">
<div id="finder"></div>
<textarea id="editor" name="acontent" cols="50" rows="4"><?=$abt_content?></textarea>
<input type="submit" name="updabt" value="Submit"></td></tr>
</form>
<?php
if(isset($_POST['updabt']))
{
extract($_POST);
$q1=mysql_query(...);
if($q1==true)
{...}
else
{...}
}
?>
Note: for editer you have to use div's id for POST as
$_POST['finder'];

php javascript alertbox have to click 2 times before it show

I'm doing php that is textbox a value empty it will open a alertbox (I'm using javascript in here )
this is my code
<?php
include('config.php');
if(isset($_POST['submit'])){
$username=$_POST['username'];
?>
<script>
function validate(){
if(document.forms[0].username.value==""){
window.alert("You must enter both values");
return false;
}
}
</script>
<?php
}
?>
<html>
<div><p>Member Profile</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username<br>
<input class="user" type="text" name="username" id="username" /><br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</html>
The problem is i have to click 2 times before the alert show
please help me to solve this problem
It's because the script is inside the php if(isset){} block, one click submits the form, which generates the script and then it works the second time.. try this setup instead:
<?php
include ('config.php');
if (isset($_POST['submit']))
{
$username = $_POST['username'];
}
?>
<html>
<head>
<script>
function validate () {
if (document.forms[0].username.value == "") {
window.alert("You must enter both values");
return false;
}
}
</script>
</head>
<body>
<div>
<p>
Member Profile
</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username
<br>
<input class="user" type="text" name="username" id="username" />
<br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</body>
</html>
Edit:
I've moved the script tag inside the head tag. I'm not sure if there are any implications for having the script outside but just to be sure I've moved it.
2nd Edit: (OCD is kicking in)
I've added body tags, not sure if you copied and pasted this code but it looked weird to me :)

Problems With Dynamic Form Using JavaScript and PHP

I'm having trouble with these files, see if you guys can help me out :)
I get an object required error..
index.php
<?php
//Start session
session_start();
//Require functions.php
require("functions.php");
//Require posts.php
require("posts.php");
?>
<html>
<body>
<title>Log Into Booking System</title>
<?php
//Call function to display login
displayLogin();
?>
</body>
</html>
posts.php
<?php
if (isset($_POST['sublogin']))
{
//Check that all fields were typed in and are not null
if(!$_POST['user'] || !$_POST['pass'])
{
//Call function to display error
printText("Please make sure all required fields are filled in.");
}
else
{
//Here is some database checking
}
}
?>
functions.php
<?php
function displayLogin()
{
//Break php, then return to PHP
?>
<h1>Login</h1>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td><div id='error'></div></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
</table>
</form>
<?
}
function printText($txtmsg)
{
?>
<!-- Set up the displayError javascript function -->
<script type="text/javascript">
function displayError()
{
document.getElementById('error').innerHTML = <?echo $txtmsg;?>;
}
</script>
<!-- Call function to Display the error -->
<script type="text/javascript">
displayError();
</script>
<?
}
?>
I'm pretty sure
document.getElementById('error').innerHTML
Is causing me problems, i think it might have to do with how im calling it, like it dosent know what its looking for..
Thanks guys much appreciated,
Jenny
EDIT: Here is the paste of what jQuerybeast tried to do, http://pastebin.com/jj0RVMAd
SOLUTION: Who knew it was this easy? You MUST change the order of where posts.php is required as well as make sure you don't call a javascript function within functions.php because that will execute the javascript above the form and therefore giving a null object error.
Index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Log Into Booking System</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<?php
//Start session
session_start();
//Require functions.php
require("functions.php");
?>
</head>
<body>
<?php
//Call function to display login
displayLogin();
//Require posts.php
require("posts.php");
?>
</body>
</html>
posts.php
<?php
//POST: Main login page
if (isset($_POST['sublogin']))
{
//Display error if feilds are not filled in
if(!$_POST['user'] || !$_POST['pass'])
{
echo '<script type="text/javascript">document.getElementById("error").innerHTML = "Please make sure all required fields are filled in.";</script>';
return false;
}
else
{
//Some database minipulation here....
//...
if ($_POST['user'] != $databaseUsername)
{
echo '<script type="text/javascript">document.getElementById("error").innerHTML = "Please make sure your username is correct.";</script>';
return false;
}
elseif($_POST['pass'] != $databasePassword)
{
echo '<script type="text/javascript">document.getElementById("error").innerHTML = "Please make sure your password is correct.";</script>';
return false;
}
}
return true;
}
?>
functions.php
<?php
//Function: Display main.php login
function displayLogin()
{
//Break php, then return to PHP
?>
<div style="float: left; padding: 10px; width:20%;">
<fieldset>
<legend>
<h1>Login</h1>
</legend>
<form name = "mainlogin" action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember">
<font size="2">Remember username and password</td></tr>
<tr><td><div id="error"></div></tr><td>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
</table>
</form>
</fieldset>
</div>
<?php
}
?>
The first thing I notice is that the PHP-echoed string inside the Javascript function doesn't have quotation marks around it.
Change:
function displayError()
{
document.getElementById('error').innerHTML = <?echo $txtmsg;?>;
}
To:
function displayError()
{
document.getElementById('error').innerHTML = "<?echo $txtmsg;?>";
}
I think the problem is caused from functions.php is because you open and close PHP the opposite way.
Instead of ?> <?
Try: <? ?>
Which is this:
function displayLogin()
{
//Break php, then return to PHP
<?
<h1>Login</h1>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td><div id='error'></div></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
</table>
</form>
?>
}
function printText($txtmsg)
{
<?
<!-- Set up the displayError javascript function -->
<script type="text/javascript">
function displayError()
{
document.getElementById('error').innerHTML = <?echo $txtmsg;?>;
}
</script>
<!-- Call function to Display the error -->
<script type="text/javascript">
displayError();
</script>
?>
}
change
document.getElementById('error').innerHTML = <?echo $txtmsg;?>;
to
document.getElementById('error').innerHTML = '<?= $txtmsg; ?>';
or
document.getElementById('error').innerHTML = '<?php echo $txtmsg; ?>';
Use this
document.getElementById('error').innerHTML = '<?php echo $txtmsg; ?>';
and
It seems short tag is not enabled on your server. Please make sure.
Or always use <?php ?> instead of <? ?>

Categories