How to create directory with HTML button and PHP - javascript

I wanted to share with you my little attempt at code .. I basically have to make sure that once you press the button is created a folder (via mkdir and php) I do not want to be redirected to other php pages .. he simply has to create this folder, launch the alert and then he has to reappear as before ...
it's possible ?
<!DOCTYPE html>
<?php
function createDirectory()
{
$addettoSicurezza = $_POST["addettoSicurezza"];
date_default_timezone_set('Europe/Rome');
$date = date('Y-m-d');
chdir("../../../../../Archivio/Cantieri");
opendir(".");
mkdir("../../../../Archivio/Cantieri/".$date."_".$nomeCantiere);
echo "<script type='text/javascript'>alert('Done!');</script>";
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
<p>
<table>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD" style="font-weight: bold">2</td>
<td bgcolor="#CDECFD" style="font-weight: bold">Addetto sicurezza</td>
<td bgcolor="#CDECFD"><input type="text" style="width: 220px;" class="form-control" name="addettoSicurezza" id="addettoSicurezza" /></td>
<td colspan="2" bgcolor="#CDECFD">Mail</td>
<td bgcolor="#CDECFD"><input type="text" style="align:center;" class="form-control" style="width: 100%;" name="mailAffidataria" id="mailAffidataria" /></td>
<td bgcolor="#CDECFD"colspan="2"><input type="submit" name="submit" value="Crea directory" /> </td>
</tr>
</table>
</p>
</form>
<?php
}
else{
createDirectory();
}
?>
</body>
</html>

Change your 'createDirectory' function as follows
function createDirectory()
{
$addettoSicurezza = $_POST["addettoSicurezza"];
date_default_timezone_set('Europe/Rome');
$date = date('Y-m-d');
chdir("../../../../../Archivio/Cantieri"); mkdir($date."_".$addettoSicurezza);
echo "<script type='text/javascript'>alert('Done!');</script>";
}

Related

trying to allow an empty row to the bottom of a input table using JavaScript

I am trying to create a form where the user can click on a button that will create a blank row at the bottom of the table. They can click this button for as many rows as they want to add. For some reason, when I click on the button I created, it goes back to my index.php page instead of just adding the row to the current page. Here is some of the code. Please let me know if there is more information that I should be adding here.
Thank you
JavaScript:
function new_line() {
var t = document.getElementById("desc_table");
var rows = t.getElementsByTagName("tr");
var r = rows[rows.length - 1];
var x = rows[1].cloneNode(true);
x.style.display = "";
r.parentNode.insertBefore(x, r);
}
<?php include 'connect.php'; ?>
<!DOCTYPE xhtml>
<html>
<head>
<style type="text/css"><?php //include'css\file.css';?></style>
<script type="text/javascript" src="js/new_line.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<body>
<button id="home" onclick="home_btn()">Home</button>
<title>New Estimate</title>
<h1>New Estimate</h1>
<?php
$sql = $conn->prepare('SELECT * FROM entire_info');
$sql -> execute();
$result = $sql ->get_result();
if ($result->num_rows!=0) {
$entire_info=$result->fetch_assoc();
}
else{
echo'Cannot find company information<br>';
}
?>
<form>
<table id="estimate_table">
<tr>
<td>
<?php
echo '<h1>'.$entire_info['name'].'</h1><br>'.
$entire_info['str_address'].'<br>'.
$entire_info['city'].', '.$entire_info['province'].' '.$entire_info['postal']
.'<br>Phone:'.$entire_info['phone'].'<br>Fax:'.$entire_info['fax'].'<br>'.$entire_info['email'].'<br>';
?>
<br>
</td>
<td colspan="3" style="text-align: right;"><?php echo '<h1>Estimate</h1>'; ?></td>
</tr>
<tr>
<td>
<table>
<tr>
<td style="vertical-align: top;">
For:<br>
<select name="estimate_for">
<?php
$sql = $conn->prepare('SELECT * FROM company');
$sql -> execute();
$result = $sql ->get_result();
if ($result->num_rows>0) {
while ($row=$result->fetch_assoc()) {
$company_name = $row['company'];
echo '<option value="'.$company_name.'">'.$company_name.'</option>';
}
}
else{
echo'Cannot find company information<br>';
}
?>
</select>
</td>
<td>
Job:<br> <textarea name="job_name" style="width: 200px ! important;" style="height: 30px ! important;"></textarea>
</td>
</tr>
</table>
</td>
<td colspan="3" style="text-align: right;">
Invoice#: <br>
Date: <input type="text" name="estimate_date" value="<?php echo date('M d, Y'); ?>">
</td>
</tr>
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<table id="desc_table">
<tr>
<td><font><br><h3>Description</h3></font></td>
<td><font><h3>Hours</h3></font></td>
<td><font><h3>Rate</h3></font></td>
<td><font><h3>Amount</h3></font></td>
</tr>
<tr>
<td ><textarea name="description" style="width: 400px" style="height: 100px ! important;"></textarea></td>
<td> <input type="text" name="hours"></td>
<td> <input type="text" name="rate"></td>
<td><input type="text" name="amount"></td>
<td>
<button onclick="new_line();">+</button>
</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><h3>Subtotal</h3></td>
<td><input type="text" name="subtotal"></td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><h3>GST (#87221 2410)
</h3></td>
<td><input type="text" name="gst"></td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><h3>Total</h3></td>
<td><input type="text" name="subtotal"></td>
</tr>
</table>
</form>
</head>
</body>
</html>
Your button is inside a <form> so by default it will behave like a submit button.
You have to set its type to a normal button by adding the type attribute:
<button onclick="new_line();" type="button">+</button>

unable to submit form data using ajax?

i am very new to php and have no idea of javascript, have done all js work using tutorials.Also tried to use existing solutions from stackoverflow, but no success !
What i am trying to do is trying to update database values using 'submit' button on the basis of values called from 'select option'.
Problem is that no data is getting updated in DB after i click on submit button (on viewtest.php), I have also tried to add the 'update.php' to form action.
Here's the screenshot of viewtest.php
here's my code:
viewtest.php
<form method="POST" action="">
<table border="1px"><tr> <td>
<select required name="tstname" id="test" onChange="fetch_ques()">
<option> Select Test Name</option>
<?php
$res=mysqli_query($connection,"select * from test_detail");
while($row=mysqli_fetch_array($res))
{
?>
<option value="<?php echo $row["test_name"]; ?>">
<?php echo
$row["test_name"]; echo' - - ['. $row['test_category'].']'; ?> </option>
<?php
}
?>
</select>
</div>
<td>
<div id="qnos"><select></select></div></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="btnSubmit" id="vform" value="Update Question"> </td></tr>
</form>
</table>
<div id="ques"></div>
<script type="text/javascript">
function fetch_ques()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","getq.php?
tstnm="+document.getElementById("test").value,false); // function id
xmlhttp.send(null);
document.getElementById("qnos").innerHTML=xmlhttp.responseText; // div id
}
function display_ques()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","displayq.php?
qnos="+document.getElementById("quesdd").value,false);
xmlhttp.send(null);
document.getElementById("ques").innerHTML=xmlhttp.responseText;
}
</script>
<script type="text/javascript">
$(document).ready(function()
{
$("#vform").submit(); (function()
// document.getElementById("vform").submit();(function()
{
location.href='update.php?
qno='+$("#quesno").val()+'&qn='+$("#ques").val()+'&c1='+$("#a1").val()+'&c2='+$
("#a2").val()+'&c3'+$("#a3").val()+'&c4='+$("#a4").val()+'&cr='+$("#cr").val();
});
});
</script>
<?php
if(isset($_GET['st']) && $_GET['st'] !== "")
{
echo"updated";
}
else echo "Error: ".mysqli_errno();
?>
displayq.php //Used to fetch data in select menu
<?php
include '../connect.php';
$quesno=$_GET["qnos"];
if($quesno!="")
{
$qry=mysqli_query($connection,"select * from quesadd where quesid='$quesno'");
echo "<table name='ques'>";
while($ftc=mysqli_fetch_array($qry))
{
?>
<form method="POST" action="">
<table name="ques">
<tr><td align="center" colspan="2"> <!-- // Comment <input type="submit" name="submit" id="upq" value="Update Question">--></td> </tr>
<tr> <td align="center"> <b> Question : <input type="text" id="quesno" value="<?php echo $ftc["quesid"];?>" disabled></b></td>
<td> <textarea name="ques" id="ques" cols="100" rows="3" placeholder="Please Input The Question Here !"> <?php echo $ftc['ques'];?></textarea> </td> </tr>
<tr> <td width="25%" align="center" colspan="2"> <br> <b>Choices</b> </td> </tr>
<tr> <td align="center" colspan="2"><b>1.</b> <input type="text" id="a1" name="a1" value="<?php echo $ftc['c1'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>2.</b> <input type="text" id="a2" size="20px" name="a2" value="<?php echo $ftc['c2'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>3.</b> <input type="text" id="a3" size="20px" name="a3" value="<?php echo $ftc['c3'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>4.</b> <input type="text" id="a4" size="20px" name="a4" value="<?php echo $ftc['c4'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b><font color="maroon">Correct Answer</font></b> <input type="text" size="20px" id="cr" name="correct" value="<?php echo $ftc['answer'];?>"> </td> </tr>
</table>
</form>
<?php
}
echo "</table>";
}
?>
</tr> </td>
</table>
</form>
update.php //Used to update question by getting values from 'viewtest.php'
<?php
include '../connect.php';
$qn=$_GET['qno'];
$qname=$GET['qn'];
$a1=$GET['c1'];
$a2=$GET['c2'];
$a3=$GET['c3'];
$a4=$GET['c4'];
$acr=$GET['cr'];
$update=mysqli_query($connection,"update quesadd SET ques='$qname',
c1='$a1',c2='$a2',c3='$a3',c4='$a4',answer='$acr' where quesid='$qn' ");
if($update==true)
{
header('location:viewtest.php?st=true');
}
?>
I can see multiple problems, don't know if all the problems will go away but it will help.
$("#vform").submit(); (function()
The line above says if a <form> with the id="vform" has been submitted, execute this function. Your form does not have an id so it will never trigger. One other problem is that the function is not part of the trigger. It should be something like
$("#vform").submit(function()
The complete code could look like:
<script type="text/javascript">
$(document).ready(function(){
$("#vform").submit(function(e){
e.preventDefault();
location.href='update.php?qno='+$("#quesno").val()+'&qn='+$("#ques").val()+'&c1='+$("#a1").val()+'&c2='+$("#a2").val()+'&c3'+$("#a3").val()+'&c4='+$("#a4").val()+'&cr='+$("#cr").val();
return false;
});
});
</script>
Use AJAX to submit your form and refresh/redirect the page with javascript.
viewtest.php
<?php
include '../connect.php';
?>
<form method="POST" action="">
<table border="1px">
<tr>
<td>
<select required name="tstname" onchange="display_ques()" id="test">
<option> Select Test Name</option>
<?php
$res = mysqli_query($connection, "select * from test_detail");
while ($row = mysqli_fetch_array($res)) {
?>
<option value="<?php echo $row["test_id"]; ?>">
<?php echo
$row["test_name"];
echo ' - - [' . $row['test_category'] . ']'; ?> </option>
<?php
}
?>
</select>
</td>
<td>
<div id="qnos">
<select>
<!-- put code here for showing question id/number -->
</select></div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnSubmit" id="vform" value="Update Question"></td>
</tr>
</table>
</form>
<div id="ques"></div>
<h1 id="status"></h1>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
function display_ques() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("ques").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "displayq.php?qnos=" + document.getElementById("test").value, true);
xmlhttp.send(null);
}
function fetch_ques() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "getq.php?tstnm = " + document.getElementById("test").value, false); // function id
xmlhttp.send(null);
document.getElementById("qnos").innerHTML = xmlhttp.responseText; // div id
}
$(document).ready(function () {
$('#vform').on('click', function (e) {
e.preventDefault();
var data = $('form#update').serialize();
$.post('update.php', data, function (response) {
// response is the data returned from php echo json_encode(['results' => true/false]), from update.php
var res = JSON.parse(response);
if (res.results == true) {
$('#status').html('Data was updated');
} else {
$('#status').html('Error occured while trying to update data.');
console.log(response);
}
});
});
});
</script>
I have given your form and id to be able to serialize it using jQuery and I have also added a hidden input to hold the id of the current question.
displayq.php
<?php
include '../connect.php';
$quesno = $_GET["qnos"];
if($quesno != "") : ?>
<form id="update" method="POST" action=""> <!-- added an id to the form -->
<table name="ques">
<?php
$qry = mysqli_query($connection,"select * from quesadd where quesid='$quesno'");
while($ftc = mysqli_fetch_array($qry)) : ?>
<tr><td align="center" colspan="2"> <!-- // Comment <input type="submit" name="submit" id="upq" value="Update Question">--></td> </tr>
<tr> <td align="center"> <b> Question : <input type="text" id="quesno" value="<?php echo $ftc["quesid"];?>" disabled></b></td>
<td> <textarea name="ques" id="ques" cols="100" rows="3" placeholder="Please Input The Question Here !"> <?php echo $ftc['ques'];?></textarea> </td> </tr>
<!-- added this hidden input to hold the question number -->
<input type="text" id="quesno" name="quesno" value="<?php echo $ftc["quesid"];?>" hidden>
<tr> <td width="25%" align="center" colspan="2"> <br> <b>Choices</b> </td> </tr>
<tr> <td align="center" colspan="2"><b>1.</b> <input type="text" id="a1" name="a1" value="<?php echo $ftc['c1'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>2.</b> <input type="text" id="a2" size="20px" name="a2" value="<?php echo $ftc['c2'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>3.</b> <input type="text" id="a3" size="20px" name="a3" value="<?php echo $ftc['c3'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b>4.</b> <input type="text" id="a4" size="20px" name="a4" value="<?php echo $ftc['c4'];?>"> </td> </tr>
<tr> <td align="center" colspan="2"><b><font color="maroon">Correct Answer</font></b> <input type="text" size="20px" id="cr" name="correct" value="<?php echo $ftc['answer'];?>"> </td> </tr>
<?php endwhile; ?>
</table>
</form>
<?php endif; ?>
Then in your update.php you can access the values using $_POST
<?php
include '../connect.php';
$qn = trim($_POST['quesno']);
$qname = trim($_POST['ques']);
$a1 = trim($_POST['a1']);
$a2 = trim($_POST['a2']);
$a3 = trim($_POST['a3']);
$a4 = trim($_POST['a4']);
$acr = trim($_POST['correct']);
$sql = "update quesadd SET ques='$qname', c1='$a1',c2='$a2',c3='$a3',c4='$a4',answer='$acr' where quesid='$qn'";
if (mysqli_query($connection, $sql)) {
// returning data to jQuery, as response
// jQuery will parse this as json {results: true}
echo json_encode(['results' => true]);
} else {
// returning data to jQuery, as response
// jQuery will parse this as json {results: false}
echo json_encode(['results' => false]);
}

How to pass the content of one file upload button to another page?

I am new in PHP. I have a button which upload file from system. I use javascript, when user upload file it automatically redirect to web form. On web form i use Three Fields. One is Date second is Title and 3rd is File upload button. Now i want to pass my file content to this button. is it possible?
My button which upload file
My Form after uploading file
I want to store file, date and title in db. To save the time of user i want to pass file content.
How i can do it?
Please help me
Code of Button
<html>
<head>
<script>
function setup() {
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
document.getElementById('fileid').addEventListener('change', submitForm);
function submitForm() {
document.getElementById('formid').submit();
}
}
</script>
</head>
<body onload="setup()">
<form id='formid' action="mb.php" method="POST" enctype="multipart/form-data">
<input id='fileid' type='file' name='filename' hidden/>
<input id='buttonid' type='button' value='Upload MB' />
<input type='submit' value='Submit' hidden="" />
</form>
</body>
</html>
Code of my form
mb.php
<?php
session_start();
//$user_id = $_SESSION['uid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra-daily";
$conn = new mysqli($servername, $username, $password, $dbname);
//$id2 = $_GET['id'];
$sql="SELECT pacra_teams.title as 'teamTitle', og_users.display_name, og_users.id
FROM og_users
LEFT JOIN pacra_teams
ON pacra_teams.id = og_users.team_id
Where og_users.id = 20 ";
$result = $conn->query($sql);
$row = $result->fetch_object();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Morning Briefing</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="js/jquery-ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#mydate").datepicker({
dateFormat: "dd-M-y",
onSelect: function(dateText, inst) {
$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);
}
}).datepicker("setDate", new Date());
});
</script>
</head>
<body>
<form action="up_mb.php" method="POST" enctype="multipart/form-data">
<div style="margin:auto; width:auto" align="center">
<table width="547" class="tblbdr" >
<tr>
<td height="23" colspan="6" class="head"><p> Morning Briefing </p></td>
</tr>
<tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:300px" readonly> </td></tr>
<tr>
<tr><td class="celltext"><b>Title: </b><br> </td>
<td class="celltext" style="width:200px" > <span id="dt_title"> <input name="title" type="text" value=" MB |
<?php echo $row->teamTitle;?> | <?php echo $row->display_name; ?> | <?php echo date("d-M-y");?>"
data-title="MB | <?php echo $row->teamTitle;?> | <?php echo $row->display_name;?> | " style="width:300px"/ readonly> </span> </td> </tr>
</tr>
<td class="celltext"><b>Upload File:</b></td>
<td colspan="4" bordercolorlight="#006666">
<input type="file" name="myfile" id="myfile" width="100%" size=80/>
<!-- <input type="file" name="files[]" multiple style="width:300px"/> -->
</td></tr>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td width="151">
</td>
<tr>
<td height="12">
</td>
<td width="290">
</td> </tr>
</table>
</div>
</form>
</body>
</html>
for security reason, it's not possible to set the file of a uppload field
but you can send the file to the server with your first button and then, add information on this upload with the second form, it depends what you want to do with these data

How to pass a page content to another page and then save it into Mysql?

I have a button code with JavaScript. This button works as a file upload button. When user click on this button a file browser window will be open and user select a file to upload. After selecting the file the page automatically redirect to another page.
PROBLEM:
I want to pass the content of my button (File which is upload by the user using button) to the another page while redirection on other page. and then save it into Mysql Db.
Here is my button code:
a1.php
<html>
<head>
<script>
function setup() {
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
document.getElementById('fileid').addEventListener('change', submitForm);
function submitForm() {
document.getElementById('formid').submit();
}
}
</script>
</head>
<body onLoad="setup()">
<form id='formid' action="mb.php" method="POST" enctype="multipart/form-data">
<input id='fileid' type='file' name='filename' hidden/>
<input id='buttonid' type='button' value='Upload MB' />
<input type='submit' value='Submit' hidden="" />
</form>
</body>
</html>
Code on which user redirect after uploading file
mb.php
<?php
session_start();
//$user_id = $_SESSION['uid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra-daily";
$conn = new mysqli($servername, $username, $password, $dbname);
//$id2 = $_GET['id'];
$sql="SELECT pacra_teams.title as 'teamTitle', og_users.display_name, og_users.id
FROM og_users
LEFT JOIN pacra_teams
ON pacra_teams.id = og_users.team_id
Where og_users.id = 20 ";
$result = $conn->query($sql);
$row = $result->fetch_object();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Morning Briefing</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="js/jquery-ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#mydate").datepicker({
dateFormat: "dd-M-y",
onSelect: function(dateText, inst) {
$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);
}
}).datepicker("setDate", new Date());
});
</script>
</head>
<body>
<form action="up_mb.php" method="POST" enctype="multipart/form-data">
<div style="margin:auto; width:auto" align="center">
<table width="547" class="tblbdr" >
<tr>
<td height="23" colspan="6" class="head"><p> Morning Briefing </p></td>
</tr>
<tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:300px" readonly> </td></tr>
<tr>
<tr><td class="celltext"><b>Title: </b><br> </td>
<td class="celltext" style="width:200px" > <span id="dt_title"> <input name="title" type="text" value=" MB |
<?php echo $row->teamTitle;?> | <?php echo $row->display_name; ?> | <?php echo date("d-M-y");?>"
data-title="MB | <?php echo $row->teamTitle;?> | <?php echo $row->display_name;?> | " style="width:300px"/ readonly> </span> </td> </tr>
</tr>
<td class="celltext"><b>Upload File:</b></td>
<td colspan="4" bordercolorlight="#006666">
<input type="file" name="myfile" id="myfile" width="100%" size=80/>
<!-- <input type="file" name="files[]" multiple style="width:300px"/> -->
</td></tr>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td width="151">
</td>
<tr>
<td height="12">
</td>
<td width="290">
</td> </tr>
</table>
</div>
</form>
</body>
</html>
In mb.php i want to replace my following code
<td class="celltext"><b>Upload File:</b>
</td>
<td colspan="4" bordercolorlight="#006666">
<input type="file" name="myfile" id="myfile" width="100%" size=80/>
<!-- <input type="file" name="files[]" multiple style="width:300px"/> -->
</td>
</tr>
With the content of button. And then i want to store it in db.
How I can Pass the content of a page?
Something like this?
<?php
session_start();
//$user_id = $_SESSION['uid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra-daily";
$conn = new mysqli($servername, $username, $password, $dbname);
//$id2 = $_GET['id'];
$sql="SELECT pacra_teams.title as 'teamTitle', og_users.display_name, og_users.id
FROM og_users
LEFT JOIN pacra_teams
ON pacra_teams.id = og_users.team_id
Where og_users.id = 20 ";
$result = $conn->query($sql);
$row = $result->fetch_object();
if(isset($_POST['submit'])) {
//Here you can put your code when clicking the button
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Morning Briefing</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="js/jquery-ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#mydate").datepicker({
dateFormat: "dd-M-y",
onSelect: function(dateText, inst) {
$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);
}
}).datepicker("setDate", new Date());
});
function setup() {
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
document.getElementById('fileid').addEventListener('change', submitForm);
function submitForm() {
document.getElementById('formid').submit();
}
}
</script>
</head>
<body>
<form action="up_mb.php" method="POST" enctype="multipart/form-data">
<div style="margin:auto; width:auto" align="center">
<table width="547" class="tblbdr" >
<tr>
<td height="23" colspan="6" class="head"><p> Morning Briefing </p></td>
</tr>
<tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:300px" readonly> </td></tr>
<tr>
<tr><td class="celltext"><b>Title: </b><br> </td>
<td class="celltext" style="width:200px" > <span id="dt_title"> <input name="title" type="text" value=" MB |
<?php echo $row->teamTitle;?> | <?php echo $row->display_name; ?> | <?php echo date("d-M-y");?>"
data-title="MB | <?php echo $row->teamTitle;?> | <?php echo $row->display_name;?> | " style="width:300px"/ readonly> </span> </td> </tr>
</tr>
<td class="celltext"><b>Upload File:</b></td>
<td colspan="4" bordercolorlight="#006666">
<form id='formid' action="mb.php" method="POST" enctype="multipart/form-data">
<input id='fileid' type='file' name='filename' hidden/>
<input id='buttonid' type='button' value='Upload MB' />
<input type='submit' name="submit" value='Submit' hidden="" />
</form>
</td></tr>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td width="151">
</td>
<tr>
<td height="12">
</td>
<td width="290">
</td> </tr>
</table>
</div>
</form>
</body>
</html>
I noticed you are starting a session in php. You can use session variables to carry over variables from one page to another as long as they are in the same session.
eg: $_SESSION["filename"]=$_POST["filename"]; in a1.php to store your filename.
(You can fetch the value through $_POST for your button)
Then in m2.php you can retrieve the same by using $_SESSION["filename"]
Make sure you have session_start() in the pages you need this value.
Here's the reference for sessions in PHP.
http://php.net/manual/en/reserved.variables.session.php

On clicking the form divert to another PHP page with the results of the check box

I have a set of check boxes on one page and submit button with value="compare" is out of the form. I have written a jQuery for the button compare outside of the form. I am comparing a set of tables side by side. My code works fine in the same Page. I don't know how to display the result in another page. Anyone please help me.
<?php
require('db.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comparision</title>
</head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#compare_id").click( function(){
$("input:checkbox:not(:checked)").each(function() {
var column = "table ." + $(this).attr("name");
$(column).hide();
});
});
});
$(document).ready(function(){
$("#compare_id").click( function(){
$("input:checkbox:(:checked)").each(function(){
var column = "table ." + $(this).attr("name");
$(column).toggle();
});
});
});
</script>
</head>
<body>
<input name="compare" id="compare_id" type="button" value="Compare" />
<form action="test.php" method="post" name="printers_comparision">
<p>
<label>
<input type="checkbox" name="p1" value="Printer1" id="CheckboxGroup1_0" />
Printer1</label>
<label>
<input type="checkbox" name="p2" value="Printer2" id="CheckboxGroup1_1" />
Printer2</label>
<label>
<input type="checkbox" name="p3" value="Printer3" id="CheckboxGroup1_2" />
Printer3</label>
<label>
<input type="checkbox" name="p4" value="Pritner4" id="CheckboxGroup1_3" />
Printer4</label>
<label>
</form>
<table width="1023" border="1">
<tr>
<td width="193"></td>
<td class="p1" width="113"><img src="images/im.png"/></td>
<td class="p2" width="67"><img src="images/im.png"/></td>
<td class="p3" width="67"><img src="images/im.png"/></td>
<td class="p4" width="67"><img src="images/im.png"/></td>
</tr>
<tr>
<td>Title</td>
<td class="p1" >Printer1</td>
<td class="p2" >Printer2</td>
<td class="p3" >Printer3</td>
<td class="p4" >Printer4</td>
</tr>
<tr>
<td>Manufacturer</td>
<td class="p1" ><?php $query=mysql_query('select Manufacturer from printers where printers_id="1";');
while($row=mysql_fetch_array($query)) echo $row['Manufacturer'] ?></td>
<td class="p2" ><?php $query=mysql_query('select Manufacturer from printers where printers_id="2";');
while($row=mysql_fetch_array($query)) echo $row['Manufacturer'] ?></td>
<td class="p3" ><?php $query=mysql_query('select Manufacturer from printers where printers_id="3";');
while($row=mysql_fetch_array($query)) echo $row['Manufacturer'] ?></td>
<td class="p4" ><?php $query=mysql_query('select Manufacturer from printers where printers_id="4";');
while($row=mysql_fetch_array($query)) echo $row['Manufacturer'] ?></td>
</tr>
</body>
</table>
</table>
You can try out using SESSION variables or setting COOKIE in case you need to show data across pages

Categories

Resources