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">
Related
How to make auto scroll to Top after submit error and when it scroll up need to be smooth but not straight to the top and when it scroll to the top it need to have like 100px space gap from the header .
This is the code that I try to used but it doesn't seems to work in my code
This is the jquery I have tried :-
$("#submit").click( function() {
$(window).scrollTop(100);
});
And I have tried to insert this in the CSS :-
scroll-behaviour: smooth;
Sometimes it work but sometimes it can't work. But when I insert the scroll behavior the text field required error message doesn't appear.
And this is my php file code :-
<!DOCTYPE HTML>
<html>
<head>
<title>Create New Explore</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/script.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/desaru.css" type="text/css">
<link rel="stylesheet" href="css/header.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="css/footer.css" type="text/css">
</head>
<body>
<br/>
<script src="js/script.js"></script>
<?php include('header.html'); ?>
<br/><br/><br/><br/>
<div id="scrollbox">
<!-- Content Section -->
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><strong>Create New Explore</strong></h1>
</div>
</div>
<br/><br/>
<script>
$(document).ready(function() { // website fully loaded
$('#submit').click(function() { //if button id=submit click trigger function down
var name = $('#foldername').val(); //retrieve input for folder name
var httpvar = 'http://211.25.118.147';
var defaultfolder = '/resource/';
//alert(name); get retrieve test name
if(name==""){ // if foldername input blank
alert("Insert folder name");
}
else {
$.ajax( {
url : "addfolder.php",
type: "POST",
data: {foldername : name}, //pass input foldername = name(variable declare at the top) foldername name base on html that set
success: function(result){ //if success will sent the post data
//alert(result);
if (result=="success") { //based on output echo addfolder.php
alert("File "+name+" has been added");
$("#SelectImageFolder option[value='.."+defaultfolder+name+"']").remove();
$("#SelectImageFolder").append($('<option>', { //add new options
value : ".."+defaultfolder+name ,
text : httpvar+defaultfolder+name
}))
$("#SelectImageFolder option:last").attr("selected", "selected");//auto select the last option
}
else if(result=="fail") {// if the file exist then result will fail to create the file
alert("Something wrong happened");
}
}
}
)
}
})
});
</script>
<form id="createexplore" action="CreateExploreProcess.php" method="post" enctype="multipart/form-data" >
<table class='table table-hover table-responsive table-bordered'>
<!--<tr>
<td>Class</td>
<td colspan="2">
<input type='text' name='Class' readonly class='form-control' value='Explore' maxlength="20"/>
</td>
</tr>-->
<!--<tr>
<td>Placemark</td>
<td colspan="2">
<Input type='number' name="Placemark" class='form-control' >
</td>
</tr>-->
<tr>
<td>Category</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select required>
<option value="" selected disabled hidden>Select Category..</option>
<option value="Stay">Stay</option>
<option value="Dining">Dining</option>
<option value="Facilities">Facilities</option>
<option value="ThingstoDo">Things to Do</option>
<option value="NearbyAttractions">Nearby Attractions</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Sub Category</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select required>
<option value="" selected disabled hidden>Select Sub Category... </option>
<option value="TheWestinDesaruCoastResort"> The Westin Desaru Coast Resort </option>
<option value="Kiosk"> Kiosk </option>
<option value="ShuttlePickupPoints"> Shuttle Pickup Points </option>
<option value="Rides&Attractions"> Rides & Attractions </option>
<option value="ParkingBay"> Parking Bay </option>
<option value="DesaruOstrichFarm"> Desaru Ostrich Farm </option>
<option value="Restroom"> Restroom </option>
<option value="Cafe"> Cafe </option>
<option value="AnataraCoastResort&Villas"> Anatara Coast Resort & Villas </option>
<option value="Kids"> Kids </option>
<option value="DesaruCrocodileFarm"> Desaru Crocodile Farm </option>
<option value="Restaurant"> Restaurant </option>
<option value="Riverside"> Riverside </option>
<option value="InformartionKiosk"> Informartion Kiosk </option>
<option value="Amphitheater"> Amphitheater </option>
<option value="MainAttractions"> Main Attractions </option>
<option value="DesaruCoastAdventureWaterPark"> Desaru Coast Adventure Water Park </option>
<option value="Golf"> Golf </option>
<option value="LuxuryResorts&Villas"> Luxury Resorts & Villas </option>
<option value="HardRockHotelDesaruCoast"> Hard Rock Hotel Desaru Coast </option>
<option value="ConferenceCentre"> Conference Centre </option>
<option value="Shopping"> Shopping </option>
<option value="Spas"> Spas </option>
<option value="BeachActivities"> Beach Activities </option>
<option value="DesaruFruitFarm"> Desaru Fruit Farm </option>
<option value="DisabledToilet"> Disabled Toilet </option>
<option value="FirstAid"> First Aid </option>
<option value="ChangingRoom"> Changing Room </option>
<option value="Locker"> Locker </option>
<option value="BabyChangingRoom"> Baby Changing Room </option>
<option value="LostandFound"> Lost and Found </option>
<option value="MuslimPrayerRoom"> Muslim Prayer Room </option>
</select>
</div>
</td>
</tr>
<tr>
<td>Item</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select required>
<option value="" selected disabled hidden>Select Item... </option>
<option value="Hotel"> Hotel </option>
<option value="Kiosks"> Kiosks </option>
<option value="ShuttlePickup"> Shuttle Pickup </option>
<option value="Rides&Attractions"> Rides & Attractions </option>
<option value="ParkingBay"> Parking Bay </option>
<option value="Sightseeing"> Sightseeing </option>
<option value="Restroom"> Restroom </option>
<option value="Cafe"> Cafe </option>
<option value="Kids"> Kids </option>
<option value="Restaurant"> Restaurant </option>
<option value="Riverside"> Riverside </option>
<option value="InformartionKiosks"> Informartion Kiosks </option>
<option value="Amphitheater"> Amphitheater </option>
<option value="MainAttractions"> Main Attractions </option>
<option value="DesaruCoastAdventureWaterPark"> Desaru Coast Adventure Water Park </option>
<option value="Golf"> Golf </option>
<option value="ConferenceCentre"> Conference Centre </option>
<option value="Shopping"> Shopping </option>
<option value="Spas"> Spas </option>
<option value="BeachActivities"> Beach Activities </option>
<option value="DisabledToilet"> Disabled Toilet </option>
<option value="FirstAid"> First Aid </option>
<option value="ChangingRoom"> Changing Room </option>
<option value="Locker"> Locker </option>
<option value="BabyChangingRoom"> Baby Changing Room </option>
<option value="LostandFound"> Lost and Found </option>
<option value="MuslimPrayerRoom"> Muslim Prayer Room </option>
</select></div>
</td>
</tr>
<tr>
<td>Title</td>
<td colspan="2">
<input type="text" required name='Title' class='form-control' maxlength="150"/>
</td>
</tr>
<tr>
<td>Details Header</td>
<td colspan="2">
<input type="text" required name="DetailsHeader" class='form-control' maxlength="200"/>
</td>
</tr>
<tr>
<td>Details</td>
<td colspan="2">
<textarea required name="Details" rows="8" class='form-control' maxlength="4000"></textarea>
</td>
</tr>
<tr>
<td>Button Promo</td>
<td colspan="2">
<Input required type="text" name="ButtonPromo" class='form-control' maxlength="20"/>
</td>
</tr>
<tr>
<td>Key Features</td>
<td colspan="2">
<Input required type="text" name="KeyFeatures" class='form-control' maxlength="20"/>
</td>
</tr>
<tr>
<td>Features</td>
<td colspan="2">
<textarea required name="FeaturesList" rows="5" class='form-control' maxlength="1000"></textarea>
</td>
</tr>
<tr>
<td>Image Folder</td>
<td colspan="2">
<select name="SelectImageFolder" id="SelectImageFolder" class='form-control'>
<option value="selected" selected="selected">Select a folder</option>
<?php
$dirs = glob("../resource/*", GLOB_ONLYDIR);
// create variable constant url
$httpvar = 'http://211.25.118.147';
foreach($dirs as $val){
$httpcon = str_replace("..",$httpvar,$val);
echo '<option value="'.$val.'">'.$httpcon."</option>\n";
}
?>
</select><br/>
<div class="input-group">
<input type="text" required name="foldername" id="foldername" placeholder="Folder Name" class='form-control' maxlength="100" />
<span class="input-group-btn">
<button type="button" name="submit" id="submit" class="btn"/>Add Folder</button>
</span>
</div></td>
<script="js/script.js">
</script>
</tr>
<tr>
<td>List Images</td>
<td colspan="2">
<input type="file" name="FileListImage" id="FileListImage">
</td>
</tr>
<tr>
<td>Carousel 1</td>
<td colspan="2">
<input required type="file" name="FileCarousel1" id="FileCarousel1">
</td>
</tr>
<tr>
<td>Carousel 2</td>
<td colspan="2">
<input type="file" name="FileCarousel2" id="FileCarousel2">
</td>
</tr>
<tr>
<td>Carousel 3</td>
<td colspan="2">
<input type="file" name="FileCarousel3" id="FileCarousel3">
</td>
</tr>
<tr>
<td>Carousel 4</td>
<td colspan="2">
<input type="file" name="FileCarousel4" id="FileCarousel4">
</td>
</tr>
<tr>
<td>Carousel 5</td>
<td colspan="2">
<input type="file" name="FileCarousel5" id="FileCarousel5">
</td>
</tr>
<tr>
<td>Carousel 6</td>
<td colspan="2">
<input type="file" name="FileCarousel6" id="FileCarousel6">
</td>
</tr>
<tr>
<td>Find On Map</td>
<td colspan="2">
<Input required type="text" name="FindOnMap" class='form-control' maxlength="100"/>
</td>
</tr>
<tr>
<td>Call To Book</td>
<td colspan="2">
<Input type="text" name="CallToBook" class='form-control' maxlength="100"/>
</td>
</tr>
<!--<tr>
<td>Find On Map Ico</td>
<td> <input type="url" name="FindOnMapIco" class='form-control' /> </td>
<td><input type="file" name="FileImage" id="FileImage"></td>
</tr>
<tr>
<td>Call To Book Ico</td>
<td> <input type="url" name="CallToBookIco" class='form-control' /></td>
<td><input type="file" name="FileImage" id="FileImage"></td>
</tr>-->
<tr>
<!--<td >Icon</td>
<td colspan="2">
<input type="url" name="Icon" class='form-control' maxlength="100"/>
</td>
</tr>-->
<tr>
<td>In Park</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select required>
<option value="" selected disabled hidden>Select... </option>
<option value="Yes"> Yes </option>
<option value="No"> No </option>
<option value=""> </option>
</select>
</div>
</td>
</tr>
<tr>
<td>Ticket Entry</td>
<td colspan="2">
<input type="text" name="TicketedEntry" class='form-control' maxlength="100"/>
</td>
</tr>
<tr>
<td>Operation Hours</td>
<td colspan="2">
<textarea name="OperationHours" rows="6" class='form-control'> </textarea>
</td>
</tr>
<tr>
<td>Ride Details</td>
<td colspan="2">
<textarea name="RideDetails" class='form-control' maxlength="255"/></textarea>
</td>
</tr>
<tr>
<td>Listing Details</td>
<td colspan="2">
<textarea name="ListingDetails" class='form-control' maxlength="255"/></textarea>
</td>
</tr>
<tr>
<!--<td>Favourites</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select>
<option value="" selected disabled hidden>Select... </option>
<option value="Yes"> Yes </option>
<option value=""> </option>
</select>
</div>
</td>
</tr>
<tr>
<td>FB Like</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select>
<option value="" selected disabled hidden>Select... </option>
<option value="Yes"> Yes </option>
<option value=""> </option>
</select>
</div>
</td>
</tr>-->
<tr>
<td>More Details</td>
<td colspan="2">
<input type="text" name="MoreDetails" class='form-control' maxlength="100"/>
</td>
</tr>
<tr>
<td>Distance </td>
<td colspan="2">
<input type="text" name="DistanceAway" class='form-control' maxlength="100"/>
</td>
</tr>
<tr>
<td>Status</td>
<td colspan="2">
<div class="custom-select" style="width:200px;">
<select required>
<option value="" selected disabled hidden>Status... </option>
<option value="Active"> Active </option>
<option value="Inactive"> Inactive </option>
</select>
</div>
</td>
</tr>
<tr>
<td>Zoom</td>
<td>
<input type="number" name="ZoomStart" class='form-control' placeholder="Start" min="14" max="19"/>
</td>
<td>
<input type="number" name="ZoomEnd" class='form-control' placeholder="End" min="14" max="19"/>
</td>
</td>
</tr>
<tr>
<td>GPS Coordinate</td>
<td>
<input type="text" id="Lat" name="Lat" class='form-control' placeholder="Latitude" maxlength="12"/>
</td>
<td>
<input type="text" id="Lng" name="numeric" class='form-control' placeholder="Longitude" maxlength="12"/>
</td>
</td>
<script src="js/script.js">
</script>
</tr>
<tr>
<td>Phone</td>
<td colspan="2">
<input required type="text" id="hpno" name="Phone" class='form-control' maxlength="12"/>
</td>
<script src="js/script.js">
</script>
</tr>
<tr>
<td></td>
<td colspan="2">
<input type='submit' id='submit' name='Add' value='Save' class='btn btn-warning'/>
<a href='Explore.php' class='btn btn-danger'>Back</a>
</td>
</tr>
<span id="error_message" class="text-danger"></span>
<span id="success_message" class="text-success"></span>
</table>
</form>
<!-- End Content Section -->
<?php include('footer.html'); ?>
</div> </div>
<script src="js/script.js"></script>
</body>
</html>
And CSS code:-
#scrollbox {
overflow-y:auto;
height: 478px;
width: 100%;
margin-top: -80px;
scroll-behaviour: smooth;
}
I have a form of 5 fields. when click on submit button it will fetch Amount against the fields from database MSSQL. Now when i fill form and submit it is giving an error. i have used MSSQL procedure query to execute it. please help me out i am in trouble now.
<div id="middle_pane">
<div>
<div id="inner_pane">
<div id="center_pane">
<div id="center_inner_pane">
<div class="txt_content">
<table width="385" height="200" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<form method="POST" action="<?php bloginfo('url');?>/fedex-tariff">
<tr>
<td colspan="2" style="background:#0066FF; color:#FFFFFF;
fontsize:50px">Fedex Rate Card</td></tr>
<tr>
<td>Origin</td>
<td>
<select name="origin" id="origin" onChange="">
<option value="pakistan">Pakistan</option>
</select>
</td>
</tr>
<tr>
<td>Select Origin city </td>
<td>
<select name="city_id" id="city_id">
<option value="">--SELECT CITY--</option>
<?php
$city = "select * from branches";
$city_query = mssql_query($city);
while ($row_city = mssql_fetch_array($city_query)){
?>
<option value="<?php echo $row_city['name'];?>"> <?php echo
$row_city['name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select Destination </td>
<td>
<select name="country_id" id="country_id">
<option value="">--SELECT Destination--</option>
<?php
$service= "select * from country";
$service_query= mssql_query($service);
while ($row_service = mssql_fetch_array($service_query)){
?>
<option value="<?php echo $row_service['Name'];?>"> <?php
echo $row_service['Name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> Selection of Weight </td>
<td>
<div id="wgt">
<input type="text" id="weight" name="weight" value=""
placeholder="weight...." required="">
</div>
</td>
</tr>
<tr>
<td>Select Your Service</td>
<td>
<select name="service_id" id="service_id">
<option value="">--SELECT--</option>
<?php
$service_type = "SELECT distinct ServiceTypeId from
dbo.IntlZoneCountry where ServiceTypeId IN ('FedEx Cash Tariff
Docs','FedEx Box','FedEx Student Package')";
$res_type = mssql_query($service_type);
$cnt_type = mssql_num_rows($res_type);
while($row_type = mssql_fetch_array($res_type)){
?>
<option value="<?php echo $row_type['ServiceTypeId'];?>"><?php
echo $row_type['ServiceTypeId'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" value="Calculate" name="submit"
class="btn"></td>
</tr>
</form>
<table width="385" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<tr>
<td>
<?php
if(isset($_POST['submit']))
{
$city_id = $_POST['city_id'];
$country_id = $_POST['country_id'];
$service_id = $_POST['service_id'];
$weight_id = $_POST['weight'];
if(empty($city_id) || empty($country_id) || empty($service_id) ||
empty($weight_id)){
?><center><?php echo "Please filled all the fields first.";?>
</center>
<?php
}
else{
$s = "[SP_UpdateCNPrice_Int_Tariff]
'$weight_id','$city_id','$country_id','$service_id'";
$result = mssql_query($s);
while($row = mssql_fetch_assoc($result)){
?>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td>
<center>
<font size="3">
<?php
$val = $row['amount'];
$gst = $row['gst'];
echo "<strong>"."Rate : "."$".""." ".$val.$gst;
?>
</font>
</center>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td><center> All Rates are Exclusive of 16% GST + 23% fuel
Charges (FSC).</center> </td>
</tr>
<?php
}
}
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
MSSQL Procedure Screenshot
Front Display of Website
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>
For some reason every once in a while my code will enter data into the database twice. I have changed my code and made some tweaks but have not had any luck. I know I must be over looking something I just don't know what.
<?php
$con = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$conpo = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$resultpo = mysqli_query($conpo, "SELECT * FROM fpo ORDER BY ponum DESC LIMIT 1");
while ($rowp = mysqli_fetch_array($resultpo)) {
$po = $rowp['ponum'];
$ponum = ++$po;
}
$date = $_POST['date'];
$to = $_POST['to'];
$time = $_POST['time'];
$vin = $_POST['stk_vin'];
$reason = $_POST['reason'];
$amount = $_POST['amount'];
$empnum = $_POST['emp'];
$mananger = $_POST['mananger'];
$accnum = $_POST['acc'];
$store_location = $_POST['store'];
$borr = $_POST['borrowed'];
$oldid = $_POST['oldid'];
mysqli_query($con,
"INSERT INTO fpo (" .
"`ponum`, `date`, `to`, `time`, `vin`, `reason`, `amount`, `empnum`, `mananger`, `accnum`, `store_location`, `borr`" .
") VALUES (" .
"'$ponum', '$date', '$to', '$time', '$vin', '$reason', '$amount', '$empnum', '$mananger', '$accnum', '$store_location', '$borr'" .
")");
?>
Here is the html forum page.
<form action="print.php" method="POST" name="form1" id="form1">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="table" style="width:700px">
<tbody>
<tr>
<td height="19" colspan="2" valign="middle" class="to" style="width:450px" ><div class="logo"></div></td>
<td width="95" rowspan="2" valign="bottom"><div class="date">Date:
<label>
<input name="date" type="text" readonly id="date" value="07/15/2015" size="10" />
</label>
</div></td>
<td width="106" rowspan="2" valign="bottom" class="po" style="width:100px" ><div class="date">PO: <span id="sprytextfield3">
<label>
<input name="po" readonly type="text" value="14739" />
<input type="hidden" name="oldid" value="11810">
</label>
<span class="textfieldRequiredMsg">A value is required.</span></span></div></td>
</tr>
<tr>
<td height="20" colspan="2" valign="middle" class="to" style="width:450px" ><div class="toheader">To: <span id="spryselect1">
<label>
<select name="to" id="to">
<option selected="selected" disabled="disabled">Select One</option>
<option value="1">Kum-N-Go</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span>
<input name="time" type="hidden" id="time" value="
11:13:33 ">
</div></td>
</tr>
<tr>
<td colspan="2" style="height:125px" ><b> Reason For Gas Ticket: </b> <br>
<span id="spryselect2">
<label>
<select name="reason" id="reason">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Advertising">Advertising</option>
<option value="Auction">Auction</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span><br>
<br>
Car Borrowed From Another Dealership? <br>
<span id="spryselect3">
<label>
<select name="borrowed" id="borrowed">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span><br></td>
<td><b>stk/vin/RO#:</b><br>
<span id="sprytextfield2">
<label>
<input name="stk_vin" type="text" id="stk_vin" onclick="return stk()" size="12" />
</label>
<span class="textfieldRequiredMsg"><br />
Stock or Vin .</span></span></td>
<td align="center"><b> Amount<br>
<div class="money"><span id="spryselect5">
<label><b>
<select name="amount" id="amount">
<option value="5.00" selected="selected">5.00</option>
<option value="1.00">1.00</option>
<option value="2.00">2.00</option>
<option value="3.00">3.00</option>
<option value="4.00">4.00</option>
<option value="5.00">5.00</option>
<option value="6.00">6.00</option>
<option value="7.00">7.00</option>
<option value="8.00">8.00</option>
<option value="9.00">9.00</option>
<option value="10.00">10.00</option>
</select>
</b></label>
<span class="selectRequiredMsg">Please select an item.</span></span></div>
</b></td>
</tr>
<tr>
<td width="257">Employee Requesting Po:<span id="spryselect9">
<label>
<select name="emp" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="5223">5223</option>
</optgroup>
</select>
</label>
<span class="textfieldRequiredMsg">Required</span><span class="textfieldInvalidFormatMsg">Required</span></span></td>
<td width="219">Acc #:<span id="spryselect4">
<label>
<select name="acc" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="51">Sales</option>
<option value="52">Services</option>
<option value="53">Parts</option>
<option value="FI">F&I</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><label> Mananger:
<input name="mananger" onclick="return getfoc()" type="text" id="mananger" size="12" readonly />
</label></td>
</tr>
<tr>
<td></td>
<td>Store: <span id="spryselect6">
<label>
<select name="store" id="store">
<option disabled="disabled" selected="selected">Select One</option>
<option value="chevy">Chevy</option>
<option value="Ford">Ford</option>
<option value="Dodge">Dodge</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><div id="btn"> </div>
<script language='javascript' type='text/javascript'>
function GetValueFromChild(myVal)
{
document.getElementById('mananger').value = myVal;
document.getElementById('btn').innerHTML = '<input type="submit" id="register" value="Print Ticket" />';
}
</script></td>
</tr>
</tbody>
</table>
<p> </p>
</form>
Because you are not doing atomic operation. Lets assume the below flow:
SELECT1 -> SELECT2-> INSERT1-> INSERT2
How are avoid this - no synchronization or locking. You can avoid this with few options.
Use a lock before entering this block and free once insert is done( in PHP). This can be based on file lock or memcache lock
You can add an index on the column you want to keep unique say, (ponum, from, to). Instead of using INSERT, you can use INSERT IGNORE
I am pretty sure your users are clicking the submit button twice I had this issue before I fixed it using jquery's validator such as following.
$(document).ready(function(){
$("#form1").validate({submitHandler: function(form) {if (!this.beenSubmitted) {this.beenSubmitted = true;form.submit();} }});
});
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>