i have a simple delete button in PHP which uses simple SQL query to delete the data from database, I have used the following code:
$myid = $this->uri->segment('3');
if (isset($_POST['submit'])){
$ret = mysqli_query($con,"delete * from smart_category where name='$myid'");
header("Location: https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory");
}
<div style="margin-left:38%" class="clearfix">
<a href="https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory">
<button type="button" class="cancelbtn bemine">Cancel</button></a>
<form action="" method="post" ><button type="submit" name="submit" class="deletebtn bemine">Delete</button></form>
</div>
the problem here is if I click the delete button, its not responding, nothing is happening. the button is like static. can anyone please tell me what could be wrong here
If any Javasscript is not involved, than just put form action.
Also send myid in the request or in URI.
please see below:
<div style="margin-left:38%" class="clearfix">
<button type="button" class="cancelbtn bemine">Cancel</button>
<form action="abc.php" method="post" ><button type="submit" name="submit" class="deletebtn bemine">Delete</button></form>
</div>
You should add an action url/path to where your PHP file is located and add a Method to your form. Also, I noticed you deleting an entry where "name" is equal to $myid please check if that is correct.
<div style="margin-left:38%" class="clearfix">
<button type="button" class="cancelbtn bemine">Cancel</button>
<form action="url-to-server.php" method="post" >
<button type="submit" name="submit" class="deletebtn bemine">Delete</button>
</form>
</div>
$myid = $this->uri->segment('3');
if (isset($_POST['submit'])){
$ret = mysqli_query($con,"delete * from smart_category where name='$myid'");
header("Location: https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory");
}
Related
I have two PHP files: index.php with a form, and data.php for further data manipulation.
Here is index.php:
<?php
session_start();
require_once("../index.conf");
$language = new Language();
$lang = $language->getLanguage(#$_POST['lang']);
?>
...
<form name="myForm" action="data.php" method="post" onsubmit="return validateForm()">
<input type="text" name="title" placeholder="e.g.: my_title" value="<?php echo isset($_POST['title']) ? $_POST['title'] : '' ?>">
...
<button class="btn_r" name="submit" type="submit">
<?php echo $lang['submit-button']; ?>
</button>
Here is data.php:
// success message
echo sprintf('
<div class="success">Good job! Your file <em>'.$file.'</em> was successfully created with this HTML content:<br>
<form name="goto_preview" method="post">
<input type="hidden" name="img_title" value="'.$title.'">
<button class="btn_l" name="reset" type="submit" name="logout" formaction="preview.php">PREVIEW RESULTS</button>
<button class="btn_r" name="submit" type="submit" name="continue" formaction="index.php">CORRECT DATA</button>
</form>
</div>',$img_name);
I try to return the user to the form, with the original values filled in if correction is needed. But the form always opens empty. What is wrong with my code?
Nothing is wrong with your code. That's just the way php forms work, you're redirecting to a new page therefore the form isn't filled out. To change that you could pass the POST arguments that you receive in the data.php and pass them back to index.php where you set them as default values (if present)
the links of this form have question marks:
This is a file: sidebar.php
echo
<form method='get'>
<div class='left'>
<div class='btn-group-vertical'>
<!-- Vertically Stck button group -->
<button 'submit' name='Service)name' class='btn btn-default'>Service Name</button>
<button type='submit' name='YYY_Service' class='btn btn-default'>YYY Service</button>
</div>
</form>;
?>
This is a part of index.php:
ini_set('session.save_path','/path/to/session');
session_start();
error_reporting(E_ALL); ini_set('display_errors', 1);
$current_menu='empty.php'; //If no menu/button is selected get right column empty(empty.php)
if(isset($_REQUEST['Service'])){$current_menu='serviceform.php';}
if(isset($_REQUEST['YYY_Service'])){$current_menu='yyyform.php';}
This is showing URLS such as:
www.foo.com/index.php?Service=
www.foo.com/index.php?YYY_Service=
How should this form changed in order to show instead urls this way?
www.foo.com/serviceform.php
www.foo.com/yyyform.php
And this code in another file:
function Button_set($name, $newline)
{
if($newline){
?>
<br><br><input type="button" name="<?=$name?>" value="<?=$name?>" /input>
<?php
}
else if (!$newline){
?>
<input type="button" name="<?=$name?>" value="<?=$name?>" /input>
<?php
}
}
If I only change the form method to POST it doesn't work...
Change:
<form method="get">
to:
<form method="post">
Also add attribute "action" to site you want:
<form method="post" action="serviceform.php">
<form method="post" action="yyyform.php">
W3C link on form
<form id="form" name="form" method="post" action="">
<div class="jquery-script-clear"></div>
<h1>BARCODE GENERATOR</h1>
<div id="generator"> Please fill in the code :
<input type="text" name="barcodeValue" id="barcodeValue" value="1234"><br> <br>
</div>
<div id="submit">
<input type="button" onclick="generateBarcode();" value=" Generate "> <input type="button" onclick="printDiv('print')" value="Print" />
</div>
</form>
<?php
$barcodeValue = $_POST["barcodeValue"];
$save = file_get_contents("save.txt");
$save = "$barcodeValue" . $save;
file_put_contents("save.txt", $save);
echo $save;
?>
sample picture
How to save the input data in save.txt file. When i clicked generate button the text file not showing in same folder.
The problem with your code is you have no submit button so your form was not actually posting when you pressed the button. if you look at my edits you can see I changed the button from input type="button" to type="submit". That allows for the form to submit back to the same php script.
Your script also was causing errors because you accessed $_POST["barcodeValue"] without checking if it existed. You also have to check if the save.txt exists before reading from it. If analyze my edits you can see how checking if the variables are available will help quite a bit.
<form id="form" name="form" method="post" action="">
<div class="jquery-script-clear"></div>
<h1>BARCODE GENERATOR</h1>
<div id="generator"> Please fill in the code :
<input type="text" name="barcodeValue" id="barcodeValue" value="1234"><br> <br>
</div>
<div id="submit">
<input type="submit" value=" Generate ">
</div>
</form>
<?php
if(isset($_POST["barcodeValue"]))
{
$barcodeValue = $_POST["barcodeValue"];
if(file_exists("save.txt"))
$save = file_get_contents("save.txt");
else
$save = "";
$save = $barcodeValue . $save;
file_put_contents("save.txt", $save);
echo $save;
}
?>
Let me know if you need more help
I'm including a a php code with angular ui routing
the problem is if the millitary.php :
`
<div class="jumbotron">
<div class="page-header">
<h1>Millitary Loot Table</h1>
</div>
<?php
$MillitaryLoot = array(
'M4A4' => 47,
'AWP' => 2,
'Karambit' => 1,
'Famas' => 50
);
$newMillitaryLoot = array();
foreach ($MillitaryLoot as $item=>$value)
{
$newMillitaryLoot = array_merge($newMillitaryLoot, array_fill(0, $value, $item));
}
$myLoot = $newMillitaryLoot[array_rand($newMillitaryLoot)];
if (isset($_POST['submit']))
{
echo "\n" . "<h2 style='display:inline;'>Item: </h2>" . '<p class="text-center text-danger">' . $myLoot . '</p>' . "</br>";
}
?>
<form name="Gamble" action="" method="post" target="_self">
<button name="submit" type="submit" class="btn btn-primary">Gamble</button>
</form>
</br>
</div>
`
the include app.js
$stateProvider
.state('millitary', {
url: '/millitary',
templateUrl: 'inc/millitary.php'
})
is included into the index.php the submit button basicly not executes the code above the form
so basically i want the php code to execute in the index.php to keep the ui instead of jumping into the executing php file and losing the index.php linked styles and navigation
edit : if i run the code normaly it works but it doesn't if it gets included
edit2 : everything outside the if statement works basically if i add a echo "test"; it outputs but inside the if it does not so the problem is the form and the connection to the if statement
kind regards, daniel
Change your HTML to the following:
<form id="form" name="Gamble" method="post">
<button id="form" name="submit" type="submit" class="btn btn-primary">Gamble</button>
</form>
You can submit your form with a button with HTML5 but it must share the same ID of the form. Also keep in mind this will only be supported with browsers that support HTML5 so if not they won't be able to submit the form.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
The other alternative is to use...
<input name="submit" type="submit" class="btn btn-primary" value="Gamble">
as #gbestard suggested.
Change
<button name="submit" type="submit" class="btn btn-primary">Gamble</button>
to
<input name="submit" type="submit" class="btn btn-primary" value="Gamble" />
In order to submit you need a type submit input or use some client side script as javascript
I have a page called service.php that uses a modal window to open a form. The action on the form was service.php.
<div class="modal hide fade" id="myServiceModal" tabindex="-1" role="dialog" aria-labelleby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Service Failure Form</h3>
</div>
<div class="modal-body">
<p>
<form class="well-small" action="service.php" method="POST" id="serviceModalForm" name="serviceModalForm">
<label>Container Selected</label>
<input type="text" name="containerNumber" id="containerNumber" />
<label>Bol Selected</label>
<input type="text" name="bolNumber" id="bolNumber" />
<input type="submit" id="modal-form-submit" name="submit" class="btn btn-success btn-small" href="#" value="Save" />
<?php
$bol = $_POST['bolNumber'];
$container = $_POST['containerNumber'];
if(isset($_POST['submit'])){
$sql_query_string =
"INSERT INTO import_view_svc_fail (bol, container_num) VALUES
('$bol', '$container');";
if(mysql_query($sql_query_string)){
echo ("<script language='javascript'>
window.alert('Added New Service Failure')
</script>");
}
?>
</form>
This form worked, and it saved to the appropriate table.
Here is my problem: I had to move that form to another page, called dispatch.php. All I did was copy the code, and put it on dispatch.php.
I changed the action of the form to dispatch.php, and that's where I think the problem starts. When I change the action back to service.php, it works for whatever reason.
When I remove the form completely from service.php, the form on dispatch.php no longer works.
I've tried everything to make this work. I removed all of the code from service.php. I even removed the whole file from the folder.
Any insight would be helpful.
You tell the script what to do but you don't tell it to do it.
In order to excecute a your SLQ-query you have to use mysql_query($sql_query_string);
You will also want to connect to your database. Take a look at http://php.net/manual/de/function.mysql-connect.php for more information.
so.. you change the action in service.php:
<form class="well-small" action="dispatch.php" method="POST" id="serviceModalForm" name="serviceModalForm">
Move to dispatch.php
<?php
if(isset($_POST['submit']))
{
$bol = (isset($_POST['bolNumber'])) ? $_POST['bolNumber'] : '';
$container = (isset($_POST['containerNumber'])) ? $_POST['containerNumber'] : '';
if (!empty($bol) && !empty($container))
{
$sql_query_string =
"INSERT INTO import_view_svc_fail (bol, container_num) VALUES
('$bol', '$container');";
// run the query here
print "<br/><br/>".$sql_query_string."<br/><br/>";
}
else { print "<br/><br/>empty values;<br/>"; }
}
else { print "<br/><br/>\$_POST info not received;<br/>"; }
?>
prints (after submit):
INSERT INTO import_view_svc_fail (bol, container_num) VALUES ('input one value', 'input two value');
you probably should check and make sure you got all your post values inside the if(isset($_POST['submit'])) statement, too. or re-work the logic as a whole... it depends if you want to allow blank values, too.
Also, read up on sql injection and why you should learn to use mysqli_ or pdo.