I have this php code which hide the download button after clicking on it one time by changing the ID from 0 to 1 .. after that if another time the user signed in , it removes the button using a simple css hide code.
here is my code :
<?php
$result = #mysql_query("SELECT * FROM scode WHERE updated= 1 and coden ='$username'");
if ($_POST[downloadTheFile]== "downloadTheFile")
{
$upd_art = "update scode set downloaded='".$_POST[t11] ."' where id='$_SESSION[userid]'";
mysql_query($upd_art) or die(mysql_error());
}
if($row['downloaded']==1)
{
echo "<style>
.thedownloadbutton {display:none;}
</style>";
}
?>
<form class="thedownloadbutton" method="get" action="<? echo '../download/'.$item_downloadlink .'.zip' ; ?>">
<button type="submit" name="downloadTheFile" value="downloadTheFile">Download </button>
<input name="t11" type="hidden" size="2" value="1">
</form>
(just for clarifying: updated =1 is a field that'll open the download page.. if the updated =1 then there is a download page )
I don't know why it doesn't work ..
can you help me please and till me which part is the wrong part ?
I know it's a bad way to hide an element using css , is there another suggestion ?
$_POST[downloadTheFile] should be $_POST['downloadTheFile']
if($row['downloaded']!=1)
{
echo '<button type="submit" name="downloadTheFile" value="downloadTheFile">Download </button>';
}
so there were some problems in this code .. it wasn't professional at all so I used this new code which has a button that update the number from 0 to 1 on the database
(that will tell the download button to not show after that)
then shows the download button
<?
$res = mysql_query("SELECT downloaded FROM scode WHERE id='$_SESSION[userid]'");
$row = mysql_fetch_array($res);
// echo $row['downloaded'];
echo '<br>';
?>
<form method="POST" action=''>
<?
if($row['downloaded'] ==='0')
{
echo "<input type='submit' name='button1' value='click to show the download link' onclick ='validatea(); return false;' />";
//echo '<button type="submit" formmethod="post" name="downloadTheFile" value="downloadTheFile">Download </button>';
?>
</form>
<?
if (isset($_POST['button1']))
{
?> <form class="aaa" method="POST" action="<? echo "../download/".$item_downloadlink .".zip" ; ?>">
<? ;
?> <input type='submit' name='submit' value='download' onclick ='validate(); return false;' /> <? ;
echo"</form>";
$upd_art = "update scode set downloaded='1' where id='$_SESSION[userid]'";
mysql_query($upd_art) or die(mysql_error());
}
}
else {
echo "you already downloaded the file , if you have any problem please contact us";
echo"<br>";
}
?>
Related
I have a list of items in one file (fruit.php):
<form action="delete_items.php" method="post">
<input type="radio" value="apple" name="fruit">Apple<br>
<input type="radio" value="pear" name="fruit">Pear<br>
<input type="radio" value="banana" name="fruit">Banana<br>
<input type="submit" value="delete" name="deleteButton"><br>
</form>
In the delete_items.php, I have a variable that stores the selection:
<?php
$selection = $_POST["fruit"];
echo "are you sure you want to delete it?";
echo '<form action="delete_confirmation.php" method="post"><br>';
echo '<input type="submit" name="deleteYes" value="Yes"><br>';
echo '<input type="submit" name="deleteNo" value="No"><br>';
echo '</form>';
?>
Than in the confirmation file (delete_confirmation.php):
<?php
include 'delete_items.php';
if($_POST["deleteYes"]){
$query = 'DELETE FROM databaseName WHERE fruitName="' . $selection . '"';
$result = mysqli_query($connection, $query);
if(!$result){
die("Delete after check query failed!");
} else {
echo "Delete after check query success!";
}
} elseif($_POST["deleteNo"]){
echo "The course was not deleted!";
}
?>
But the varibale $selection in the delete_confirmation.php file is always null even though i included the delete_items.php file (when i echo it, nothing is shown). Is there a way to pass the selection variable from delete_items.php to the delete_confirmation.php file?
I can't figure this out alone. I have .html file and in body section I'm importing some .php files using switch. I'm displaying table and I'm navigating on it with POST form. Now I want to add to my navigation bar search input which also will send data by POST. It is located on head tag and when I press the button nothing really happens.
index.php
<html>
<head>
<div class="leftNav">
<a class="buttonNav" href="index.php?subpage=table&data=session&page=0">Session</a>
<a class="buttonNav" href="index.php?subpage=table&data=all&page=0">All</a>
</div>
<div class="rightNav">
<?php include 'navbars.php' ?>
</div>
</head>
<body style="font-family:Verdana;">
<div class="content">
<?php
if(isset($_GET['subpage']))
{
switch($_GET['subpage'])
{
case 'table':
include 'datatable.php';
break;
default:
include 'home.php';
break;
}
}
else include 'home.php';
?>
</div>
</body>
</html>
datatable.php
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_POST['search'])
{
$filtr = $_POST['filtr'];
$data = $_GET['data'];
header("
Location: index.php?subpage=table&data=".$data."&page=0&search=".$filtr);
}
else{...}
}
//DISPLAYING TABLE//
echo("
</table>
<form class='nav' method='POST'>");
$disabled = '';
if($curr+1 == 1)
$disabled = "disabled='disabled'";
echo("<input type='submit' name='f' value='First page' ".$disabled.">
<input type='submit' name='p' value='Previous page' ".$disabled."> ");
$disabled = "";
if($curr == $max)
$disabled = "disabled='disabled'";
echo("<input type='submit' name='n' value='Next page' ".$disabled.">
<input type='submit' name='l' value='Last page' ".$disabled."></form>");
?>
navbars.php
<?php
if(isset($_GET['subpage']) && $_GET['subpage'] == 'table')
{
echo("
<form method='POST'>
<input type='text' name='filtr'>
<input type='submit' name='search' value='Search'>
</form>
");
}
?>
As noted in the other answer, you will want to use the action attribute but you'll want to pass the $_GET['subpage'] as in:
action="<?php if(!empty($_GET['subpage'])) echo '?subpage='.htmlspecialchars($_GET['subpage'], ENT_QUOTES) ?>"
Note: I don't see anywhere that you actually send the $_GET['subpage'] or $_GET['data'] in your scripts in the first place, so I don't know if that is even being called properly.
Try Adding form action if you are referring to same page,
action="<?php echo $_SERVER["PHP_SELF"];?>"
hope it helps you.
This is the code I wrote to generate as many forms as there is entries in a table.
I'd like to know which Submit button (i.e. of which exact form) was clicked to then execute some SQL actions.
Thank you for your help!
<?php
require_once 'header.php';
if (!$loggedin) die();
$result = queryMysql("SELECT * FROM audit_requests");
$num_rows = $result->num_rows;
echo "<div class='main'><h3>$num_rows audit requests found!</h3>";
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
$requester = stripslashes($row['user']);
$audit_request_id = stripslashes($row['audit_request_id']);
echo <<<_END
<form method='post' action='audit_listings.php' enctype='multipart/form-data'>
<span class='text'><br>Audit request number</span>
<input disabled type='text' maxlength='10' name='audit_request_id' value='$audit_request_id'>
<span class='text'><br>Auditee name</span>
<input disabled type='text' maxlength='16' name='user' value='$requester'>
_END;
if (getCategory($user) == 'Auditor')
{
echo "<input type='submit' value='Apply for this audit request'>";
}
echo <<<_END
</form></div><br>
_END;
}
if (isset($_POST['audit_request_id']))
{
$audit_request_id = stripslashes('audit_request_id');
queryMysql("INSERT INTO audit_plan SELECT * FROM audit_requests WHERE audit_request_id='$audit_request_id'");
queryMysql("UPDATE audit_plan SET applicant='$user' WHERE audit_request_id='$audit_request_id'");
queryMysql("INSERT INTO messages VALUES('', 'TrustusChain', '$org_name', '$address', '', '$city'");
}
?>
You could add a hidden field to the form. Like:
echo "<input type=\"hidden\" value=\"form_xxx\">";
You can generate random id's to the form like
<form method="post" onsubmit="return myfunc(this.id)" id="From_php">
in javascript
<script>
function myfunc(id){
//do anything with id of form
}
</script>
You can pass ajax requests to server accordingly.
<?php
$sel22 = mysql_query("SELECT id1nev, id2nev, id2, accept FROM barat WHERE id1= '$kariidje' AND accept = '1' ") or die("CANNOT FETCH DATA FOR ADMIN " . mysql_error());
if (mysql_num_rows($sel22) > 0) {
$i=0;
while ($data22 = mysql_fetch_array($sel22)) {
$i++;
?><tr>
<td>
<?php
include 'elemek/connection.php';
$idkitfogadel = $data22['id2'];
if(isset($_POST["submitelutasit"])){
$updatebaratt1 = "DELETE FROM barat WHERE id1 = $kariidje and id2 = $idkitfogadel";
mysql_query($updatebaratt1);
//header("Location: friends.php");
}
?>
<form id="form<?php echo $i; ?>" method="POST" action="#">
<Button type="SUBMIT" name="submitelutasit" id="submitelutasit<?php echo $i;?>" value="!"/></button>
</form>
</td>
<td align="center">
<a>Something</a>
</td>
</tr>
<?php
}
This is my code in my page. The problem is if I press the button in any line its delete all my data and not only what i want. Each line each button when I press a button its delete that line where is it. This is what i want. I cant solve this problem (sad).
Thank you
I will just assume that you are just playing around, and that's not even near to the production code.
Add input field to your form with id2 so you can use it later.
<form id="form<?php echo $i; ?>" method="POST" action="#">
<input type="hidden" name="id2" value="<?php echo $data22['id2'] ?>">
<Button type="SUBMIT" name="submitelutasit" id="submitelutasit<?php echo $i;?>" value="!"/></button>
</form>
And use it like this:
$idkitfogadel = $_POST['id2'];
Inside your if(isset($_POST["submitelutasit"])) statement.
I'm sure that little kitty died somewhere right now :(
I am trying to create tickets system, the idea is to fetch all the tickets beside the new ticket form in the same page, I want when someone click on the ticket the tickets and the new ticket form should disappear and open the ticket with the response form in the same page. I mean when someone clicks on the ticket I want everything to disappear expect the responses form. Please Help.
print ("
<form action='<?php echo $PHP_SELF;?>' method='post' class='f'>
<input type='text' name='subject' placeholder='العنوان'></input>
<textarea name='tmessage' placeholder='الموضوع'></textarea>
<input type='submit' name='t_submit' value='انشاء'></input>
</form>");
$tsubject=$_POST['subject'];
$tmessage=$_POST['tmessage'];
$tsubmit=$_POST['t_submit'];
$ttdate=date ("Y-m-d");
if(isset($tsubmit)){
$int=mysql_query("INSERT INTO tickets(id,u_id,message,subject,date,status)
VALUES('','$_SESSION[id]','$tmessage','$tsubject','$ttdate','0')");
if($int) { echo "تم انشاء التذكرة بنجاح";} else{ echo "خطاء"; }
}
$gtk=mysql_query("SELECT * FROM tickets WHERE u_id='$_SESSION[id]'");
while($ftk=mysql_fetch_object($gtk)){
if($ftk->status == 0) { $tkst= "معلقة"; }
if($ftk->status == 1) { $tkst= "مجابه"; }
print("<a href='tickets.php?tkid=$ftk->id' class='f'>$ftk->subject</a> .
$tkst");
}
$tkid=$_GET['tkid'];
$uig=mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]'");
$fuig=mysql_fetch_object($uig);
$gm=mysql_query("SELECT * FROM tickets WHERE id='$tkid'");
$fgm=mysql_fetch_object($gm);
print ("<fieldset>
<legend>$fuig->username </legend>
$fgm->message
</fieldset>");
$grs=mysql_query("SELECT * FROM responses WHERE t_id='$tkid' ORDER BY id
ASC");
while($fgrs=mysql_fetch_object($grs)){
print("$fgrs->response <br>");
}
print("
<form action='<?php echo $PHP_SELF;?>' method='post'>
<textarea name='response'></textarea>
<input type='submit' name='rsubmit' value='ارسل'></input>
</form>
");
$response=$_POST ['response'];
$rsubmit=$_POST ['rsubmit'];
$tdate=date ("Y-m-d");
if(isset($rsubmit)){
$ir=mysql_query("INSERT INTO responses(id,t_id,response,r_date) VALUES
('','$tkid','$response','$tdate')");
if($ir) { echo "تم ارسال الرد";
} else { echo "خطاء";}
}
?>