I need an extra set of eyes here. I've been over this numerous times with no success. The issue is the getFilename function, which as the name suggests, is supposed to get the file name of the uploaded file. No matter what I do, it doesn't seem to work, so I must be missing something.
<?php
$data = $_GET["data"];
if($data)
{
echo '
<head>
<style>
.atklf
{
color: Red;
background: #292929;
border: 1px solid Red
}
</style>
</head>
<iframe name="fuh1" style="display: none;"></iframe>
<form
action="attklstformupldproc.php"
method="post"
target="fuh1"
enctype="multipart/form-data">
<table border="2" cellpadding="3" frame="void" style="color: red; width:100%;">
<tr>
<td>Priority:</td>
<td>Pirate: <span id="Pirreq"></span></td>
<td>Level:</td>
<td>Known Fleet Level:</td>
<td>X:</td>
<td>Y:</td>
</tr>
<tr>
<td>
<select id="Priority" class="atklf" name="Priority">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
<td><input id="Pirate" class="atklf" name="Pirate" type="text" size="17" /></td>
<td><input id="Level" class="atklf" name="Level" type="text" size="4" /></td>
<td><input id="Fleet_Level" class="atklf" name="Fleet_Level" type="text" size="4" /></td>
<td><input id="XCoord" class="atklf" name="XCoord" type="text" size="5" /></td>
<td><input id="YCoord" class="atklf" name="YCoord" type="text" size="5" /></td>
</tr>
<tr>
<td>Outpost Level:</td>
<td>Known Wall Level:</td>
<td>Known Turret Level:</td>
<td colspan="2">Turret Types:</td>
<td>Group: <span id="Grpreq"></span></td>
</tr>
<tr>
<td><input id="Outpost_Level" class="atklf" name="Outpost_Level" type="text" size="4" /></td>
<td><input id="Knwn_wall_lvl" class="atklf" name="Knwn_wall_lvl" type="text" size="4" /></td>
<td><input id="Knwn_turr_lvl" class="atklf" name="Knwn_turr_lvl" type="text" size="4" /></td>
<td colspan="2" rowspan="2"><textarea id="Turret_Types" class="atklf" name="Turret_Types" rows="5" cols="16"></textarea></td>
<td rowspan="2">
<select id="Group" class="atklf" name="Group">
<option value="null">Pick a group</option>
<option value="General">General</option>
<option value="Sector 23">Sector 23</option>
<option value="Max Chaos">Max Chaos</option>
</select>
</td>
</tr>
<tr>
<td>Base Picture:</td>
<td colspan="2"><input id="Base_Picture" name="uploaded_bp" class="atklf" type="file" /></td>
</tr>
<tr>
<td colspan="6">Notes:</td>
</tr>
<tr>
<td rowspan="1" colspan="6"><textarea id="Notes" class="atklf" name="Notes" rows="7" cols="60"></textarea></td>
</tr>
<tr>
<td align="center"><input id="hlfsubmit" class="atklf" name="submit" value="Submit" type="submit" style="width: 90px;" onClick="assignVars()" /></td>
</tr>
<input type="button" class="atklf" value="Reset debug" onClick="resetDebug()"/>
<input type="button" class="normal" value="Get File name" onClick="getFilename1()"/>
</table>
</form>
<script type="text/javascript">
function resetDebug() {
document.getElementById("debug1").innerHTML = "";
}
function formFieldvalue(id) {
return document.getElementById(id).value;
}
function getFilename1() {
document.getElementById("debug1").innerHTML = formFieldvalue("Base_Picture");
}
Pri = "1";
Pir = "null";
Grp = "null";
function assignVars () {
Pri = document.getElementById("Priority").options[document.getElementById("Priority").selectedIndex].value;
Pir = encodeURIComponent(formFieldvalue("Pirate"));
if (formFieldvalue("Level")) {
Lvl = encodeURIComponent(formFieldvalue("Level"));
}
else {
Lvl = encodeURIComponent("?");
}
if (formFieldvalue("Fleet_Level")) {
Flv = encodeURIComponent(formFieldvalue("Fleet_Level"));
}
else {
Flv = encodeURIComponent("?");
}
if (formFieldvalue("XCoord")) {
XCd = encodeURIComponent(formFieldvalue("XCoord"));
}
else {
XCd = encodeURIComponent("?");
}
if (formFieldvalue("YCoord")) {
YCd = encodeURIComponent(formFieldvalue("YCoord"));
}
else {
YCd = encodeURIComponent("?");
}
if (formFieldvalue("Notes")) {
Nts = encodeURIComponent(formFieldvalue("Notes"));
}
else {
Nts = encodeURIComponent("?");
}
if (formFieldvalue("Outpost_Level")) {
Opl = encodeURIComponent(formFieldvalue("Outpost_Level"));
}
else {
Opl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_wall_lvl")) {
Kwl = encodeURIComponent(formFieldvalue("Knwn_wall_lvl"));
}
else {
Kwl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_turr_lvl")) {
Ktl = encodeURIComponent(formFieldvalue("Knwn_turr_lvl"));
}
else {
Ktl = encodeURIComponent("?");
}
if (formFieldvalue("Turret_Types")) {
Tty = encodeURIComponent(formFieldvalue("Turret_Types"));
}
else {
Tty = encodeURIComponent("?");
}
Grp = encodeURIComponent(formFieldvalue("Group"));
insertAttacktablerow();
}
if ( window.addEventListener ) {
window.addEventListener( "load", insertAttacktablerow, false );
}
else if ( window.attachEvent ) {
window.attachEvent( "onload", insertAttacktablerow );
}
function insertAttacktablerow() {
if (Pir != "null" && Grp != "null") {
document.getElementById("Pirreq").innerHTML = "";
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) {
//updateAttacktable();
document.getElementById("debug1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/attacklist/attklstformproc.php?Pri=" + Pri + "&Pir=" + Pir + "&Lvl=" + Lvl + "&Flv=" + Flv + "&XCd=" + XCd + "&YCd=" + YCd + "&Nts=" + Nts + "&Opl=" + Opl + "&Kwl=" + Kwl + "&Ktl=" + Ktl + "&Tty=" + Tty + "&Grp=" + Grp + "&data=' . $data . '",true);
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.send();
document.forms[0].reset();
}
else if (Pir == "null") {
document.getElementById("Pirreq").innerHTML = "(<b>required</b>)";
document.getElementById("Pirreq").style.color = "red";
}
else if (Grp == "null") {
document.getElementById("Grpreq").innerHTML = "(<b>required</b>)";
document.getElementById("Grpreq").style.color = "red";
}
}
</script>
<span id="debug1"></span>';
}
else
{
echo 'Restricted access.';
}
OK, so I removed my last answer because I finally took the time to execute your code. As you have it, it works for me.
Here's what I suggest you do. Remove your HTML and JavaScript and place them in a stand alone html file and load it in your browser. Add the necessary tags to make it complete. (Also, you're missing a "body" tag, not that this is the source of your problem.)
Then test it. If it works, then your problem is coming from somewhere else not in the code you provided. Do you have header and footer code somewhere?
If it doesn't work, start removing HTML and JavaScript in portions until it does work. Use this to isolate the cause of your bug.
Good luck.
Related
When I select something in bill.php, it ajax call and get value from get user.php then it display content on bill.php the page but how could I hold those value in a variable in bill.php page for further use in php
<?php
include('db.php');
?>
<html>
<head>
<style>
table, tr th{
border: green;
}
th {
}
</style>
<script type="text/javascript">
function updatesum()
{
document.form.sum.value = (document.form.sum2.value -0);
document.form.sumone.value = (document.form.sum3.value -0) ;
document.form.sumtotal.value = (document.form.sum.value -0) * (document.form.sumone.value -0);
document.form.sumtotalgiven.value=(document.form.sumtotalmoney.value -0) - (document.form.sumtotal.value -0);
}
</script>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
//document.getElementById("txtHin").innerHTML = "";
return;
} else {
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("txtHint").innerHTML = xmlhttp.responseText;
//document.getElementById("txtHin").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<script>
function shoUser(str) {
if (str == "") {
document.getElementById("txtHin").innerHTML = "";
return;
} else {
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("txtHin").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body bgcolor="#C7CBE1">
<form method="get" name="form">
<table border="0" bordercolor="#D83E41">
<tr>
<td> medicine </td>
<td> price batchno
expire date</td>
<td>
quantity</td>
<td>
Total </td>
</tr>
<tr>
<td>
<?php
$qry="select * from inventory";
$rs=mysql_query($qry);
?>
<select name="user" onchange="showUser(this.value)">
<option value=>selet medicine name</option>
<?php
while($rw=mysql_fetch_array($rs)){
?>
<option value="<?php echo $rw['id']?>"><?php echo $rw['medicine']?></option>
<?php
}
?>
</select>
</td>
<td>
<div id="txtHint">
</div>
</td>
<td>
<input type="text" name="sum2" style="width: 70px" onChange="updatesum()" ></td>
<td>
<input name="sum" readonly " style="width: 70px"></td>
</tr>
<tr>
<td>
<?php
$qry="select * from inventory";
$rs=mysql_query($qry);
?>
<select name="user" onchange="shoUser(this.value)">
<option value=>selet medicine name</option>
<?php
while($rw=mysql_fetch_array($rs)){
?>
<option value="<?php echo $rw['id']?>"><?php echo $rw['medicine']?></option>
<?php
}
?>
</select>
</td>
<td>
<div id="txtHin">
</div>
</td>
<td>
<input type="text" name="sum3" style="width: 70px" onChange="updatesum()" ></td>
<td>
<input name="sumone" readonly " style="width: 70px"></td>
<td>
</td>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td> total<input name="sumtotal" readonly style="border:0px;"> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td> paid<input type="text" name="sumtotalmoney" style="border:0px;" onChange="updatesum()"> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td> Return<input name="sumtotalgiven" readonly style="border:0px;" > </td>
</tr>
</table>
</form>
<br>
</body>
</html>
<?php
include("db.php");
?>
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, td, th {
/* border: 1px solid black;*/
/* padding: 5px;*/
text-align: center;
}
th {text-align: left;}
</style>
<body>
<?php
$q = intval($_GET['q']);
//echo $q;
$qry="SELECT * FROM inventory WHERE id = '".$q."'";
$rs=mysql_query($qry);
?>
<?php
while($rw=mysql_fetch_array($rs)){
?>
<table>
<tr>
<td>
<?php echo " ". " ". " ". " ". " " . " ". " ". " " ?>
<?php echo $rw['price']?> <?php echo " ". " " . " " . " " . " ". " ". " ". " ". " ". " ". " ". " "
. " ". " ". " " ?>
<?php echo $rw['batchno'] ?>
<?php echo " ". " " . " " . " " . " ". " ". " ". " ". " ". " ". " ". " "
. " ". " ". " " ?>
<?php echo $rw['expire'] ?>
</td>
</tr>
</table>
<?php
}
?>
</body>
</html>
Read more about sessions in php.
If you need to store some values between php files you can do it like:
<?php
session_start();
$_SESSION['myVariable'] = $_GET['myVariable'];
In another php file you can get the previous defined variable as:
<?php
session_start();
echo $_SESSION['myVariable'];
<head>
<title> Add User page</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<form name='f2' action="insert_ac.php" method="post" >
<script src="validation.js" type="javascript/text"></script>
</head>
<body onload="firstfocus();">
<table align="center" border="0" cellpadding="3" cellspacing="1">
<tr>
<td> First Name</td><td > : </td>
<td> <input type='text' name='fname' id='fid' size="50" style="background-color:#abcddd; height:18px;" value='' maxlength="100" onblur="fname_validation(5,12);"> </td>
</tr>
<tr>
<td> Last Name</td><td> : </td>
<td> <input type='text' name='lname' id='lid' size="50" style="background-color:#abcddd; height:18px; "value='' maxlength="100" onblur="lname_validation(5,12);"> </td>
</tr>
<tr>
<td> Gender</td><td> : </td>
<td> <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
</tr>
<tr>
<td> Phone Number</td><td> : </td>
<td> <input type='number_format' name='phone' id='phno'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="allnumeric();"></td>
</tr>
<tr>
<td> Work Experiance</td><td> : </td>
<td><select name="exp" onblur="expselect();">
<option > Select One</option>
<option selected="" value="Default"> Select One </option>
<option value="F"> Fresher </option>
<option value="E"> Experiance</option>
</select></td>
</tr>
<tr>
<td>User Name</td><td>:</td><td> <input type='txt' name='uname' id='uid'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="userid_validation(5,10);"> </td>
</tr>
<tr>
<td>Password</td><td>:</td><td> <input type='password' name='pwd' id='pid' size="50" style="background-color:#abcddd; height:18px; " value=''onblur="passid_validation(7,12);"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td width="84"><input name="enter" class="btn_login" type="submit" value="Submit" onsubmit="alert('Data stored successfully');"/> <input name="cancle" class="btn_login" type="reset" value="Cancle" /></td>
</tr>
</table>
</form>
</body>
</html>
I included the external javascript file using script tag but the validations are not working.
This is my external javascript code which was saved as validation.js and i am unable to find errors in it please help me.
// After form loads focus will go to first name field.
function firstfocus()
{
var fname = document.f2.fname.focus();
return true;
}
// This function will validate First name
function fname_validation(mx,my)
{
var fname = document.f2.fname;
var fname_len = fname.value.length;
var letters = /^[A-Za-z]+$/;
if (fname_len == 0 || fname_len >= my || fname_len < mx)
{
alert("First Name should not be empty / length be between "+mx+" to "+my);
fname.focus();
return false;
if(fname.value.match(letters))
{
// Focus goes to next field i.e.Last Name
document.f2.lname.focus();
return true;
}
}
}
// This function will validate Last name
function lname_validation(mx,my)
{
var lname = document.f2.lname;
var lname_len = lname.value.length;
var letters = /^[A-Za-z]+$/;
if (lname_len == 0 || lname_len >= my || lname_len < mx)
{
alert("Last Name should not be empty / length be between "+mx+" to "+my);
lname.focus();
return false;
if(fname.value.match(letters))
{
// Focus goes to next field i.e.Phone Number
document.f2.phone.focus();
return true;
}
}
}
// This function will validate Phone Number.
function allnumeric()
{
var phone = document.f2.phone;
var numbers = /^[0-9]+$/;
if(phone.value.match(numbers))
{
// Focus goes to next field i.e. Experiance.
document.f2.exp.focus();
return true;
}
else
{
alert('Phone Number must have numeric characters only');
phone.focus();
return false;
}
}
// This function will select Experiance.
function expselect()
{
var exp = document.f2.exp;
if(exp.value == "Default")
{
alert('Select your Experiance from the list');
exp.focus();
return false;
}
else
{
// Focus goes to next field i.e. Username Code.
document.f2.uname.focus();
return true;
}
}
// This function will validate User Name.
function allLetter()
{
var uname = document.f2.uname;
var letters = /^[A-Za-z]+$/;
if(uname.value.match(letters))
{
// Focus goes to next field i.e. Password.
document.f2.pwd.focus();
return true;
}
else
{
alert('Username must have alphabet characters only');
uname.focus();
return false;
}
}
// This function will validate Password.
function passid_validation(mx,my)
{
var passid = document.registration.passid;
var passid_len = passid.value.length;
if (passid_len == 0 ||passid_len >= my || passid_len < mx)
{
alert("Password should not be empty / length be between "+mx+" to "+my);
passid.focus();
return false;
}
}
try to change <script type="javascript/text"> to <script type="text/javascript">
and double check the reference of your js file. Also, put an alert check to determine if it is really going through the firstFocus() function.
You have to reference the .js if its not in the same folder as html
EDIT
function fname_validation(mx,my)
{
is missing a closing bracket!
I changed the java script file and now i can find validations in my form...
Thanks for your help..
here i am sharing my code...
HTML code
<form name='f1' action="insert_ac.php" method="post" onSubmit="return validateForm();" >
<tr>
<td height="25" height="25" colspan="2" bgcolor="#EC6921" class="form_heading">Add User Form</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt"> First Name:</td>
<td bgcolor="#FFFFFF"> <input type='text' name='fname' id='fid' size="50" style="height:18px;" value='' maxlength="100" ></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt"> Last Name:</td>
<td bgcolor="#FFFFFF" > <input type='text' name='lname' id='lid' size="50" style=" height:18px; "value='' maxlength="100" ></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt"> Gender:</td>
<td bgcolor="#FFFFFF" > <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt"> Phone Number:</td>
<td bgcolor="#FFFFFF" > <input type='number_format' name='phone' id='phno'size="50" style=" height:18px; " value=''></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt"> Work Experiance:</td>
<td bgcolor="#FFFFFF" ><select name="exp" >
<option selected="" value="Default"> Select One </option>
<option value="Fresher"> Fresher </option>
<option value="Experiance"> Experiance</option>
</select></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt">User Name:</td><td bgcolor="#FFFFFF"> <input type='txt' name='uname' id='uid'size="50" style=" height:18px; " value=''></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="28" class="form_txt">Password:</td><td bgcolor="#FFFFFF"> <input type='password' name='pwd' id='pid' size="50" style=" height:18px; " value=''></td>
</tr>
</table>
<table align="center">
<tr>
<td ><input name="enter" class="btn_login" type="submit" value="Submit" align="center"><input name="cancle" class="btn_login" type="reset" value="Cancle" valign="right" /></td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
Here is my java script file which is working fine....
var RE = /^.+#.+\..{3}$/;
var RE1 = /^[a-zA-Z]+$/;
var RE2 = /^[0-9]{10}$/;
var RE3 = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
function validateForm()
{
if (document.f1.fname.value == "")
{
window.alert("first name should NOT BE empty");
document.f1.fname.focus();
return false;
}
else
if (RE1.test(document.f1.fname.value) == false)
{
alert("Invalid first name\n\
");
return false;
}
else
if (document.f1.fname.value.length < 3)
{
window.alert("Firstname must have atleast Three characters");
document.f1.fname.focus();
return false;
}
else
if (document.f1.lname.value == "")
{
window.alert("Lastname should not be empty");
document.f1.lname.focus();
return false;
}
else
if (RE1.test(document.f1.lname.value) == false)
{
alert("Invalid last name");
return false;
}
else
if (document.f1.lname.value.length < 4)
{
window.alert("Lastname must have atleast four characters");
document.f1.lname.focus();
return false;
}
else
if (document.f1.lname.value == "")
{
window.alert("Last name should not be empty");
document.f1.lname.focus();
return false;
}
else
if (document.f1.phone.value == "")
{
window.alert("phne no should NOT BE empty");
document.f1.phone.focus();
return false;
} else
if (RE3.test(document.f1.phone.value) == false)
{
alert("Invalid phone number");
document.f1.phone.focus();
return false;
}
else
if (document.f1.exp.selectedIndex == 0)
{
window.alert("please select work experiance ");
return false;
}
else
if (document.f1.uname.value == "")
{
window.alert("UserName should not be empty");
document.f1.uname.focus();
return false;
}
else
if (RE1.test(document.f1.uname.value) == false)
{
window.alert("Invalid userName ");
document.f1.uname.focus();
return false;
}
else
if (document.f1.pwd.value == "")
{
window.alert("password should not be empty");
document.f1.pwd.focus();
return false;
}
else
if (document.f1.pwd.value.length < 6)
{
window.alert("password must have atleast six characters");
document.f1.pwd.focus();
return false;
}
else
{
window.alert("User has been added successfully.");
return true;
}
}
I have table player_points with player_name, runs, sixes, match_no, fiftys, hundreds, point_scored.
I make form with above fields where i insert runs and sixes and calculate fiftys, hundreds and point_scored using runs & sixes, give extra 10 points for every sixex after 3 six.
Its works properly but when i insert runs and sixes and save it only shows calculation in fiftys, hundred and point-scored textbox not saved into database table. After i saved it second time its save into database. My code is like below:
<tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>
<tr>
<th>Player</th>
<th>Status</th>
<th>Runs</th>
<th>6's</th>
<th>50's</th>
<th>100's</th>
<th>TP</th>
<th>Action</th>
</tr>
<tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>
<?php
$classObj->getPlayerPointTable();
//$matchid = $_GET['mid'];
$condpl = "player_name='".$player1."' AND match_no = '".$matchid."'";
$resultpl = $classObj->selectSql($condpl);
//$recordcount = $classObj->getAffectedRows($result);
$rowpl = $classObj->fetchData($resultpl);
foreach($rowpl as $rowspl)
{
$Status1 = $rowspl['status'];
$runs1 = $rowspl['run_scored'];
$sixes1 = $rowspl['sixs'];
$fifty1 = $rowspl['fifty'];
$hundred1 = $rowspl['hundred'];
$total_score1 = $rowspl['Total_Score'];
$total_points1 = $rowspl['point_scored'];
$firstPoint1 = $rowspl['FirstPoint'];
$allocation1 = $rowspl['allocation'];
}
?>
<?php
$bonus1 = 10;
$bonus2 = 20;
$bonus3 = 25;
$bonus4 = 50;
/*condition for fifty 0 & 1 start */
if ($runs1 >= 50 && $runs1 <= 99 || $runs1 >= 150 && $runs1 <= 199 || $runs1 >= 250 && $runs1 <= 299) {
$fifty1 = 1;
} else {
$fifty1 = 0;
}
if ($runs1 >= 50 && $runs1 <= 499) {
$tfif1 = $runs1 + $bonus3;
} else {
$tpor1 = $runs1;
}
/*condition for fifty 0 & 1 end */
/*condition for hundred 0 & 1 start */
if ($runs1 >= 100 && $runs1 <= 199) {
$hundred1 = 1;
}
else if ($runs1 >= 200 && $runs1 <= 299) {
$hundred1 = 2;
}
else {
$hundred1 = 0;
}
/*condition for hundred 0 & 1 end */
/*Condition start for Six excess to 3 sixes*/
$i1 = $sixes1 - 3;
if($i1 >= 1 && $i1 <= 500)
{
$tsix1 = $i1 * $bonus1;
}
else
{
$tsix1 == 0;
}
/*Condition start for Six excess to 3 sixes*/
if($fifty1 == 1 && $hundred1 >= 1)
{
$tsixhnrd1 += $bonus4;
}
/*condition for hundred 0 & 1 end */
if ($runs1 >= 100 && $runs1 <= 500) {
$trun1 += $bonus3;
}
$total_points1 = $tfif1+$tsix1+$tsixhnrd1+$trun1+$tpor1;
$total_score1 = $runs1;
/*veriable for Balling team database insertions end*/
?>
<form enctype="multipart/form-data" method="post" name="formA1">
<tr>
<td><div style="width:auto;padding-left:7px;font-size:17px;"><?php echo $player1;?></div>
<input type="hidden" name="player1" id="player1" value="<?php echo $player1;?>" />
<input type="hidden" name="matchid" id="matchid" value="<?php echo $matchid;?>" />
</td>
<?php
if($Status1=='P'){
?>
<td align="center">
<select id='status1' name='status1' onChange="dis_ableA1(this)">
<option value='NP'>NP</option>
<option value='P' selected>P</option>
<option value='O'>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#f5c0c0;" name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#f5c0c0;" name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php
} else if($Status1=='O'){
?>
<td align="center">
<select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)">
<option value='NP'>NP</option>
<option value='P'>P</option>
<option value='O' selected>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#ccc;" disabled name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#CCC;" disabled name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php } else { ?>
<td align="center">
<select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)" tabindex="1">
<option value='NP'>NP</option>
<option value='P'>P</option>
<option value='O'>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;" name="runs1" disabled id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;" name="sixes1" disabled id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php }?>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $fifty1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="fifty1" name="fifty1" value="<?php echo $fifty1;?>" size='2' maxlength='2' />
</td>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $hundred1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="hundred1" name="hundred1" value="<?php echo $hundred1;?>" size='2' maxlength='2' />
</td>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $total_points1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="total_points1" name="total_points1" value="<?php echo $total_points1;?>" size='5' maxlength='5' />
<input type="hidden" name="allocation1" id="allocation1" value="pending" />
</td>
<?php
if($Status1=='P'){
?>
<td align="center">
<input type="submit" name="submitA1" id="submitA1" value="Save" />
</td>
<?php } else { ?>
<td align="center">
<input type="submit" disabled="disabled" name="submitA1" id="submitA1" value="Save" />
</td>
<?php } ?>
</tr>
</form>
<tr><td style="height:5px"></td></tr>
<!-- Insert Code Starts Submit1-->
<?php
if(isset($_POST['submitA1']))
{
$classObj->getPlayerPointTable();
$matchid = $_GET['mid'];
$cond = "player_name='".$player1."' AND match_no = '".$matchid."'";
$result = $classObj->selectSql($cond);
$count = $classObj->getAffectedRows($result);
//echo $count;
if($count > 0)
{
$player1up['status'] = $postedData['status1'];
//$player1up['player_name'] = $postedData['player1'];
$player1up['run_scored'] = $postedData['runs1'];
$player1up['sixs'] = $postedData['sixes1'];
$player1up['fifty'] = $postedData['fifty1'];
$player1up['hundred'] = $postedData['hundred1'];
$player1up['Total_Score'] = $postedData['total_score1'];
$player1up['point_scored'] = $postedData['total_points1'];
$player1up['allocation'] = $postedData['allocation1'];
$player1up['FirstPoint'] = $postedData['total_points1'];
$classObj->getPlayerPointTable();
$classObj->userPostedData = $player1up;
$cond = "match_no= '".$matchid."' AND player_name='".$player1."'";
$insert_query = $classObj->updateData($cond);
echo "<script> alert ('Player 1 update successfully.')</script>";
echo "<script>window.location='FirstIn.php?mid=$matchid'</script>";
}
else if($count <= 0)
{
$player['player_name'] = $postedData['player1'];
$player['match_no'] = $postedData['matchid'];
$player['status'] = $postedData['status1'];
$player['run_scored'] = $postedData['runs1'];
$player['sixs'] = $postedData['sixes1'];
$player['fifty'] = $postedData['fifty1'];
$player['hundred'] = $postedData['hundred1'];
$player['Total_Score'] = $postedData['total_score1'];
$player['point_scored'] = $postedData['total_points1'];
$player['FirstPoint'] = $postedData['total_points1'];
$classObj->userPostedData = $player;
$insert_query = $classObj->insertData();
if($insert_query == 'success')
{
echo "<script> alert('Player 1 score added.')</script>";
echo "<script>window.location='score.php?mid=$matchid'</script>";
}
}
else
{
echo "<script> alert ('Error Occured')</script>";
}
}
?>
Assuming that your class' getAffectedRows() method really fetches the affected rows from the last statement, it must be noted that a SELECT does not set this, it will be zero.
If you want to know how many lines were selected, use something like mysqli_num_rows.
in this code,error message shows error by alert box,but i want to see error message below particular text box. mean when i click on submit button which field not fill, below that field it should display message below that field.
and also there is one problem if i not fill radio button or checkbox and other all are filled and when i click on submit button it store in database other all detail except that radio or checkbox.
so how can i solve it
Thanks.....
<!DOCTYPE html>
<?php
session_start();
if (!isset($_SESSION['txt_user'])) {
header('Location: Login.php');
}
?>
<html>
<head>
<title> Form with Validation </title>
<script language="JavaScript">
var file_selected = false;
var file_selected1 = false;
function validform()
{
var x=document.forms["form1"]["tname"].value;//Name
var y=document.forms["form1"]["address"].value;//Address
var psel=document.getElementById('fp'); //Favourite place
var valid = false;
for(var i = 0; i < psel.options.length; i++) {
if(psel.options[i].selected) {
valid = true;
break;
}
}//Favourite place
if (x==null || x=="")
{
alert("Please Enter Name:");
//flag = 0;
}
if (y==null || y==" ")
{
alert("Please Enter Address");
}
if ((form1.gender[0].checked == false) && (form1.gender[1].checked == false))
{
alert("Pleae Select Gender");
}
if (form1.hobby.checked == false && form1.hobby.checked == false && form1.hobby.checked == false)
{
alert ('Please!!!, Select any hobby!');
}
if(valid==false)
{
alert("Please! Select Any Favourite Place ");
}
if(!file_selected)
{
alert('Please Select any Picture');
}
if(!file_selected1)
{
alert('Please Select any Document');
return false;
}
{
document.getElementById('data_form').action = "Data_con.php";
return false;
}
return false;
}
function Logout()
{
document.getElementById('data_form').action = "Logout.php";
}
</script>
</head>
<body>
<!--onsubmit="return validform()"-->
<form id="data_form" name="form1" method="post" enctype="multipart/form-data" action="">
<table align="center" border="2">
<tr>
<td>Name:</td>
<td><input type="text" name="tname"></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea rows="3" cols="16" name="address"> </textarea> </td>
</tr>
<tr>
<td>Gender:</td>
<td> <input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
</td>
</tr>
<tr>
<td>Hobby:</td>
<td>
<input type="checkbox" name="hobby" value="hockey"> Hockey
<input type="checkbox" name="hobby" value="reading"> Reading<br>
<input type="checkbox" name="hobby" value="traveling"> Traveling
<br>
</td>
</tr>
<tr>
<td>Country: </td>
<td>
<select name="helo">
<option value="germany">Germany </option>
<option value="india" selected>India </option>
<option value="japan">Japan </option>
</select>
</td>
</tr>
<tr>
<td>Favourite Place:</td>
<td>
<select id="fp" name="place" multiple="multiple">
<option value="ahmedabad">Ahmedabad</option>
<option value="nadiad">Nadiad</option>
<option value="anand">Anand</option>
<option value="vadodara">Vadodara</option>
<option value="surat">Surat</option>
</select>
</td>
</tr>
<tr>
<td>Photo:</td>
<td><input type="file" onchange="file_selected=true;" name="pic" ></td>
</tr>
<tr>
<td>Resume:</td>
<td><input type="file" onchange="file_selected1=true;" name="doc" ></td>
</tr>
<tr>
<td colspan="2"><center>
<input type="submit" value="Submit" Name="Submit" onclick="validform();">
<input type="submit" value="Logout" Name="Submit" onclick="Logout();">
<center></td>
</tr>
</table>
</form>
</body>
</html>
you first create tds with different id's for each and every input field
instead of alert
document.getElementById('td id').innerHTML="your message";
return false;
like this
<tr>
<td>Favourite Place:</td>
<td>
<select id="fp" name="place" multiple="multiple">
<option value="ahmedabad">Ahmedabad</option>
<option value="nadiad">Nadiad</option>
<option value="anand">Anand</option>
<option value="vadodara">Vadodara</option>
<option value="surat">Surat</option>
</select>
</td>
<td id="fp_error"></td>
</tr>
and in javascript
document.getElementById('fp_error').innerHTML="your message";
return false;
download jquery.js and jquery.validate.js and validate form elements using below demo code.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> </script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.validate.js"> </script>
<script>
$('document').ready(function() {
$('#data_form').validate({
rules: {
'tname': {
required: true
},
'address': {
required: true
}
},
messages:{
'tname': {
required: 'Please Enter Name'
},
'address': {
required: 'Please Enter address'
}
}
});
});
</script>
It is better way. Easy of implementation and also saves time.
Hi, I have a form which has an ajax function which appends the data when the user enters the code and selects a value from the combo box. Since the data which is appended has dynamic rows I want to validate those input boxes so that a user can only enter a value such as 01, 02, 03....10 and if the user tries to enter a value which is greater than 10 it should display an alert box. So far, I have the script which does that but since the name attribute keeps on changing the validation doesn't seem to work. Can anyone help me out please?
Here is my JavaScript code:
function getXMLHTTP() { //function to return the xml http object
var xmlhttp = false;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
xmlhttp = false;
}
}
}
return xmlhttp;
}
function getfunit2(makhcode, cmbmon) {
var strURL = "subjsele2.php?makhcode=" + document.nigran.makhcode.value + "&cmbmon=" + document.nigran.cmbmon.value;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function () {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('suboth').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("POST", strURL, true);
req.send(null);
}
}
Here is my PHP code:
<?php
$makhcode=$_GET["makhcode"];
$cmbmon=$_GET["cmbmon"];
$monno1 = "mon$cmbmon";
$con = mysql_connect('localhost', '****', '*****');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$scomp = mysql_query("SELECT * FROM subject WHERE compulsory !='1' ORDER BY ordby")or die(mysql_error());
if(mysql_num_rows($scomp)>0){
echo "<table>";
while($csub = mysql_fetch_assoc($scomp)){
$msubjcode = $csub["code"];
$csubqry = mysql_query("SELECT * FROM nigstat WHERE makhcode='".$makhcode."' AND subcode='".$msubjcode."'") or die(mysql_error());
$fetchmon = mysql_fetch_array($csubqry) ;
$mmonval = $fetchmon["$monno1"];
echo "<tr>";
echo "<td width='200px'><font color='#FF0033'><strong>".$csub[name]."</strong></td><td><input id='s_id' name='s_$csub[code]' type='text' onkeypress=\"return chknum()\" size='1' maxlength='2' value='$mmonval'></td><input type='hidden' name='$mmonval' size='3' maxlength='3'>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>
Here is my HTML code:
<table border ="0px" width="100%">
<tr>
<td align="right" width="58px"><label class="" for="element_1"><font size="3px"><b>Code</b></font></label></td><td><input id="makhcode" name="makhcode" onkeyup="showyear('makhsele.php?makh='+this.value); getfunit(); getfunit2();" type="text" maxlength="6" size="6" value=""/></td><td><label class="description" align="right" for="element_1">Month</label></td><td><select id="cmbmon" name="cmbmon" class="" onchange="getfunit(); getfunit2();" style="font-size:14px;">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</td>
</tr>
</table>
<p style="border-bottom: 1px dotted #ccc;"></p>
<div id="makhhint" style=""></div>
<p style="border-bottom: 1px dotted #ccc;"></p><br />
<table border="0px" width="100%" cellspacing="0" cellpadding="0">
<th><div class="form_description"><h2>Compulsory Subjects</h2></div></th>
<th><div class="form_description"><h2>Other Subjects</h2></div></th>
<tr>
<td style="vertical-align: top;">
<div id="subcomp" align="left" align="top" style="background-color: #99FFFF;border: 1px solid black;padding:10px;">
</div>
</td>
<td style="vertical-align: top;">
<div id="suboth" align="left" align="top" style="background-color: #FFFFCC;border: 1px solid black;padding:10px;">
</div>
use this function to validate code
<input type="text" id="fname" onkeyup="validate_code(this)">
function validate_code(that)
{
if(isNaN(that.value)==true || that.value>10)
{
that.value='';
alert('enter a valid value');
}
return true
}
link to example validation example