$jepse = $_POST['slj'];
if(isset($jepse)){
$sql43 = "UPDATE notifications SET seen='1' WHERE touser='$myid' ";
if(mysqli_query($con, $sql43)){
}}
?>
<center>
<form action="#" method="POST">
<input type="submit" name="slj" value="Seen" style="background: rgba(255,255,255, 0); ">
</form>
</center>
I have very stupid problem here... My submit button wont set ..... Don't know what is problem... I have many same things on different pages and with different names... But for this it wont work .... Anyone help?
:::::::::::::::::::UPDATE:::::::::::::::::::::::
I did it with moving update code to another file and at action set that file...
A submit button alone isn't enough to post a value. You should use a form field like a hidden input to post your data. I made this stupid mistake also.
<input type="hidden" name="slj" value="some-value">
You doesn't set any values to submit to the server.
You have to change the form like this:
<center>
<form action="" method="POST">
<input type="hidden" name="slj" value="1">
<input type="submit" value="Seen" style="background: rgba(255,255,255, 0); ">
</form>
</center>
A value in the submit button is just the text printed on the button. You have to set another hidden input value and that will be sent.
Also it could be heplful to change the action to "".
your codding is expected to work as is if there are no spelling mistakes somewhere: Although the
defining a POST element before checking if it is set, the program will see it as it is not defined ref: $jepse = $_POST['slj']; but that should not be the main problem why your database is not updating since once you clicked the button it was then defined.
Also in your form <form action="#"... remove the #
i.e. if you are on the same page <form action=""...
or
i.e. be direct <form action="the-php-page.php"...
<?php
if(isset($_POST['slj'])){
$sql43 = "UPDATE `notifications` SET `seen`='1' WHERE `touser`='$myid' ";
if(mysqli_query($con, $sql43)){
echo "updated";
}
else
{
echo "Error updating record: " . mysqli_error($con);
}
}
?>
<span>
<form action="" method="POST">
<input type="submit" name="slj" value="Seen" style="background: rgba(255,255,255, 0); ">
</form>
</span><br>
REGARDS
<center>
<form method="POST">
<input type="submit" name="slj" value="Seen" style="background: rgba(255,255,255, 0); ">
</form>
</center>
<?php
$jepse = $_POST['slj'];
if(isset($jepse)){
echo "Working fine";
}
?>
Let mw know whether this code return "Working fine" or not
Related
I updated the question.
Since the last code was pretty complex and even after fixing the stuff it didn't work, I executed the below simple code to check if things work. Even this code doesn't work. Whenever I click on the submit button, it again returns a 404 error.
Yes, I placed the PHP code in the body as well to check if this work but it doesn't.
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<html>
<head>
<title>Echo results!</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
</body>
</html>
Try giving the button_create as name of the submit button
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
if(isset($_POST['button_create'])) {
<td><input type="submit" name="button_create" id="button_create" value="Create Table!"></td>
change these lines see how you go from there
There are a couple of things wrong here, method should be POST instead of GET. The name attribute of text fields should be used when receiving the values. The submit button name should be used to check whether the button is clicked or not. See the example given below.
<?php
if (isset($_POST['submit'])) {
$ex1 = $_POST['ex1'];
$ex2 = $_POST['ex2'];
echo $ex1 . " " . $ex2;
}
?>
<form action="" method="post">
Ex1 value: <input name="ex1" type="text" />
Ex2 value: <input name="ex2" type="text" />
<input name="submit" type="submit" />
</form>
Echo results!
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
this is for your updated question
<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
hello i have problems sending an id in a form.
the structure of the site is:
session_start();
if (!isset($_SESSION['a'])){
...create the session from some variables...
$_SESSION['a'] = $var;
$var = $_SESSION['a'];
}else{
$var = $_SESSION['a'];
if (isset($_POST["one"]) ){
echo "post one was send";
}
if (isset($_POST["two"]) ){
echo "post en was send";
}
echo "session already exists.";
}
the form where it will be send is placed at the end of the page and will be embedded into html by an excluded php:
echo '...
<ul class="drop_down">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="one" name="one" value="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="two" name="two" value="two"><div>set two</div>
</form>
</ul>
...';
so the strange about that is, that the form not seems to be send because the first part of the code works as it should do just the else part does not work when sending the form. it just will be displayed the echo text below the conditions for post-method.
so if there is someone who could tell how i can solve this i really would apreciate.
thanks alot.
UPDATE:
okay, using the request-method without action makes echo out the message. i thought it will work.
now the problem is, that when i will send the post the session should have been changed. this is not the case and i have no clue why this is not working.
so the original code is like that:
if (isset($_POST["tr"]) ){
$_SESSION['a'] = "tr";
echo "post tr was send and session has changed to tr";
}
If you have a forms like this
<form method="post">
<input type="submit" value="Submit Form" name="formA">
</form>
<form method="post">
<input type="submit" value="Submit Form" name="formB">
</form>
Then you can check like this
if (isset($_REQUEST['formA']) ...
elseif (isset($_REQUEST['formB']) ...
<div class = 'buttons'>
<button type="submit" class="regular" name="save">
<img src="elephant.png" alt=""/>
Memory
</button>
</div>
This is the code for a submit button
however when i try validate the form using php, the button does not seem to be submitting
<?php if( isset($_POST['save']) && $_POST['save'])
{
$submit = $_POST['save'];
echo "lol";
}
else
{
echo "lola";
}
Submit buttons only work in forms. Try to wrap the whole thing in a form tag and try again.
Your submit button doesn't have any value to send when posting the form. The <button> element does not send its element's content as its submit value. You still have to add a value attribute to the element in order for it to have a submitted value. Since you don't, it's sending an empty string, which is causing your conditional statement to fail:
if( isset($_POST['save']) && $_POST['save'])
Since $_POST['save'] is empty, that second part returns false and thus it goes to your else block.
Here is the code that you want:
<form name="myForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="buttons">
<button type="submit" class="regular" name="save" value="Save">
<img src="elephant.png" alt="Elephant" />
Memory
</button>
</div>
</form>
As written already your code lacks the wrapping. While submit button as a button might work without the form, then catching the _POST data surely doesnt.
Also, your solution for image-button could be better, maybe something like this:
<style type="text/css">
input[type="submit"] {background: url('elephant.png') right no-repeat; padding: 10px; padding-left: 30px; font-size: 14px; font-weight: bold;} /* or call this .regular */
</style>
<?
if ($_POST['save']) { // the trigger
echo '<h1>Cooking with fire now!</h1>';
}
?>
<form method="POST" action="">
<div class="buttons">
<input type="submit" name="save" value="Memory" class="regular" />
</div>
</form>
Note that class = "buttons" with the spaces, is incorrect syntax!
You should include your code within <form method="post" action="path/to/your/php/processing/file"> and </form> tags
Replace your button code with <input type="submit" class="regular" name="save" />
Remove isset($_POST['save']) && part from condition of if as you don't have set value for your button.
I have a little problem. I want to reload my page after submitting a form.
<form method="post" action="">
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input type="submit" value=" Update " id="update_button" class="update_button"/>
</form>
only use
echo "<meta http-equiv='refresh' content='0'>";
right after insert query before }
example
if(isset($_POST['submit']))
{
SQL QUERY----
echo "<meta http-equiv='refresh' content='0'>";
}
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action -->
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" -->
</form>
on your full page, you could have this
<?php
// check if the form was submitted
if ($_POST['submit_button']) {
// this means the submit button was clicked, and the form has refreshed the page
// to access the content in text area, you would do this
$a = $_POST['update'];
// now $a contains the data from the textarea, so you can do whatever with it
// this will echo the data on the page
echo $a;
}
else {
// form not submitted, so show the form
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action -->
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" -->
</form>
<?php
} // end "else" loop
?>
If you want the form to be submitted on the same page then remove the action from the form attributes.
<form method="POST" name="myform">
<!-- Your HTML code Here -->
</form>
However, If you want to reload the page or redirect the page after submitting the form from another file then you call this function in php and it will redirect the page in 0 seconds. Also, You can use the header if you want to, just make sure you don't have any content before using the header
function page_redirect($location)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';
exit;
}
// I want the page to go to google.
// page_redirect("http://www.google.com")
LOL, I'm just wondering why no one had idea about the PHP header function:
header("Refresh: 0"); // here 0 is in seconds
I use this, so user is not prompt to resubmit data if he refresh the page.
See Refresh a page using PHP for more details
You can maybe use :
<form method="post" action=" " onSubmit="window.location.reload()">
<form method="post" action="">
<table>
<tr><td><input name="Submit" type="submit" value="refresh"></td></tr>
</table>
</form>
<?php
if(isset($_POST['Submit']))
{
header("Location: http://yourpagehere.com");
}
?>
action attribute in <form method="post" action="action="""> should be just action=""
You want a form that self submits? Then you just leave the "action" parameter blank.
like:
<form method="post" action="" />
If you want to process the form with this page, then make sure that you have some mechanism in the form or session data to test whether it was properly submitted and to ensure you're not trying to process the empty form.
You might want another mechanism to decide if the form was filled out and submitted but is invalid. I usually use a hidden input field that matches a session variable to decide whether the user has clicked submit or just loaded the page for the first time. By giving a unique value each time and setting the session data to the same value, you can also avoid duplicate submissions if the user clicks submit twice.
//insert this php code, at the end after your closing html tag.
<?php
//setting connection to database
$con = mysqli_connect("localhost","your-username","your-
passowrd","your-dbname");
if(isset($_POST['submit_button'])){
$txt_area = $_POST['update'];
$Our_query= "INSERT INTO your-table-name (field1name, field2name)
VALUES ('abc','def')"; // values should match data
// type to field names
$insert_query = mysqli_query($con, $Our_query);
if($insert_query){
echo "<script>window.open('form.php','_self') </script>";
// supposing form.php is where you have created this form
}
} //if statement close
?>
Hope this helps.