Trying to pass variable in url - php

I'm echoing this form:
echo "<form action='/leaguemaster/fichaTorneio.php?id=" . $_GET['torneioid'] . "'>";
When I submit the form and it links to the page from the action, the variable I'm passing doesn't reach the page...
/leaguemaster/fichaTorneio.php?
I've done this in other pages and it worked, I don't know what's going on here. I've tried having the same form outside a PHP echo and I get the same result.
-EDIT-
This is the full form:
echo "<form method='GET' action='/leaguemaster/fichaTorneio.php?id= " . $_GET['torneioid'] . "'>";
echo "<input type='submit' value='Voltar'>";
echo "</form>";

Use hidden type form's element named id:
echo "<form action=\"/leaguemaster/fichaTorneio.php\">";
echo "<input type=\"hidden\" name=\"id\" value=\"$_GET[torneioid]\" />"
Notice: I did not set the method attribute to the form because the GET method is the default method for HTML forms and it makes the form submits its values through the URL query string.

Please try
// check $_GET['torneioid'] value
echo 'torneioid = ' . $_GET['torneioid'] . '<br />';
echo '<form action="/leaguemaster/fichaTorneio.php?id=' . $_GET['torneioid'] . '">';
And make sure the URL contains "http:// yourdomain.com/?torneioid=something"

There are several things that you should check:
$_GET['torneioid']
This indicates that you are attempting to resolve form or other variables through GET. Make sure that you are passing information through GET and not POST.
Also make sure there is something that is actually stored in torneioid, and that the form or database that you are 'GETting' from, actually holds a value.

Related

jQuery send data AJAX after the time is up

So, I have a form that has to be filled by the user in a duration. (Fyi, it's still a dummy web). Let's say the duration is 100sec. After 100sec, the data should be sent to database. Here are my codes :
HTML
<div id="countdown"></div>
<form class="test" method="post">
<?php
for($num=1;$num<=10;$num++){
echo "<div class=\"question\">" .$num. "<br>"; /* the question is written here */
echo "<input type=\"radio\" name=\"answer" .$num. "\" value=\"A\">A<br>";
echo "<input type=\"radio\" name=\"answer" .$num. "\" value=\"B\">B<br>";
echo "<input type=\"radio\" name=\"answer" .$num. "\" value=\"C\">C<br>";
}
?>
</form>
Why did I do PHP and looping? Coz this is the prototype of my form and also for shortening purpose. I'll not do this for the real web. But, if you think this is a bad idea although it's just a dummy web, just tell me :)
jQuery
var duration=100;
var countdown=setInterval(timer,1000);
function timer(){
duration=duration-1;
$("#countdown").html(duration+" sec");
if(duration<=0){
clearInterval(countdown);
var form_data=$(".test").serialize();
$.post("action.php",form_data,function(){alert("success!")});
}
}
action.php
<?php
include("connection.php"); /* it's the connection to the database */
$answer1=$_POST["answer1"];
$answer2=$_POST["answer2"];
$answer3=$_POST["answer3"];
$answer4=$_POST["answer4"];
$answer5=$_POST["answer5"];
$answer6=$_POST["answer6"];
$answer7=$_POST["answer7"];
$answer8=$_POST["answer8"];
$answer9=$_POST["answer9"];
$answer10=$_POST["answer10"];
mysqli_query($link,"INSERT INTO prototype (`answer1`,`answer2`,`answer3`,`answer4`,`answer5`,`answer6`,`answer7`,`answer8`,`answer9`,`answer10`) VALUES ('$answer1','$answer2','$answer3','$answer4','$answer5','$answer6','$answer7','$answer8','$answer9','$answer10')";
?>
So, the problem is : after the duration = 0, the success action (alert) appears, but after I checked the database, no data has been stored. Wut's actually happen?

Php - echoing an html textbox, setting the textbox's value to a variable: returns only up to the first space of the string

So within my php code: I'm trying to auto generate and populate a form that will edit a database.
$aName = "Wayne Gretzky";
echo "<form>";
echo "<input type='text' value=".$aName.">";
echo "<input type='Submit'>";
echo "</form>";
But when the code executes it shows a textbox with the value of "Wayne" rather than "Wayne Gretzky"
Because i want the form to be auto generated, so it can adapt to whatever data I may pull form the database; How do i call the variable or the result of a query so that the full string will be displayed in the textbox?
You need to put quotes on the value attribute as well, otherwise the browser does it for you and then you get what you got.
echo "<input type='text' value='" . $aName . "'>";
You are going wrong with the quotes.
If you are using double quotes outside, use single quotes inside for the html tags.
The correct code is
<?php
$aName = "Wayne Gretzky";
echo "<form>";
echo "<input type='text' value='$aName'>";
echo "<input type='Submit'>";
echo "</form>";
?>

Whole value is not passing from input field using POST PHP

I am facing problem to pass data from one page to another using POST method. I want to pass data from the input field name 'keyword' to another PHP page. But it is not passing the complete data but when i print this data in same page using the 'keyword_div' it is showing the complete data.
Div is showing only 10 words:
আয়,গুর,ছুটে,লগন,জীবন,বয়ে, আজ,যায়,করে,চাঁদের
These lines are for passing the data-
print "<input type='hidden' id='keyword' name='keyword' value=". implode(',', extractKeyWords($file)) .">";
Print "<div class='output' name='keyword_div' id='keyword_div'>Keywords: " . implode(',', extractKeyWords($file)) . "<div>";
These lines are for getting the data after form submission-
if (isset($_POST['keyword'])){
$val = $_POST['keyword'];
} echo $val;
But Input is passing 6 words only:
আয়,গুর,ছুটে,লগন,জীবন,বয়ে
Why I am not getting the whole value? Please help.
You need to put quotes around the value, because there's a space at the beginning of the 7th keyword and that's ending the value attribute.
print "<input type='hidden' id='keyword' name='keyword' value='". implode(',', extractKeyWords($file)) ."'>";
Good HTML style is to put quotes around all attribute values.
If you want to get rid of the whitespaces as well, call trim().
print "<input type='hidden' id='keyword' name='keyword' value='". implode(',', array_map('trim', extractKeyWords($file))) ."'>";

Input from PHP generated form is not being recorded

The issue I have been experiencing deals with input from HTML which was generated using PHP echo statements. Here is the function I have that outputs the form:
function confirm_recipients()
{
echo "<form action = ' ' name ='email_options' method='post'>";
echo "<input type='submit' name='sendRecipients' value='Yes, I want to send the emails' >";
echo "</form>";
}
Later on in the same PHP page, I call the function and then check to see if the submit button was set.
confirm_recipients();
if (isset($_POST['sendRecipients']))
{
//perform actions
}
However, this code is not functional seeing as even when the submit button is set (clicked by the user), the if statement block is never executed. Perhaps there is an issue with posting from the same file I want to "read in" from? Thanks for any advice.
Updates
Thank you for such immediate response. Sadly none of the suggestions have worked (removing the space in the action value or the suggestion made by user623952). No errors have been reported, the button is just failing to be set. I am looking for other places in the file that might have errors, perhaps in the order I call the function.
This works fine for me:
<?php
print "<pre>".print_r($_POST,true)."</pre>";
confirm_recipients();
function confirm_recipients() {
echo "<form action = ' ' name ='email_options' method='post'>";
echo "<input type='submit' name='sendRecipients' value='Yes, I want to send the emails' >";
echo "</form>";
}
if (isset($_POST['sendRecipients']))
{
print "<br/>sendRecipients is set!<br/>";
}
?>
I think your problem might be somewhere else in the code.
It's okay to POST the form data to the same script that contains the form. Change the action attribute to the URL of the script, do not set it to whitespace, which is what you did.
I don't think the value of a submit input is sent as part of the POST. Try using an input type="hidden" with the name 'sendRecipients'.

PHP Refresh button onclick

I have this while loop that echoes entries from a SQL database. I have an "Add to Cart" button which is supposed to remove the entry from the list and add it somewhere else. This part works, but once I click on the "Add to Cart" button, the entry is not removed right away, I have to manually refresh the page or visit another page and come back in order to see that the item is removed. I tried using the following (and few similar) lines on the onclick propery of the button, but it didn't work.
echo "<br /><center><input type='submit' name='submitAdd' value='Add to Cart' onclick='window.location.reload();'></center>";
Any suggestions are appreciated.
Thank you.
EDIT: This is the while loop that I use to generate the table. It is within a tag which is within the .
while ($row = mysql_fetch_array($song_query)) {
foreach ($_SESSION['selected_items'] as $key => $value) {
if ($value == $row['Item_ID']) {
$rowID = $row['Item_ID'];
echo "<tr style='background-color: #66FFFF;'>";
echo "<td><input type='checkbox' name='removeFromCart[]' value='$rowID'></td>";
echo "<td>" . $row['Item_ID'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Artist'] . "</td>";
echo "<td>" . $row['Album'] . "</td>";
echo "<td>" . $row['Time'] . "</td>";
echo "<td>" . $row['Year'] . "</td>";
echo "<td>" . $row['Bit_Rate'] . "</td>";
echo "<td>" . $row['Sample_Rate'] . "</td>";
echo "</tr>";
}
}
}
PHP is a server-side language, so any "actions" will be executed on the server, before the results are displayed to the user. In order to modify the page after it has been loaded on the user's browser, you have to use a client-side language, such as JavaScript. If you want to show an update to your cart without having to reload the page, then using an AJAX request is your best option. Check out the tutorial at http://www.w3schools.com/ajax/ and let me know if you have any questions about how to implement one :)
Update: Force Reload
If you want to just stick with reloading the page as is, try onclick='window.location.reload(true);' instead of onclick='window.location.reload();'. The true parameter forces a get request to the server. http://www.w3schools.com/jsref/met_loc_reload.asp
I use a link that references to the same page
Recargar
If the only feature you are looking for is to reload the page on the button's click, the way I typically do that is onclick="history.go(0)"
But if the form button is what's submitting a form and already reloads the page then I don't see why you couldn't put the while loop after your other code like this,
CHECK FOR FORM() {
UPDATE SQL DB
}
WHILE () {
OUTPUT DB DATA
}
not a button but a simple link, but maybe still useful for some:
<?php
$page = $_SERVER['PHP_SELF'];
print "Reload this page";
?>
Use header() function to refresh a web page in PHP. The PHP header() function sends an HTTP header to a client or browser in raw form.
Before HTML, XML, JSON or other output has been sent to a browser or client, a raw data is sent with the request (especially HTTP Request) made by the server as header information.
Syntax:
header ("header:url of the page")
I hope that this can place you on the right way.

Categories