SQL shown no record after submit INSERT - php

When I submit an SQL query there is no record created in the database, but also no error message is displayed.
** Sorry for long code because I don't know where is the problem with the code and I also just have basic knowledge in programming.
I am using 2 different tables for query and insert:
<?php
if(isset($send))
{
$today=date('Y-m-d');
$fname=isset ($_POST['fname']) ? $_POST['fname'] : '';
$fname=mysqli_real_escape_string($con, $fname);
$sql=mysqli_query("SELECT * FROM kc54i_workforce_employees WHERE fname='$fname'");
$row=mysqli_fetch_array($sql);
$namestaff=$row['lname'];
$sql2 = "
INSERT INTO `avenue`.`staff_movement` (`id`, `staff_no`, `department`, `name`, `status`, `category`, `dateStart`, `dateEng`)
VALUES (NULL, '$fname','$department','$namestaff','$status','$category','$dateStart','$dateEnd');";
if(#mysqli_query($con, $sql2))
{
echo "<script type='text/javascript'>\n";
echo "alert('New record created successfully');\n";
echo "window.navigate('add_move_test.php');";
echo "</script>";
}
else
echo "Error: " . $sql2 . "<br>" . mysqli_error();
}
else
?>
<html>
<body>
<form name="add_move_test.php" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return formCheck(this);">
<table>
<tr>
<tr>
<td valign="top">Department</td>
<td valign="top">
<select name="department" onchange='this.form.submit();'>
<?php $department=isset($_POST[ 'department']) ? $_POST[ 'department'] : '';
$department=mysqli_real_escape_string($con, $department); ?>
<option value="">-Select One-</option>
<option value="7" <?php if ($department=="7" ) echo "selected";?>>Management</option>
<option value="2" <?php if ($department=="2" ) echo "selected";?>>Administration</option>
<option value="5" <?php if ($department=="5" ) echo "selected";?>>Human Resource</option>
<option value="25" <?php if ($department=="25" ) echo "selected";?>>Business Development</option>
<option value="12" <?php if ($department=="12" ) echo "selected";?>>Finance</option>
<option value="19" <?php if ($department=="19" ) echo "selected";?>>Procurement</option>
<option value="1" <?php if ($department=="1" ) echo "selected";?>>IT Support</option>
<option value="6" <?php if ($department=="6" ) echo "selected";?>>Project</option>
<option value="13" <?php if ($department=="13" ) echo "selected";?>>Project(Control)</option>
<option value="10" <?php if ($department=="10" ) echo "selected";?>>Project(Management)</option>
<option value="8" <?php if ($department=="8" ) echo "selected";?>>Project(Transportation)</option>
<option value="24" <?php if ($department=="24" ) echo "selected";?>>Construction</option>
<option value="16" <?php if ($department=="16" ) echo "selected";?>>Construction(Management)</option>
<option value="4" <?php if ($department=="4" ) echo "selected";?>>Construction(Planning & Cost Estimation)</option>
<option value="18" <?php if ($department=="18" ) echo "selected";?>>Engineering</option>
<option value="15" <?php if ($department=="15" ) echo "selected";?>>Engineering(Civil)</option>
<option value="14" <?php if ($department=="14" ) echo "selected";?>>Engineering(Fire & Gas)</option>
<option value="23" <?php if ($department=="23" ) echo "selected";?>>Engineering(Electrical)</option>
<option value="22" <?php if ($department=="22" ) echo "selected";?>>Engineering(Instrument)</option>
<option value="3" <?php if ($department=="3" ) echo "selected";?>>Engineering(Mechanical)</option>
<option value="9" <?php if ($department=="9" ) echo "selected";?>>Engineering(Layout & Piping)</option>
<option value="20" <?php if ($department=="20" ) echo "selected";?>>Engineering(Process)</option>
<option value="17" <?php if ($department=="17" ) echo "selected";?>>HSSE</option>
<option value="11" <?php if ($department=="11" ) echo "selected";?>>Quality(QA/QC)</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Name</td>
<td valign="top">
<select name="fname">
<option selected>-Select Name-</option>
<?php $sql="select * from kc54i_workforce_employees where department='$department' ORDER BY lname ASC" ;
$results=mysqli_query($con, $sql);
while ($row=mysqli_fetch_array($results)) { $department=$row[ 'department'];
$name=$row[ 'lname']; $fname=$row['fname']; ?>
<option value="<?php echo $fname;?>">
<?php echo $name;?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top">Category</td>
<td valign="top">
<select name="category">
<?php $category=i sset($_POST[ 'category']) ? $_POST[ 'category'] : ''; $category=mysqli_real_escape_string($con, $category); ?>
<option value="">-Select One-</option>
<option value="office" <?php if ($category=="office" ) echo "selected";?>>Office</option>
<option value="site" <?php if ($category=="site" ) echo "selected";?>>Site</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Date Start</td>
<td valign="top">
<script>
DateInput('dateStart', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Date End</td>
<td valign="top">
<script>
DateInput('dateEnd', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Status</td>
<td valign="top">
<input name="status" type="text" id="status" size="50" maxlength="50">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2">
<input name="send" type="submit" id="send" value="Send">
<input name="clear" type="reset" id="clear" value="Clear">
<input type="button" name="back" value="Back" onClick="javascript:history.back();">
</td>
</tr>
</table>
</form>
</body>
</html>

There is space in between isset function all things are already there,I just run it because I don't have table structure of yours,
<html>
<body>
<form name="add_move_test.php" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return formCheck(this);">
<table>
<tr>
<tr>
<td valign="top">Department</td>
<td valign="top">
<select name="department" onchange='this.form.submit();'>
<?php
$department=isset($_POST[ 'department']) ? $_POST[ 'department'] : '';
$department=mysqli_real_escape_string($con, $department); ?>
<option value="">-Select One-</option>
<option value="7" <?php if ($department=="7" ) echo "selected";?>>Management</option>
<option value="2" <?php if ($department=="2" ) echo "selected";?>>Administration</option>
<option value="5" <?php if ($department=="5" ) echo "selected";?>>Human Resource</option>
<option value="25" <?php if ($department=="25" ) echo "selected";?>>Business Development</option>
<option value="12" <?php if ($department=="12" ) echo "selected";?>>Finance</option>
<option value="19" <?php if ($department=="19" ) echo "selected";?>>Procurement</option>
<option value="1" <?php if ($department=="1" ) echo "selected";?>>IT Support</option>
<option value="6" <?php if ($department=="6" ) echo "selected";?>>Project</option>
<option value="13" <?php if ($department=="13" ) echo "selected";?>>Project(Control)</option>
<option value="10" <?php if ($department=="10" ) echo "selected";?>>Project(Management)</option>
<option value="8" <?php if ($department=="8" ) echo "selected";?>>Project(Transportation)</option>
<option value="24" <?php if ($department=="24" ) echo "selected";?>>Construction</option>
<option value="16" <?php if ($department=="16" ) echo "selected";?>>Construction(Management)</option>
<option value="4" <?php if ($department=="4" ) echo "selected";?>>Construction(Planning & Cost Estimation)</option>
<option value="18" <?php if ($department=="18" ) echo "selected";?>>Engineering</option>
<option value="15" <?php if ($department=="15" ) echo "selected";?>>Engineering(Civil)</option>
<option value="14" <?php if ($department=="14" ) echo "selected";?>>Engineering(Fire & Gas)</option>
<option value="23" <?php if ($department=="23" ) echo "selected";?>>Engineering(Electrical)</option>
<option value="22" <?php if ($department=="22" ) echo "selected";?>>Engineering(Instrument)</option>
<option value="3" <?php if ($department=="3" ) echo "selected";?>>Engineering(Mechanical)</option>
<option value="9" <?php if ($department=="9" ) echo "selected";?>>Engineering(Layout & Piping)</option>
<option value="20" <?php if ($department=="20" ) echo "selected";?>>Engineering(Process)</option>
<option value="17" <?php if ($department=="17" ) echo "selected";?>>HSSE</option>
<option value="11" <?php if ($department=="11" ) echo "selected";?>>Quality(QA/QC)</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Name</td>
<td valign="top">
<select name="fname">
<option selected>-Select Name-</option>
<?php $sql="select * from kc54i_workforce_employees where department='$department' ORDER BY lname ASC" ;
$results=mysqli_query($con, $sql);
while ($row=mysqli_fetch_array($results)) {
$department=$row[ 'department'];
$name=$row[ 'lname']; $fname=$row['fname']; ?>
<option value="<?php echo $fname;?>">
<?php echo $name;?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top">Category</td>
<td valign="top">
<select name="category">
<?php $category=isset($_POST[ 'category']) ? $_POST[ 'category'] : ''; $category=mysqli_real_escape_string($con, $category); ?>
<option value="">-Select One-</option>
<option value="office" <?php if ($category=="office" ) echo "selected";?>>Office</option>
<option value="site" <?php if ($category=="site" ) echo "selected";?>>Site</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Date Start</td>
<td valign="top">
<script>
DateInput('dateStart', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Date End</td>
<td valign="top">
<script>
DateInput('dateEnd', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Status</td>
<td valign="top">
<input name="status" type="text" id="status" size="50" maxlength="50">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2">
<input name="send" type="submit" id="send" value="Send">
<input name="clear" type="reset" id="clear" value="Clear">
<input type="button" name="back" value="Back" onClick="javascript:history.back();">
</td>
</tr>
</table>
</form>
</body>
</html>

Related

how to show selected dropdown value after submit on same page

There is two drop-down list having different values and a submit button. after submiting it the action is on the same page with $_SERVER['PHP_SELF']; now i want to show the selected dropdown value after the report is generated but i cant figure out how to do that.
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx">XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24" >18-23</option>
<option value="25-34" >25-34</option>
<option value="35-44" >35-44</option>
<option value="45-54" >45-54</option>
<option value="55-64" >55-64</option>
<option value="65-74" >65-74</option>
<option value="75" >75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
<?php
//db connection goes here
echo "<table style='width:70%' table border='1' style='table-layout:fixed' align='center'>";
echo "<tr>
<th>No</th>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
</tr>";
if(isset($_POST['submit'])) {
//processing request here
//echo fetched rows
result comes like this
centername:-
age:-
submit
slno col1 col2 col3 col4
//after submit i get the report fetched here on the same page but could not get the selected drop-down values
I don't understand your question very well... I have read your comments... I think you want something like this?
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx"<?php if(isset($_POST["center_name"]) && $_POST["center_name"] == "xxx") { echo " selected"; } ?>>XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "18-24") { echo " selected"; } ?>>18-23</option>
<option value="25-34"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "25-34") { echo " selected"; } ?>>25-34</option>
<option value="35-44"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "35-44") { echo " selected"; } ?>>35-44</option>
<option value="45-54"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "45-54") { echo " selected"; } ?>>45-54</option>
<option value="55-64"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "55-64") { echo " selected"; } ?>>55-64</option>
<option value="65-74"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "65-74") { echo " selected"; } ?>>65-74</option>
<option value="75"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "75") { echo " selected"; } ?>>75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
To get the select values you can simply:
<?php
echo $_POST['center_name'];
echo $_POST['age_bracket'];
?>
You can remove <?php echo $_SERVER['PHP_SELF']; ?> from action as well.
<?php
echo "centername:".$_POST['center_name'];
echo "Age:" $_POST['age_bracket'];
?>
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx">XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24" >18-23</option>
<option value="25-34" >25-34</option>
<option value="35-44" >35-44</option>
<option value="45-54" >45-54</option>
<option value="55-64" >55-64</option>
<option value="65-74" >65-74</option>
<option value="75" >75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</form>

How to set timestamp with this php script

I have this script. When I select the date then I get the data by selecting date, but I want to set this with timestamp
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
From : <input type="text" name="d1" class="tcal" value="" />
<input type="submit" value="Search">
</form>
<table id="resultTable" data-responsive="table" style="text-align: left; width: 400px;" border="1" cellspacing="0" cellpadding="4">
<thead>
<tr>
<th> Birtday </th>
<th> Name </th>
<th> Gender </th>
</tr>
</thead>
<tbody>
<?php
include('connect.php');
if (isset($_GET["d1"])) { $d1 = $_GET["d1"]; } else { $d1="0000-00-00"; };
$result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
$result->bindParam(':a', $d1);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['gender']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
How I set timestamp with this script
Just use date() to echo out today's date as the value of your d1 input field:
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
From : <input type="text" name="d1" class="tcal" value="<?php echo date("m/d/Y"); ?>" />
<input type="submit" value="Search">
</form>
Ya the date - function will give all the information you need. If you havn't worked with it or just in case you are new to PHP, have a look at the documentation for finding the right date parameters.
For example:
date("d.m.Y") //outputs: 13.03.2014
date("n.d.Y") //outputs: 3.13.2014
date("m.d.y") //outputs: 03.13.14
The whole documentation can be found here: http://php.net/manual/en/function.date.php
EDIT::
So if I got you right you are looking for something simular like this:
<select class="Calendar" id="cdate_Month_ID" >
<option value="1" <?=(date('n')==1?'selected':'')?>>Jan</option>
<option value="2" <?=(date('n')==2?'selected':'')?>>Feb</option>
<option value="3" <?=(date('n')==3?'selected':'')?>>Mar</option>
<option value="4" <?=(date('n')==4?'selected':'')?>>Apr</option>
<option value="5" <?=(date('n')==5?'selected':'')?>>May</option>
<option value="6" <?=(date('n')==6?'selected':'')?>>Jun</option>
<option value="7" <?=(date('n')==7?'selected':'')?>>Jul</option>
<option value="8" <?=(date('n')==8?'selected':'')?>>Aug</option>
<option value="9" <?=(date('n')==9?'selected':'')?>>Sep</option>
<option value="10" <?=(date('n')==10?'selected':'')?>>Oct</option>
<option value="11" <?=(date('n')==11?'selected':'')?>>Nov</option>
<option value="12" <?=(date('n')==12?'selected':'')?>>Dec</option>
</select>
<select class="Calendar" id="cdate_Day_ID" >
<option <?=(date('d')==1?'selected':'')?>>1</option>
<option <?=(date('d')==2?'selected':'')?>>2</option>
<option <?=(date('d')==3?'selected':'')?>>3</option>
<option <?=(date('d')==4?'selected':'')?>>4</option>
<option <?=(date('d')==5?'selected':'')?>>5</option>
<option <?=(date('d')==6?'selected':'')?>>6</option>
<option <?=(date('d')==7?'selected':'')?>>7</option>
<option <?=(date('d')==8?'selected':'')?>>8</option>
<option <?=(date('d')==9?'selected':'')?>>9</option>
<option <?=(date('d')==10?'selected':'')?>>10</option>
<option <?=(date('d')==11?'selected':'')?>>11</option>
<option <?=(date('d')==12?'selected':'')?>>12</option>
<option <?=(date('d')==13?'selected':'')?>">13</option>
<option <?=(date('d')==14?'selected':'')?>>14</option>
<option <?=(date('d')==15?'selected':'')?>>15</option>
<option <?=(date('d')==16?'selected':'')?>>16</option>
<option <?=(date('d')==17?'selected':'')?>>17</option>
<option <?=(date('d')==18?'selected':'')?>>18</option>
<option <?=(date('d')==19?'selected':'')?>>19</option>
<option <?=(date('d')==20?'selected':'')?>>20</option>
<option <?=(date('d')==21?'selected':'')?>>21</option>
<option <?=(date('d')==22?'selected':'')?>>22</option>
<option <?=(date('d')==23?'selected':'')?>>23</option>
<option <?=(date('d')==24?'selected':'')?>>24</option>
<option <?=(date('d')==25?'selected':'')?>>25</option>
<option <?=(date('d')==26?'selected':'')?>>26</option>
<option <?=(date('d')==27?'selected':'')?>>27</option>
<option <?=(date('d')==28?'selected':'')?>>28</option>
<option <?=(date('d')==29?'selected':'')?>>29</option>
<option <?=(date('d')==30?'selected':'')?>>30</option>
<option <?=(date('d')==31?'selected':'')?>>31</option>
</select>
<input class="Calendar" type="text" size="4" maxlength="4" title="Year" value="<?=date('Y'?>">

need to display different value from dynamic dropdown list using php mysql

Hi i'm creating students marks entry list using php and mysql. Let say students subjects as "english,maths,social,science and computers" in database and Now i need to display these values from dropdown list as each row will need to show different value automatically.
<?php
$user = $_SESSION['loginUserId'];
$commonQuery = mysql_query("select sno from users where userId = '$user' and status='Active'");
$count = mysql_num_rows($commonQuery);
if($count == 1)
{
$commonQueryRes = mysql_fetch_array($commonQuery);
$uId=$commonQueryRes['sno'];
$subjectsCount = mysql_query("select COUNT(subjectName) as sub_count from subjects where userId='$uId' and status='Active' ");
$subjectsCountRes = mysql_fetch_array($subjectsCount);
$scount=$subjectsCount['sub_count'];
}
$bg = "light";
for($i=1;$i<=$scount;$i++)
{
if ($bg == "light") $bg = "dark";
else $bg = "light";
?>
<tr class="<?php echo $bg; ?>">
<td>
<select name="subName[]">
<option value="none">--select Subject--</option>
<?php
$subjectOptions = mysql_query("select subjectName from subjects where userId='$uId' and status='Active' ");
while($subjectOptionsRes = mysql_fetch_array($subjectOptions))
{
$sub = $subjectOptionsRes['subjectName'];
$sub_Sub_Options = mysql_query("select sno from subjects where userId='$uId' and subjectName='$sub'");
$sub_Sub_OptionsRes = mysql_fetch_array($sub_Sub_Options);
?>
<option value="<?php echo $sub_Sub_OptionsRes['sno']; ?>" selected="selected"><?php echo $subjectOptionsRes['subjectName']; ?></option>';
<?php
}
?>
</select>
</td>
<td>
<select name="result[]">
<option value="none">--select Result--</option>
<option value="pass"><?php echo "Pass";?></option>
<option value="fail"><?php echo "Fail";?></option>
</select>
</td>
<td><input type="text" name="quartely[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="halfearly[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="anually[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="rank[]" required size="5"/>(Kgs)</td>
<?php
}
?>
And Expected OUTPUT Should Be like this and It should be dynamic:
<table>
<thead>
<tr>
<th style="background: #5792C8;" rowspan="2">subject Name</th>
<th style="background: #5792C8;" rowspan="2">Result</th>
<th style="background: #5792C8;" colspan="4"> Progress </th>
</tr>
<tr>
<th>Quarterly</th>
<th>Halfearly</th>
<th>Annually</th>
<th>Rank</th>
</tr>
</thead>
<tbody>
<tr class="dark">
<td>
<select name="subjectName[]">
<option value="none">--select Subject--</option>
<option value="6" selected="selected">English</option>';
<option value="7" >Maths</option>';
<option value="8" >Science</option>';
<option value="9" >Social</option>';
<option value="10" >Computers</option>';
</select>
</td>
<td>
<select name="result[]">
<option value="none">--select Result--</option>
<option value="pass">Pass</option>
<option value="fail">Fail</option>
</select>
</td>
<td><input type="text" name="qua[]" required size="5"/></td>
<td><input type="text" name="half[]" required size="5"/></td>
<td><input type="text" name="anual[]" required size="5"/></td>
<td><input type="text" name="rank[]" required size="5"/></td>
<tr class="light">
<td>
<select name="subjectName[]">
<option value="none">--select Subject--</option>
<option value="6" >English</option>';
<option value="7" selected="selected" >Maths</option>';
<option value="8" >Science</option>';
<option value="9" >Social</option>';
<option value="10" >Computers</option>';
</select>
</td>
<td>
<select name="result[]">
<option value="none">--select Result--</option>
<option value="pass">Pass</option>
<option value="fail">Fail</option>
</select>
</td>
<td><input type="text" name="qua[]" required size="5"/></td>
<td><input type="text" name="half[]" required size="5"/></td>
<td><input type="text" name="anual[]" required size="5"/></td>
<td><input type="text" name="rank[]" required size="5"/></td>
<tr class="dark">
<td>
<select name="subjectName[]">
<option value="none">--select Subject--</option>
<option value="6" >English</option>';
<option value="7" >Maths</option>';
<option value="8" selected="selected" >Science</option>';
<option value="9" >Social</option>';
<option value="10" >Computers</option>';
</select>
</td>
<td>
<select name="result[]">
<option value="none">--select Result--</option>
<option value="pass">Pass</option>
<option value="fail">Fail</option>
</select>
</td>
<td><input type="text" name="qua[]" required size="5"/></td>
<td><input type="text" name="half[]" required size="5"/></td>
<td><input type="text" name="anual[]" required size="5"/></td>
<td><input type="text" name="rank[]" required size="5"/></td>
</tr>
</tbody>
</table>
I got solution,here my solution is:
I took $count=0 and i'm increasing $count+=1 for each row adding dynamically. And i took subjuct name in one array as $sub_array[] and doing if($sub_array[$count]==$subjectOptionsRes['subjectName']){echo 'selected="selected"';}
<?php
$user = $_SESSION['loginUserId'];
$commonQuery = mysql_query("select sno from users where userId = '$user' and status='Active'");
$count = mysql_num_rows($commonQuery);
if($count == 1)
{
$commonQueryRes = mysql_fetch_array($commonQuery);
$uId=$commonQueryRes['sno'];
$subjectsCount = mysql_query("select COUNT(subjectName) as sub_count from subjects where userId='$uId' and status='Active' ");
$subjectsCountRes = mysql_fetch_array($subjectsCount);
$scount=$subjectsCount['sub_count'];
}
$bg = "light";
$count=0;
for($i=1;$i<=$scount;$i++)
{
if ($bg == "light") $bg = "dark";
else $bg = "light";
?>
<tr class="<?php echo $bg; ?>">
<td>
<select name="subName[]">
<option value="none">--select Subject--</option>
<?php
$subjectOptions = mysql_query("select subjectName from subjects where userId='$uId' and status='Active' ");
while($subjectOptionsRes = mysql_fetch_array($subjectOptions))
{
$sub = $subjectOptionsRes['subjectName'];
$sub_array[] = $subjectOptionsRes['subjectName'];
$sub_Sub_Options = mysql_query("select sno from subjects where userId='$uId' and subjectName='$sub'");
$sub_Sub_OptionsRes = mysql_fetch_array($sub_Sub_Options);
?>
<option value="<?php echo $sub_Sub_OptionsRes['sno']; ?>" if($sub_array[$count]==$subjectOptionsRes['subjectName']){echo 'selected="selected"';}><?php echo $subjectOptionsRes['subjectName']; ?></option>';
<?php
}
?>
</select>
</td>
<td>
<select name="result[]">
<option value="none">--select Result--</option>
<option value="pass"><?php echo "Pass";?></option>
<option value="fail"><?php echo "Fail";?></option>
</select>
</td>
<td><input type="text" name="quartely[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="halfearly[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="anually[]" required size="5"/>(Kgs)</td>
<td><input type="text" name="rank[]" required size="5"/>(Kgs)</td>
<?php
$count+=1;
}
?>

Why is my PHP upload script not working on jquery Mobile?

I Have PHP upload Script, and it's no problem, but if i use the jquery mobile, the upload file did'nt work.
This is my script
<!DOCTYPE html>
<html>
<head>
<title>Security</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="jqm/jquery.mobile-1.1.0.min.css" />
<!--script src="jqm/jquery-1.7.1.min.js"></script> //if I Open this line, the upload script don't work.
<script src="jqm/jquery.mobile-1.1.0.min.js"></script--> //if I Open this line, the upload script don't work.
</head>
<body>
<?php
include "koneksi.php";
if (isset($_POST[SAVE]))
{
$tglkirim = $_POST[TGLKIRIM];
$nopol = $_POST[NOPOL];
$jenis = $_POST[JENIS];
$namasupexp = $_POST[NAMASUPEXP];
$bkirim = $_POST[BKIRIM];
$kotatujuan = $_POST[KOTATUJUAN];
$jamm = $_POST[JAMM];
$jamk = $_POST[JAMK];
$namasopir = $_POST[NAMASOPIR];
$jkendaraan = $_POST[JKENDARAAN];
$sj = $_POST[SJ];
$stnk = $_POST[STNK];
$sim = $_POST[SIM];
$lrem = $_POST[LREM];
$lkota = $_POST[LKOTA];
$lsign = $_POST[LSIGN];
$spion = $_POST[SPION];
$sabuk = $_POST[SABUK];
// $ukuran_gbr = GetImageSize($direktori);
$lokasi_file = $_FILES['fupload']['tmp_name']; //script for upload
$nama_file = $_FILES['fupload']['name']; //script for upload
$ukuran_file = $_FILES['fupload']['size']; //script for upload
$tipe_file = $_FILES['fupload']['type']; //script for upload
$direktori = "fkendaraan/$nama_file"; //script for upload
print_r($_POST);
move_uploaded_file($lokasi_file,"$direktori"); //script for move upload file
echo "Nama File :<b>$nama_file</b> sukses di Upload<br>";
echo "Ukuran File :<b>$ukuran_file</b> bytes<br>";
$sql="INSERT INTO tb_secure (tgl_kirim,
nopol,
jenis,
namasupexp,
bkirim,
kota_tujuan,
jam_masuk,
jam_keluar,
nama_sopir,
jenis_kendaraan,
surat_jalan,
stnk,
sim,
lrem,
lkota,
lsign,
spion,
sabuk,
nama_file,
ukuran_file,
direktori)
VALUES('$tglkirim',
'$nopol',
'$jenis',
'$namasupexp',
'$bkirim',
'$kotatujuan',
'$jamm',
'$jamk',
'$namasopir',
'$jkendaraan',
'$sj',
'$stnk',
'$sim',
'$lrem',
'$lkota',
'$lsign',
'$spion',
'$sabuk',
'$nama_file',
'$ukuran_file',
'$direktori')";
$sql2="INSERT INTO temp_gudang(nopol,tgl_kirim)VALUES('$nopol','$tglkirim')";
$input=mysql_query($sql);
$input2=mysql_query($sql2);
if ($input && $input2)
{
echo "<strong>Data berhasil dimasukkan</strong>";
//echo "<script language='javascript'>";
//echo " alert('Data berhasil dimasukkan');";
//echo " alert(print_r($_POST));";
//echo "window.location='admin/index-admin.php';";
//echo "</script>
}
else
{
echo "<strong>Data tidak berhasil dimasukkan, check ukuran gambar, yg diperbolehkan kurang dari 1.5 Mb </strong>";
}
}
<?php
if (isset($_SESSION['username']))
{
?>
<div data-role="page" class="type-interior" data-theme="b">
<div data-role="header">
<!--h1>PT UNIMOS GRESIK</h1-->
<h1>CHECKLIST APPS </h1>
<h2>Security</h2>
</div><!-- /header -->
Anda Login Sebagai <?php echo $_SESSION['username'];?>
<div data-role="content">
<form action="satpam.php" enctype="multipart/form-data" method="post">
Tanggal Pengiriman
<input type="text" name="TGLKIRIM" id="TGLKIRIM" value="<?php echo "$today";?>" />
Nomor Kendaraan
<input type="text" name="NOPOL" id="NOPOL" value="" />
Nama
<select name="JENIS" id="switch-a" data-role="slider">
<option value="Suplier">Sup</option>
<option value="Expedisi">Exp</option>
</select>
<select name="NAMASUPEXP" id="select-choice-a" data-native-menu="false">
<option >Ekspedisi</option>
<?php
$sql="SELECT * FROM tb_exp_local";
$hasil = mysql_query($sql);
while($data=mysql_fetch_array($hasil))
{
echo "<option value=$data[nama_exp] width=300>$data[nama_exp]</option>";
}
?>
</select>
<td colspan="3">Barang Yang Dikirim</td>
<input type="text" name="BKIRIM" id="BKIRIM" value="">
Kota Tujuan
<!--input type="text" name="KOTATUJUAN" id="KOTATUJUAN" value="" /-->
<select name="KOTATUJUAN" id="select-choice-a" data-native-menu="false">
<option >Kota Tujuan</option>
<?php
$sql="SELECT * FROM tb_exp_local";
$hasil = mysql_query($sql);
while($data=mysql_fetch_array($hasil))
{
echo "<option value=$data[kota_tujuan]>$data[kota_tujuan]</option>";
}
?>
</select>
Jam Masuk
<input type="text" name="JAMM" id="JAMM" value="<?php echo "$time";?>"/>
Jam Keluar
<input type="text" name="JAMK" id="JAMK" value="" />
Nama Pengemudi
<input type="text" name="NAMASOPIR" id="NAMASOPIR" value="" />
Jenis Kendaraan
<select name="JKENDARAAN" id="select-choice-a" data-native-menu="false">
<option>Jenis Kendaraan</option>
<option value="Pick Up">Pick Up</option>
<option value="Colt Diesel">Colt Diesel</option>
<option value="Fuso">Fuso</option>
<option value="Truck bak Tertutup">Truck bak Tertutup</option>
<option value="Container">Container</option>
</select>
<table>
<tr>
<td colspan="2">Surat Jalan</td><td><select name="SJ" id="switch-a" data-role="slider">
<option value="Ada">Ada</option>
<option value="Tidak">Tidak</option>
</select></td>
</tr>
<tr>
<td colspan="2">Buku KIR & STNK</td>
<td>
<select name="STNK" id="STNK" data-role="slider">
<option value="Ada">Ada</option>
<option value="Tidak">Tidak</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">SIM</td>
<td> <select name="SIM" id="SIM" data-role="slider">
<option value="Ada">Ada</option>
<option value="Tidak">Tidak</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">Lampu Rem</td>
<td><select name="LREM" id="LREM" data-role="slider">
<option value="Oke">Oke</option>
<option value="Tidak">Tidak</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">Lampu Kota</td>
<td><select name="LKOTA" id="LKOTA" data-role="slider">
<option value="Oke">Oke</option>
<option value="Tidak">Tidak</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">Lampu Sign</td>
<td> <select name="LSIGN" id="LSIGN" data-role="slider">
<option value="Oke">Oke</option>
<option value="Tidak">Tidak</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">Kaca Spion</td>
<td><select name="SPION" id="SPION" data-role="slider">
<option value="Oke">Oke</option>
<option value="Tidak">Tidak</option>
</select></td>
</tr>
<tr>
<td colspan="2">Sabuk Pengaman</td>
<td><select name="SABUK" id="SABUK" data-role="slider">
<option value="Ada">Ada</option>
<option value="Tidak">Tidak</option>
</select></td>
</tr>
</div><!-- /content -->
</div><!-- /page -->
<tr>
<td colspan="2">Upload</td>
<!--td><input type="file" name="fupload" /></td-->
<td><input type="file" accept="image/*;capture=camera" name="fupload" id="file"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="SAVE" value="SAVE"></td>
</tr>
<tr>
<td colspan="2"><a href="logout.php" data-role="button" data-icon="home" onclick='logout()'>Log Out</a></td>
<?php
echo "<script language='javascript'>";
echo "function logout()";
echo "{window.location.assign('logout.php');}";
echo "</script>";
?>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
Why the Only upload script dont work? the other script like insert data and etc is work properly.
Anyone can Help me?
Are you sure you've included enctype in your <form> declaration?
<form action="" method="post" enctype="multipart/form-data">

two dropdown and checkboxes on same page not working

I have to use same checkboxes and dropdowns according to the if condition ,---->
<div id="5" <? if($long_term_rental!=1) {?> style="display:none" <? } else {?>style="display:block" <? } ?>>
<table width="85%" >
<tr class="td3">
<td>City </td>
<td><select style="width:100px;" name="citylong" size="1" class="textfeild1" id="citylong">
<option <? if($citylong=="None")echo "selected='selected'";?>>None</option>
<option <? if($citylong=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($citylong=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($citylong=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($citylong=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($citylong=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($citylong=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td></tr>
<tr class="td2">
<td align="left">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floorlong" size="1" class="textfeild1" id="floorlong">
<option <? if($floorlong=="None")echo "selected='selected'";?>>None</option>
<option <? if($floorlong=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floorlong=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floorlong=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floorlong=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td>
</tr>
<tr class="td2">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="petslong" id="petslong" value="Pets" <? if($petslong==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="poollong" id="poollong" value="Pool" <? if($poollong==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td2">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzilong" id="jacuzzilong" value="Jacuzzi" <? if($jacuzzilong==1) echo "checked='checked'";?>/></td></div>
And on condition false display the below code---->
<div id="mylng" <? if($long_term_rental!=1) {?> style="display:block" <? } else {?>style="display:none" <? } ?>>
<table width="100%" >
<tr class="td3">
<td> </td>
<td>City </td>
<td><select style="width:100px;" name="city" size="1" class="textfeild1" id="city">
<option <? if($city=="None")echo "selected='selected'";?>>None</option>
<option <? if($city=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($city=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($city=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($city=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($city=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($city=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td>
<td align="right" style="width: 223px;">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floor" size="1" class="textfeild1" id="floor">
<option <? if($floor=="None")echo "selected='selected'";?>>None</option>
<option <? if($floor=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floor=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floor=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floor=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td></tr>
<tr class="td3">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="pets" id="checkbox9" value="Pets" <? if($pets==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="pool" id="checkbox8" value="Pool" <? if($pool==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td3">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzi" id="checkbox6" value="Jacuzzi" <? if($jacuzzi==1) echo "checked='checked'";?>/></td>
<td> </td>
<td> </td>
</tr>
</table></div>
But the code under <div id="5" is NOT WORKINg and the same code under <div id="mylng" is working PERFECTLY
Please help
at first you did not closed your
/tr
/table
at the end of
div id=5
please send us code with your form tag maybe your fault its on you HTML

Categories