So i made this countdown generator; it's based on a PHP input to fill the JavaScript, the problem is that in Safari it doesn't show this:
or
Is there a way to fix it in Safari? I've been thinking of disabling that input when in Safari and enabling a more basic numbers one but I don't know how to detect, is there another fix?
My code:
Form page:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://monopolo11.ninja/tests/css/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://monopolo11.ninja/tests/js/dropdown.js"></script>
<title>Countdown Maker</title>
</head>
<body class="lato">
<?php include("assets/navbartools.html");?>
<div class="lato container-fluid text-center" id="contents">
<p>Introduce la fecha</p>
<form action="countdownres.php" method="get" >
Fecha:
<input type="date" name="datein">
<br/>
Hora:
<input type="time" action="countdownres.php" method="get" name="timein">
<p>Cuantos argumentos quieres que se visualicen:</p>
<input type="checkbox" name="mil" value="1">Milenios
<input type="checkbox" name="cen" value="1">Siglos
<input type="checkbox" name="dec" value="1">Decadas
<input type="checkbox" name="yr" checked value="1">Años
<input type="checkbox" name="mo" checked value="1">Meses
<input type="checkbox" name="wk" value="1">Semanas
</br>
<input type="checkbox" name="da" checked value="1">Dias
<input type="checkbox" name="h" checked value="1">Horas
<input type="checkbox" name="m" checked value="1">Minutos
<input type="checkbox" name="s" checked value="1">Segundos
<input type="checkbox" name="mili" value="1">Milisegundos
<input type="submit" class="center-block btn btn-primary">
</form>
</div>
</body>
</html>
Result page:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://monopolo11.ninja/tests/css/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://monopolo11.ninja/tests/js/countdown.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://monopolo11.ninja/tests/js/dropdown.js"></script>
<title>Countdown</title>
</head>
<body class="lato">
<?php include("assets/navbartools.html");?>
<?php
//variables
$date = $_GET[datein];
$date = explode('-', $date);
$time = $_GET[timein];
$time = explode(':', $time);
$hour = $time[0];
$minute = $time[1];
$year = $date[0];
$month = $date[1];
$day = $date[2];
$mil = 0;
$cen = 0;
$dec = 0;
$yr = 0;
$mo = 0;
$wk = 0;
$da = 0;
$h = 0;
$m = 0;
$s = 0;
$mili = 0;
//variables de get
$mil = $_GET[mil];
$cen = $_GET[cen];
$dec = $_GET[dec];
$yr = $_GET[yr];
$mo = $_GET[mo];
$wk = $_GET[wk];
$da = $_GET[da];
$h = $_GET[h];
$m = $_GET[m];
$s = $_GET[s];
$mili = $_GET[mili];
if ($mil == 1){
$mil = "countdown.MILLENNIA";
}
else{$mil=0;};
if ($cen == 1){
$cen = "countdown.CENTURIES";
}
else{$cen=0;};
if ($dec == 1){
$dec = "countdown.DECADES";
}
else{$dec=0;};
if ($yr == 1){
$yr = "countdown.YEARS";
}
else{$yr=0;};
if ($mo == 1){
$mo = "countdown.MONTHS";
}
else{$mo=0;};
if ($wk == 1){
$wk = "countdown.WEEKS";
}
else{$wk=0;};
if ($da == 1){
$da = "countdown.DAYS";
}
else{$da=0;};
if ($h == 1){
$h = "countdown.HOURS";
}
else{$h=0;};
if ($m == 1){
$m = "countdown.MINUTES";
}
else{$m=0;};
if ($s == 1){
$s = "countdown.SECONDS";
}
else{$s=0;};
if ($mili == 1){
$mili = "countdown.MILLISECONDS";
}else{$mili=0;};
?><h1 class="lato text-center">Cuenta Regresiva para el <?php echo $_GET[datein]." ".$_GET[timein];?>
<div id="cuenta" class="lato text-center text-capitalize"><strong></strong></div>
</h1>
<script>
//labels
countdown.setLabels(
' milisegundo| segundo| minuto| hora| dia| semana| mes| año| década| siglo| milenio',
' milisegundos| segundos| minutos| horas| dias| semanas| meses| años| décadas| siglos| milenios',
' y ',
' + ',
'Ahora');
//variables de fechas
var dia = <?php echo $day?>;
var mes = <?php echo $month?> - 1;
var year = <?php echo $year?>;
var hour = <?php echo $hour?>;
var minute = <?php echo $minute?>;
//variables de atributos que se mostraran
var mil = <?php echo $mil?>;
var cen = <?php echo $cen?>;
var dec = <?php echo $dec?>;
var yr = <?php echo $yr?>;
var mo = <?php echo $mo?>;
var wk = <?php echo $wk?>;
var da = <?php echo $da?>;
var h = <?php echo $h?>;
var m = <?php echo $m?>;
var s = <?php echo $s?>;
var mili = <?php echo $mili?>;
var ref =1000;
if (mili == 1){
ref = 1;
}
//countdown clock
var clock1 = document.getElementById("cuenta")
, tdy = new Date();
clock1.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate()) ).toString();
setInterval(function(){
clock1.innerHTML = countdown(new Date(year, mes, dia, hour, minute),null,mil | cen | dec | yr | mo| wk | da | h | m | s | mili ).toString();
},ref);
console.log(ref);
console.log(mili);
console.log(tdy);
</script>
</body>
</html>
Related
we have a program that has two button(approve and disapprove). Our problem is when i hit on the button, the value on the prompt doesn't save on the database.
ServiceRequest.php
<?php
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['lname']) || !isset($_SESSION['fname']) || !isset($_SESSION['lname']) || !isset($_SESSION['pass']) || !isset($_SESSION['assign']) || !isset($_SESSION['department']) || !isset($_SESSION['branch']) || !isset($_SESSION['province']) || !isset($_SESSION['position']))
{
header('Location:login.php');
}
include 'config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="image/fblogo.ico">
<title>FB | ITS&CMS</title>
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- <link href="signin.css" rel="stylesheet"> -->
<link rel="stylesheet" type="text/css" href="dist/css/jquery.dataTables.min.css"></script>">
<link rel="stylesheet" type="text/css" href="css/body.css">
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
<script src="dist/js/jquery-1.12.4.js"></script>
<script src="dist/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#otable').DataTable({
"searching": false,
"order" : [[ 5, "desc" ]]
});
$("#search").click(function(){
$("#searchPanelWrap").slideToggle("slow");
});
$("#searchServiceRequests").click(function(){
var filterVal ="";
filterVal = "srfno=" + $('#srf').val() + "&branch=" + $('#branch').val() + "&dept=" + $('#dept').val() + "&reqf=" + $('#datereqfrom').val() + "&reqt=" + $('#datereqto').val() + "";
document.location.href = 'servicereq.php?s=1&' + filterVal;
});
});
</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<?php
include "header.php";
?>
</nav>
<br><br><br><br><br>
<div class="form">
<center>
<fieldset id="fieldsetform">
<div class="form"><br><br>
<center><h4>Service Request Forms</h4></center>
<ul class="tab-group"><br>
<button style="width: 150px; height: 50px;" type="button" class="btn btn-success" value="Service">Service Request</button>
<button style="width: 150px; height: 50px;" type="button" class="btn btn-danger" value="Service">Close Request</button>
<button class="btn" style="width: 50px; height: 50px;" value="Search" id="search"><span class="glyphicon glyphicon-filter"></span></btn>
</ul>
<div id="searchPanelWrap" style="padding-bottom:10px; display:none;">
<input style = "text" placeholder = "SRF No." id="srf"/>
<input style = "text" placeholder = "Branch" id="branch"/>
<input style = "text" placeholder = "Department" id="dept"/>
Request Date From: <input style = "text" type = "date" value="" id="datereqfrom"/>
Request Date To: <input style = "text" type = "date" value="" id="datereqto"/>
<button class="btn btn-default" id="searchServiceRequests">Search</button>
</div>
<form action="downloadfile.php" method="get"></form>
<?php
//if(!$uname == 'uname' && !$pass = 'pass'){
include 'dbconn.php';
if($_SESSION['assign']!="Main Approver"){
$clause = "dept = '".$_SESSION['department']."' AND city='".$_SESSION['branch']."' AND type != '".$_SESSION['assign']."' AND status = 'PENDING' ";
}else{
$clause = "status = 'PENDING' ";
}
if($_GET["s"] == "1"){
$srf = $_GET["srfno"];
$branch = $_GET["branch"];
$dept = $_GET["dept"];
$datereqfrom = $_GET["reqf"];
$datereqto = $_GET["reqt"];
$srfFilter = "";
$brFilter = "";
$deptFilter = "";
$reqFilter = "";
if($srf != ""){
$srfFilter = "AND SRFNo = '".$srf."' ";
}
if($branch != ""){
$brFilter = "AND city = '".$branch."' ";
}
if($dept != ""){
$deptFilter = "AND dept = '".$dept."' ";
}
if($datereqfrom != "" && $datereqto != ""){
$reqFilter = "AND RequestDateTime BETWEEN '".$datereqfrom." 00:00:00.000' AND '".$datereqto." 23:59:59.999' ";
}
$addFilter = $srfFilter.$brFilter.$deptFilter.$reqFilter;
}else{
$addFilter = "";
}
$record= getAllServicePending($clause.$addFilter);
echo '<table id="otable" class="table table-striped">';
echo '<thead>';
echo '<th>SRF No.</th>';
echo '<th>Last Name</th>';
echo '<th>First Name</th>';
echo '<th>Branch</th>';
echo '<th>Department</th>';
echo '<th>Date Requested</th>';
echo '<th>Attached File</th>';
echo '<th>Service Form View</th>';
echo '<th>Status</th>';
echo '<th>Action</th>';
echo '</thead>';
echo "<tbody>";
foreach($record as $r){
$i=0;
echo '<tr>';
$idno;
foreach($r as $fields){
if($i==0) $idno=$fields;
//echo '<td>'.strtoupper($fields).'</td>';
$i++;
}
$files = $r['file'];
echo '<td>'.$r['SRFNo'].'</td>';
echo '<td>'.$r['lastreq'].'</td>';
echo '<td>'.$r['firstreq'].'</td>';
echo '<td>'.$r['city'].'</td>';
echo '<td>'.$r['dept'].'</td>';
echo '<td>'.$r['RequestDateTime'].'</td>';
echo '<td>'.$r['file'].'</td>';
echo '<td>Service Request</td>';
echo '<td>'.$r['status'].'</td>';
echo '<td>
<button type="button" class="btn btn-success" onclick="window.location.href=`approveserv.php?idno='.$idno.'&status=approve`" style="width:136px;"><span class="glyphicon glyphicon-thumbs-up" style="padding-right:5px"></span>APPROVE</button><br>
<button type="button" class="btn btn-danger" onclick="window.location.href=`approveserv.php?idno='.$idno.'&status=disapprove`" style="width:136px;"><span class="glyphicon glyphicon-thumbs-down" style="padding-right:5px"></span>DISAPPROVE</button>
</td>';
echo '</tr>';
}
echo "</tbody>";
echo '</table>';
//}
?><br><br>
</div>
</fieldset>
</center>
</div><?php
include "footer.php";
?>
</body>
</html>
Here is how I used the prompt(), this will just perform the SQL for approve and disapporve but the value of the prompt does not store to the database.
SQL query:
approveserv.php<?php
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['lname']) || !isset($_SESSION['fname']) || !isset($_SESSION['lname']) || !isset($_SESSION['pass']) || !isset($_SESSION['assign']) || !isset($_SESSION['department']) || !isset($_SESSION['branch']) || !isset($_SESSION['province']) || !isset($_SESSION['position']))
{
header('Location:login.php');
}
include ('dbconn.php');
$idno = $_GET["idno"];
$reqstat = $_GET["status"];
$s = ret_status_service($idno);
$user = $_SESSION['user'];
$db = site_db();
if($reqstat=="approve"){
$sql = "UPDATE services SET status ='APPROVED', ApprovalDateTime = CURRENT_TIMESTAMP(), ApprovedBy = '".$user."' WHERE ser_id = ?";
}else{
$sql = "UPDATE services SET status ='DISAPPROVED', ApprovalDateTime = CURRENT_TIMESTAMP(), ApprovedBy = '".$user."' WHERE ser_id = ?";
}
$s = $db->prepare($sql);
$s->execute(array($idno));
$db = null;
echo "<script>if(prompt('Successfully ${reqstat}d request.')){document.location.href='servicereq.php?s=0'};</script>";
// header('location:servicereq.php');
?>
If your concerns are how to get the input of prompt dialog and send it to servicereq.php. You could refer to the following code:
//servicereq.php - to get the prompt message from approveserv.php and store it to database
if(isset($_REQUEST['prompt_msg'])){
$prompt_msg= $_REQUEST['prompt_msg'];
// you could continue to store it in the database
}
//approveserv.php - to output the javascript and get the prompt message and send it to servicereq.php
echo "<script>if(prompt_msg=prompt('Successfully ".$reqstat."d action request.')){document.location.href='servicereq.php?prompt_msg='+prompt_msg+'&s=0'};</script>";
Note: I suppose you could manage to store the prompt msg to the database, so I didn't write the code here.
Here is a further material for how to use prompt.
I'm trying to print alternative character form two different string dynamically. I did below code but it's give me "TrAaUuSt" this output. but I want "TrAaUuStIF". How can I solve this? Anyone can help me? Thank You in advance. I'm new in PHP. If you have better solution then please suggest me.
<?php
/*$str1 = "TAUSIF";
$str2 = "raut";
Output = TrAaUuSt*/
if(isset($_POST['submit']))
{
$str1 = $_POST['str1'];
$str2 = $_POST['str2'];
$strlen1 = strlen($str1);
$strlen2 = strlen($str2);
if($strlen1 > $strlen2)
{
for($i = 0; $i<$strlen2; $i++){
$new[] = $str1[$i];
$new[] = $str2[$i];
}
}
else
{
for($i = 0; $i<$strlen1; $i++){
$new[] = $str1[$i];
$new[] = $str2[$i];
}
}
foreach($new as $str){
echo $str;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Print alternative character.</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="str1" ><br><br>
<input type="text" name="str2" ><br><br>
<input type="submit" name="submit" value="Submit" >
</form>
</body>
</html>
You could try something like this:
if(isset($_POST['submit']))
{
//$str1 = "TAUSIF";
//$str2 = "raut";
$str1 = $_POST['str1'];
$str2 = $_POST['str2'];
// SPLIT STRINGS TO ARRAY
$a1 = str_split($str1);
$a2 = str_split($str2);
$out = ''; // THE OUTPUT STRING
// CHECK WHICH STRING IS LONGEST
$count = (count($a1) > count($a2)) ? count($a1) : count($a2);
// LOOP BASED ON THE NUMBER OF CHARACTERS IN LONGEST STRING
for ($x = 0; $x <= $count; $x++) {
$out .= (isset($a1[$x])) ? $a1[$x] : '';
$out .= (isset($a2[$x])) ? $a2[$x] : '';
}
echo $out; // TrAaUuStIF
}
NOTE:
If you need Unicode support, then you should consider making your own str_split function as described in the top voted comment here: http://php.net/str_split
<?php
/*$str1 = "TAUSIF";
$str2 = "raut";
Output = TrAaUuSt*/
if(isset($_POST['submit']))
{
$str1 = $_POST['str1'];
$str2 = $_POST['str2'];
$strlen1 = strlen($str1);
$strlen2 = strlen($str2);
if($strlen1 > $strlen2)
{
for($i = 0; $i<$strlen2+$strlen1; $i++){
$new[] = $str1[$i];
$new[] = $str2[$i];
}
}else
{
for($i = 0; $i<$strlen1+$strlen2; $i++){
$new[] = $str1[$i];
$new[] = $str2[$i];
}
}
foreach($new as $str){
echo $str;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Print alternative character.</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="str1" ><br><br>
<input type="text" name="str2" ><br><br>
<input type="submit" name="submit" value="Submit" >
</form>
</body>
</html>
I am working on a small project. I have created a PHP page in that as soon as a button in clicked a function named sendMessage should get executed but instead it is showing me uncaught reference error.
My error:
Uncaught ReferenceError:sendMessage is not defined at HTMLInputElement.onclick
line 29. At last onclick call
Here is my js file named chat.js:
function btn() {
var s = document.getElementById("chat_id");
var o = s.options[s.selectedIndex].value;
var x = document.getElementsByClassName("chat");
x[0].style.display = "inline-block";
x[1].innerHTML = "<span>" + "Chatting with:" + o + "<span>";
}
function sendMessage() {
var msg = document.getElementById("msg").value;
if (msg.length === 0 || msg === "") {
alert("please enter some message");
return;
}
var sender = document.getElementById("username").value;
var sendto = document.getElementById("chat_id").options[document.getElementById("chat_id").selectedIndex].value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 400) {
document.getElementById("chat_logs").innerHTML = xhttp.responseText;
}
xhttp.open('GET', 'send_messages.php?sender=' + sender + 'sendto=' + sendto + 'message=' + msg, true);
xhttp.send();
}
}
function test() {
alert("lol");
}
My PHP code:
<?php
include ('db.php');
session_start();
if(empty($_SESSION['user_logs'])){ //check if user session is set
header('Location:login.php'); //redirect to login page if user session is not set
}
?>
<!DOCTYPE html>
<html>
<head>
<title>chat box</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="chat.js"></script>
<link rel="stylesheet" href="chatbox.css" />
</head>
<body>
<div class="container cont">
<p>
Logout <?php echo $_SESSION['user_logs']; ?>
</p>
<input type="hidden" id="username" value=<?php echo $_SESSION[ 'user_logs']; ?>>
<p>
<label for="chatwith">Chat with:</label>
<select name="chat_user" id="chat_id" class="selectpicker">
<option disabled selected>select</option>
<?php
$current_user=$_SESSION['user_logs'];
$rows=mysqli_query($con,"select username from users where username!='".$current_user."'");
while($rowsArray=mysqli_fetch_array($rows)):
?>
<option value=<?php echo $rowsArray[ 'username']; ?>>
<?php echo $rowsArray['username']; ?>
</option>
<?php endwhile;?>
</select>
<input type="button" id="btn_chat" name="toggle" value="chat" class="btn btn-info" onclick="btn();" />
<div id="chat_div" class="chat">
<span class="chat">Chatting with:</span>
<div class="chat" id="chat_logs"></div>
<div class="chat" id="input">
<textarea value="" placeholder="Enter message" id="msg" name="message" required maxlength="150"></textarea>
<input type="button" id="btn-send" class="btn btn-primary" value="send" onclick="sendMessage();" />
</div>
</div>
</div>
</body>
</html>
I've created a webpage in order to get a table based on both a json and a user entry.
I have a script in my home page but it doesn't enter in my $.getJSON while getvalues() works and I really don't understand why...
My home page :
<html>
<head>
<meta charset="utf-8" />
<script src="http://****/js/jQuery.js"></script>
<link rel="stylesheet" href="http://****/style/style.css"/>
<title>****</title>
<link href='http://fonts.googleapis.com/css?family=Audiowide|Artifika' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div class="contenu">
<form action="#" class="tableau"> <!--Creation du formulaire pour l'entree utilisateur-->
</br></br>Quel TI recherchez vous ?</br></br>
<table border=0>
<tr>
<td>Nom du TI</td>
<td>
<input type="text" name="nom_TI" id="Filtre_ti">
</td>
</tr>
<tr>
<td COLSPAN=1>
<button onclick="get_values()">GO</button>
</td>
</tr>
</table></br>
<table id="mon_tableau" border=1><tbody></tbody></table>
</form>
</div>
</body>
</html>
<script type="text/javascript">
function get_values(){
var titre_colindex = 0;
var json = "http://****/get_json.php?callback=?";
console.log(document.getElementById('Filtre_ti').value);
if(document.getElementById('Filtre_ti').value!=""){
$.getJSON( json , {'nom_TI' : document.getElementById('Filtre_ti').value}).done(function( json ) {
var myjson = json;
console.log(myjson);
newRow = document.getElementById('mon_tableau').getElementsByTagName('tbody')[0].insertRow(-1);
$.each(myjson[0], function(index, valeur){ //Pour chaque colonne
newCell = newRow.insertCell(titre_colindex);
newCell.innerHTML = index;
titre_colindex+=1;
console.log("premier for each");
});
$.each(myjson, function(i,ti){
var newRow;
var newCell;
newRow = document.getElementById('mon_tableau').getElementsByTagName('tbody')[0].insertRow(-1);
newCell = newRow.insertCell(0);
newCell.innerHTML = ti.TI;
console.log("deuxieme");
var i_colindex=1;
$.each(ti, function(index, valeur){
if(index != "TI"){
newCell = newRow.insertCell(i_colindex);
newCell.innerHTML = valeur;
i_colindex+=1;
}
});
}); //End each
}); //End getJSON
}
}
</script>
My get_json.php page :
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("content-type: application/json");
$DB_HOST="****";
$DB_PORT="****";
$DB_USER="****";
$DB_PASS="****";
$DB_NAME="****";
$pdo = new PDO('mysql:host='.$DB_HOST.';port='.$DB_PORT.';dbname='.$DB_NAME, $DB_USER, $DB_PASS); //Connexion base de donnees
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Affichage des erreurs
$mon_tableau = array();
if (isset($_GET['nom_TI'])){
$ti = $_GET['nom_TI'];
$sql = "
SELECT ti.TI, ti.SYSTEM_TYPE, ti.SYSTEM_NAME, ti.ENTITY_IN_CHARGE
FROM technical_item ti
WHERE ti.TI LIKE '%$ti%';
";
//La connexion est lancee et stockee dans l'objet $pdo
$sth = $pdo->prepare($sql);
$sth->bindvalue(':ti','%'.$ti.'%', PDO::PARAM_STR); //On selectionne en fonction de la saisie de l'utilisateur
$sth->execute();
$result = $sth->fetchall(PDO::FETCH_ASSOC);
if($result){
foreach ($result as $donnees){
$mon_tableau[] = $donnees;
} //end foreach
}
}//end if
if(isset($_GET['callback'])){
echo json_encode($mon_tableau);
}
else {
$mon_tableau = array('error',true);
echo json_encode($mon_tableau);
}
?>
I've launched several tests : change script position, delete the if, fix a value for 'Filtre_ti' but I couldn't find a solution.
Would you know why I can't get into this $.getJSON ?
Thanks for your help,
Corentin.
this is my main.php
<?php
session_start();
if (!isset($_SESSION['username']))
{
header('Location: index.php');
}
include("connection/config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TOM ELOY CONVENIENCE STORE</title>
<link rel="stylesheet" href="css/design.css" type="text/css" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/iconic.css" media="screen" rel="stylesheet" type="text/css" />
<script></script>
</head>
<body>
<div id="wrapper">
<!--header link -->
<div id="sitename" class="clear">
<?php include_once("header.php"); ?>
</div>
<!--menu navigation -->
<div class="wrap">
<nav>
<?php include_once("menunav.php"); ?>
<div class="clearfix"></div>
</nav>
</div>
<div id="body-wrapper">
<!-- body -->
<div id="body" class="clear">
<div class="clear">
<div id="content"></div>
<!-- script for pages -->
<script type="text/javascript" src="js/general.js"></script>
<script src="js/main.js"></script>
</div>
</div>
</div>
<!--footer link -->
<div id="footer" align="center">
<?php include_once("footer.php"); ?>
</div>
</div>
</body>
</html>
this is my javascript the main.js
$(document).ready(function () {
$('#content').load('main2.php');
$('ul#nav li a').click(function() {
var page = $(this).attr('href');
$('#content').load( page + '.php');
return false;
});
});
this is my supplierprofile.php
<?php
session_start();
if (!isset($_SESSION['username']))
{
header('Location: index.php');
}
include("connection/config.php");
?><html>
<head>
<link rel="stylesheet" href="css/styles.css" type="text/css" />
<!-- autorefresh of the table -->
<script type="text/javascript">
function Ajax()
{
var
$http,
$self = arguments.callee;
if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
}
}
if ($http) {
$http.onreadystatechange = function()
{
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 0);
}
};
$http.open('GET', 'supplierprofiletable.php' + '?' + new Date().getTime(), true);
$http.send(null);
}
}
</script>
</head>
<!-- content2 -->
<div id="content">
<p id="bcp">Browse Supplier Profile</p><br><br>
<ul id="nav">
<li>
<a id="abutton">PRINT</a>
<a id="abutton" href="addspform">ADD SUPPLIER</a>
</li>
</ul>
<!-- autorefresh of the table -->
<script type="text/javascript">
setTimeout(function() {Ajax();}, 0);
</script>
<!-- table to be refresh -->
<div id="ReloadThis"><?php include_once("supplierprofiletable.php"); ?></div>
</div>
<? -- script for pages --?>
<script type="text/javascript" src="js/general.js"></script>
<script src="js/submain.js"></script>
this is the supplieprofiletable.php
<table id="spvt" align="center">
<tr>
<th id="spvth">SUPPLIER NAME</th>
<th id="spvth">TERMS DAY</th>
<th id="spvth">VAT</th>
<th id="spvth">MODIFY</th>
<th id="spvth">DELETE</th>
</tr>
<?php
include("connection/config.php");
$sql = "select * from SUPPLIER_PROFILE ORDER BY SP_NAME";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<tr id='spvtr'>";
echo "<td id='spvtd' style='text-align:left;'>" . $row['SP_NAME'] . "</td>";
echo "<td id='spvtd'>" . $row['SP_TERMS_DAY'] . "</td>";
echo "<td id='spvtd'>" . $row['SP_VAT'] . "</td>";
echo "<td id='spvtd'>MODIFY SUPPLIER</td>";
echo "<td id='spvtd'>DELETE SUPPLIER</td>";
echo "</tr>";
}
?>
this is the addspform.php
<head>
<link rel="stylesheet" href="css/design.css" type="text/css" />
<link href="style.css" media="screen" rel="stylesheet" type="text/css" />
<link href="iconic.css" media="screen" rel="stylesheet" type="text/css" />
<script type = "text/javascript">
<!--
var run1 = function()
{
var x1 = document.addsp.spname.value.length;
if(x1 == 0)
{
alert("SUPPLIER NAME SHOULD NOT BE EMPTY");
return(false);
}
else
return(true);
}
var run2 = function()
{
var x1 = document.addsp.spadd.value.length;
if(x1 == 0)
{
alert("SUPPLIER ADDRESS SHOULD NOT BE EMPTY");
return(false);
}
else
return(true);
}
var run3 = function()
{
var x1 = document.addsp.sptd.value.length;
if(x1 == 0)
{
alert("SUPPLIER TERMS DAY SHOULD NOT BE EMPTY");
return(false);
}
else
return(true);
}
var run4 = function()
{
var x1 = document.addsp.spvat.value.length;
if(x1 == 0)
{
alert("SUPPLIER VAT SHOULD NOT BE EMPTY");
return(false);
}
else
return(true);
}
function checkall()
{
if(run1() == false)
{
addsp.spname.focus();
return(false);
}
if(run2() == false)
{
addsp.spadd.focus();
return(false);
}
if(run3() == false)
{
addsp.sptd.focus();
return(false);
}
if(run4() == false)
{
addsp.spvat.focus();
return(false);
}
if(/^[0-9]+$/i.test(addsp.sptd.value) == false)
{
alert("invalid Terms Day");
addsp.sptd.focus();
return(false);
}
else
{
return(true);
}
}
-->
</script>
</head>
<!-- body -->
<div id="content">
<div class="clear">
<p id="bcp">ADD Supplier</p><br><br>
<ul id="nav">
<li>
<a id="abutton" href="supplierprofile">VIEW SUPPLIER</a>
</li>
</ul>
<br>
<form id="aft" name ="addsp" action = "addsp.php" method = "post" onsubmit = "return checkall();">
<fieldset>
<legend>SUPPLIER FORM (NEW)</legend>
<table>
<tr><td>
<span style = "width: 50px;" >Supplier Name</span>
</td><td>
<input size="100" type = "text" name = "spname" onkeyup = "this.value = this.value.toUpperCase();" value =""/><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">Address</span>
</td><td>
<input size="100" type = "text" name = "spadd" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 120px;">Telephone No.</span>
</td><td>
<input size="100" type = "text" name = "sptelno" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">Terms Day</span>
</td><td>
<input size="100" type = "text" name = "sptd" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">VAT</span>
</td><td>
<select name="spvat">
<option id="o1"> </option>
<option id="o2">INCLUSIVE</option>
<option id="o3">EXCLUSIVE</option>
</select>
</td></tr>
<tr><td></td><td>
<input class="afbutton" type = "submit" name = "ADD" value = "ADD" id="ADD"/>
</td></tr>
<tr><td>
</table>
</fieldset>
</form>
</div>
</div>
<? -- script for pages --?>
<script type="text/javascript" src="js/general.js"></script>
<script src="js/submain.js"></script>
this is the addsp.php
<html>
<head>
<script type="text/javascript">
<!--
function direct()
{
window.alert("Suppler has been added");
w = window || document
w.location.reload();
}
-->
</script>
</head>
<body>
<?php
include("connection/config.php");
$spname = $_POST['spname'];
$spadd = $_POST['spadd'];
$sptelno = $_POST['sptelno'];
$sptd = $_POST['sptd'];
$spvat = $_POST['spvat'];
if(!$_POST['ADD'])
{
echo "Please fill out the form";
header('Location: addspform.php');
}
else
{
$query = "SELECT * FROM supplier_profile WHERE sp_name = '$spname'";
$result = mysql_query($query)or die(mysql_error());
$counter = 0;
while($supplier = mysql_fetch_array($result))
{
$counter = $counter + 1;
}
if($counter == 0)
{
mysql_query("INSERT INTO supplier_profile(`SP_NAME`,`SP_ADDRESS`, `SP_TELNO`,`SP_VAT`,`SP_TERMS_DAY`)
VALUES('$spname','$spadd','$sptelno','$spvat','$sptd')") or die(mysql_error());
echo '<script type="text/javascript">
direct();
</script>';
}
}
?>
</body>
sorry about the previous information. Now if i click the add button to the addspform.php all i want after the javascript that pop-up and click ok is to direct the supplierprofile.php inside in the main.php
make your addsp.php like this
<?php
session_start();
include("connection/config.php");
$spname = $_POST['spname'];
$spadd = $_POST['spadd'];
$sptelno = $_POST['sptelno'];
$sptd = $_POST['sptd'];
$spvat = $_POST['spvat'];
if(!$_POST['ADD'])
{
$_SESSION['msg'] = "Please fill form";
header('Location: addspform.php');
exit;
}
else
{
$query = "SELECT * FROM supplier_profile WHERE sp_name = '$spname'";
$result = mysql_query($query)or die(mysql_error());
$counter = 0;
while($supplier = mysql_fetch_array($result))
{
$counter = $counter + 1;
}
if($counter == 0)
{
mysql_query("INSERT INTO supplier_profile(`SP_NAME`,`SP_ADDRESS`, `SP_TELNO`,`SP_VAT`,`SP_TERMS_DAY`)
VALUES('$spname','$spadd','$sptelno','$spvat','$sptd')") or die(mysql_error());
$_SESSION['msg'] = "form has been submitted successfully";
header('Location: addspform.php');
exit;
}
}
?>
you can use header function of php to redirect on some page. use session as msg and print it on your form page as follows
<?php
session_start();
if(isset($_SESSION['msg']))
{
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
?>
<form id="aft" name ="addsp" action = "addsp.php" method = "post" onsubmit = "return checkall();">
<fieldset>
<legend>SUPPLIER FORM (NEW)</legend>
<table>
<tr><td>
<span style = "width: 50px;" >Supplier Name</span>
</td><td>
<input size="100" type = "text" name = "spname" onkeyup = "this.value = this.value.toUpperCase();" value =""/><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">Address</span>
</td><td>
<input size="100" type = "text" name = "spadd" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 120px;">Telephone No.</span>
</td><td>
<input size="100" type = "text" name = "sptelno" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">Terms Day</span>
</td><td>
<input size="100" type = "text" name = "sptd" value = "" /><br />
</td></tr>
<tr><td>
<span style = "width: 100px;">VAT</span>
</td><td>
<select name="spvat">
<option id="o1"> </option>
<option id="o2">INCLUSIVE</option>
<option id="o3">EXCLUSIVE</option>
</select>
</td></tr>
<tr><td></td><td>
<input class="afbutton" type = "submit" name = "ADD" value = "ADD" id="ADD"/>
</td></tr>
<tr><td>
</table>
</fieldset>
</form>
redefine direct as:
function direct(){
window.alert("Suppler has been added");
w = window || document
w.location.reload();
}
Just do a redirect in addsp.php
if (test){
//do something
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=yourpage.php">';//This causes the browser to open the new page after 0 seconds, i.e immediately.
} else {
return false;
}
http://php.about.com/od/learnphp/ht/phpredirection.htm
//addsp.php
function direct()
{
window.alert("Suppler has been added");
document.location.href = "main.php?page='pagenamewhichlastloaded'&redirect=1";
}
//main.php
$(function(){
if($("#redirect").val() == 1){
var page = $("#page").val();
$('#content').load( page + '.php');
}
$('ul#nav li a').click(function() {
var page = $(this).attr('href');
$('#content').load( page + '.php');
return false;
});
});
<div id="content"></div>
<input type="hidden" id="page" value="<?php if(isset($_POST['page'])){ echo $_POST['page']; }?>" />
<input type="hidden" id="redirect" value="<?php if(isset($_POST['redirect'])){ echo $_POST['redirect']; }?>" />