Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm busy with a webpage to make it possible to reply a question. I have 2 pages in written in PHP.
results.php: a while loop that fetchs all rows from the database incl. their id's. Each question has its own id.
<li>Answer this question: </li>
reply.php: this shows a question according its id, but I don't want to show the id in the $_POST like: reply.php?id=1. I have tried to hide the id, through put it in the session but that doesn't work.
Can someone help me out?
<?php
if(isset($_POST['answer']))
{
$id = $_GET['id'];
/*
Each id that belongs to its question needs to changed when you click on another link it has to be looped.
Each time when we click on the answer link, we get the same id constantly but that is not our purpose.
I tried to give in the results.php file to give the id together with the url to avoid SQL Injections.
I placed the ids out of loops and placed it in session. Only the $_SESSION['vid'] stays the same even if I click on another answer link.
*/
}
<Form methode="POST"></form>
will stop showing the ?id=1. but you won't get infomation out of url with $GET[''] anymore.You need to use $_GET[''] to get the infomation out of the url. You can try to use a php rewrite rule to rewrite the url, so it won't show the id anymore.
$_POST[""] will not show any information in the URL. Although in your case if you want to post data from your database on the same page (as example a blog) you should be using $_GET[""].
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have am currently working on a web shop. The website has a small basket in the top right that shows the current price of all the products in the basket. It shows the correct number, however only updates the number after a refresh of the page, or after you navigate to another place on the website.
I have a file called basket.php which correctly calculates the sum of the products and puts it in a variable called $sum. There is also a file called tinybasket.php, which is only for showing the small basket in the top right.
Basket.php uses this code:
$_SESSION['sum'] = $sum;
tinybasket.php has this code:
echo $_SESSION['sum']
How do i update the tinybasket in the top right, without the user having to refresh or navigate to another page?
You need Javascript to go on. Because PHP is rendering your tinybasket.php into HTML code which means in browser there is no PHP variable it is the only text.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have just built a responsive HTML5 page, and as such, it links to other parts of the page from the menu... so, I have #home, #about, etc. I also need to pass a php variable for language, so that the correct language displays on the page, so I have lang=es, lang=gb, etc.
The languages are working fine and the links are working fine, but when I combine them both, the links stop working. Either as #about?lang=es or as index.php#about?lang=es. Neither works. It just stays at the top of the page and doesn't jump.
Any clues as to why?
Thanks in advance.
Kirsty
You should pass the php params first and then html tag ID
see the example below
https://domain.extension?lang=es#about
Dont worry about php variable value, it will remain untouched, servers will handle it
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Am undoubtedly a fresher on the web programming stuff but I got this problem that I got to fix. Hoping you guys help me out.
Alright, am trying to display rows from the My SQL database into a div using the while loop. But when I want to alert the i d of each result using j Query, it shows me only the i d of the first displayed data.
...
var post_id = $('#hide').prop(value);
alert(post_id);
...
Now, on clicking the submit button. It alerts the i d of the first displayed data from My SQL. Please what am I missing or need to add to fix this.
It is because you are using id and id works for a single element. For more then one occurrence try class instead, like:
PHP:
for($results as $result)
{
echo '<li class="link">'.$result.'</li>';
}
JS:
$('.link').click(function(){
var post = $(this).html(); // here you can use val(), id() also depends on your code
alert(post); // you will get data for the li on which you click
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to create a news system.
I'm implementing the ability to edit the news.
But there is a problem, if i change the picture the system sends the change to mysql. but If you change only the text, as the title or description but not edit the image changes are not updated to databse.
if not change the image, the change does not come. because the variable "file" is empty.
Code:
form: http://ideone.com/e62q84
action: http://ideone.com/q3noFc
see above url for my code.
there is a way to continue entering data even if the user chooses to leave the variable "file" empty?
This is happened because may be you check like if(isset($_POST['file'])) so change this to any required filed i.e. if(isset($_POST['title'])) or you can check with button also like if(isset($_POST['submit'])). Hope this help to you. If your issue is different then please add your code so we can identify the bug with your code.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
In my page I have a bunch of instances where (using php) I have links sending to the same page with query strings (?action=x) so that when it sends to the same page at the beginning of the page it will see that _GET[action] isset and perform the desired action.
FOR EXAMPLE: Say you want to allow a user to delete a comment made at the end of one of their posts (on a blog). The way I learned to do it is to make the delete button a link to "currentpage.php?action=delete". Clicking the button will in a sense refresh the page where the page will see that _GET[action]=="delete" and run the code to delete the comment.
Is this the best way to do this? Is there not a way to make a click of a button cause code to run (in php) without having to refresh the page?
In addition to causing the user to lose their place in the page, there are certain cases when I won't know the actual page url and need to reference it (like if you have a "comments" function in a file that's required on each page so that you don't have to use the code to display the comments on every single page that has comments). So, I'd need a way to reference the current page in the link since I won't know it ahead of time. Is there a way to do that?
I apologize for not being clear enough earlier. Is this any better?
Take a look at the $_SERVER superglobal. It contains all the information you'll need about the current request, to reconstruct it.
echo '<pre>';
print_r($_SERVER);
echo '</pre>';