I'm trying to implement a Facebook connect button to my website.
It's working, but it's written in JavaScript and I'd like to insert the information into the database (the tutorial I used is linked below.)
I'm trying to redirect the users from the index.php to index.php?name=xxx.
The name value is rendered with JavaScript so I can't simply just set a PHP variable, can I?
I've been told it's possible with $_GET so that's what I'm trying to achieve.
Using location.href/replace, both redirect to the same page over and over again...
This is the tutorial I used.
I would like to store some information in the database, but I can't do it directly since it's JavaScript and not PHP.
Is there a solution/any other way?
check if the name parameter is filled or not, and if it is, do not redirect
Related
how can I send PHP parametres, get method like .php?id=xx
I am using K2 items with Joomla. Currently I am printing out all results fetched from database using PHP. When user clicks on one of the results it should send him to different page and that page should get id of the thing user clicked. How do I do it if joomla shows me sites like:
joomla.com/index.php/example-showing-this/
This is a very broad question, and we'd more details to better help you. On a broad level, you can generate these URLs using PHP and JRoute http://docs.joomla.org/JRoute/1.5
You may also find this thread helpful too https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-general/1548yu9I2jQ
When the user is able to click on things this is no longer PHP, this is HTML and javascript. PHP is executed on the server, the result of this execution is the HTML+CSS+Javascript that the user downloads to its pc.
From what you descrived you need to generate the correct HTML+javascript using the PHP variables you get from the database, for example:
echo "Click me";
This will display a link, but it will not pass any parameters, if you want to pass a id using GET you should do it like this:
$id=1234;
echo "Click me";
In the your_php_page.php you can receive this id like this:
$id=$_GET['id'];
//if you are going to use this in a query you should do something like this to prevent injection
$id=$mysqli->real_escape_string($id);
If you want to use POST, you will have to submit a form or use AJAX, but that's more advanced, you should focus on making it work using GET.
I currently have 2 pages:
Follow.php:a PHP page which is all setup with twitters api and will follow any user on twitter with the specific parameter you put in.
One index.php page, which has a list of links of people you can follow.
What I am looking to do is have it so when a user clicks on one of the people to follow on index.php, the variable in follow.php (which is used as a parameter and is the username of twitter account that is going to be followed) gets set to the name attribute of the link selected.
Now I am not the greatest developer, so I am not sure of the best way of doing this. There is probably a better way of doing it that what I am thinking of. I was thinking of using jquery to say something like:
$('a').click(function(){
<?php $group=?>$(this).attr('name'); //trying to set a php variable to name attr
})
This was going to be in its own new file,
then I was going to include this script into the follow.php script and use the variable. This is not working, unsurprisingly. I hope I explained what I was trying to do well.
So I have two questions.
Number 1:what is the best way of achieving what I am trying to do? can i do this all in php?
Number 2: is it possible to do what I was trying to do with jquery and setting the php var equal to the name attr?
PHP runs on the server. JavaScript (jQuery) runs on the browser. PHP can be used to write JS, but JS can't affect PHP (except via AJAX or similar).
What you need to do is do a POST on the Follow.php page and accept the username value. This is a great resource for that: http://www.html.net/tutorials/php/lesson10.php
You can simply set the link href for each tag on the index page to go got Follow.php?user=twitterHandle (where twitterHandle is the twitter username of a person). This way, you dont need to use any javascript at all.
I have a form that a user fills out, which submits information to my mysql database. On submission, my php code creates a url based on form data that was submitted and a unique ID. Rather than having a new webpage populate my web directory based off of the generated url, I would like to point that url to something similar to a "profile" page.
So my php creates a link after a user has submitted the form that looks like this: http://localhost/State=ALCity=SeattleEvent=eventSubject=titleID=135
This link gets stored inside my table along with the data that was submitted by the user. I've read that storing a url inside a table isn't practical, however for my purposes the table data will expire and get deleted within a certain amount of time.
In short, I'd like to be able to have a user click the link which will pull up data that was submitted. Can I grab data from the url to pull that information up for the user? Or will I need to change my setup that's already implemented? I can explain further if needed :)
If I get you right, this is a classic case for the mod_rewrite extension of Apache (since you mentioned .htaccess, I think you use Apache as webserver). With this mod, you can filter parts of the url and send it to your php script as normal $_GET parameters.
You will need something like this in your .htaccess (just out of my mind)
RewriteEngine on
RewriteRule ^State=([a-zA-Z0-9]+)=SeattleEvent=([a-zA-Z0-9]+)=titleID=([0-9]+)$ profile.php?state=$1&event=$2&id=$3
What this is actually doing, is that the Apache checks if the current requested url match the regular expression of this rule. If that is the case, it will call the profile.php and pass the "dynamic" part of the url as $_GET parameter (using the backreferences).
For further information, I recommence the official mod_rewrite documentation, the mod_rewrite guide and this nice tutorial.
I have a webpage with a form on it. The heading of the form is this:
<form name="sw" METHOD ="POST" ACTION="logger1.php">
After some event has happened, a javascript function submits the form like this:
document.forms["sw"].submit();
The php file logs the data from the form in a text file on the server, and then redirects the browser to another page. My issue is that I want to examine one of the values in the form from the previous page on the page that the browser is redirected to. I am completely lost. help!
Have you considered using sessions? The $_SESSION[] array might keep your previously posted variable between pages.
Basically all the form information is being passed to the "logger1.php" file in the POST method.
So you need to see what the code in the "logger1.php" file is and see exactly how the file is redirecting once it's done doing what it does.
Then you can possibly append the variable you want passed on to the redirect method in the GET method.
Lets say the variable you want to pass on is:
$_POST['Some_variable']
and the redirect method is something like:
header('Location: some_file.php');
then you can append it this way:
header('Location: some_file.php?variable_name='.$_POST['Some_variable']);
You can append ?info=hello to the end of the URL it redirects to, then retrieve it in PHP with $_GET['info']
You can't. The information is not passed when the browser is redirected so there is no way to access it.
I think the best way to do this would be to store the value in a database. If you are using ASP.NET the easiest way to do this would be to set up a SQL Server Express database. They are free until you go over 10GB.
Cant you put the variable that you want to look at as a get variable added to the url of the redirected page like so http://yourdomain/thepage.php?var=variable
I have a basic map and it is set up to take user (no need to sign up, just click and add details, then submit) input, it is just a plain text field. I know I need to set-up a php to store the new data as people enter it but I am a little lost. I searched but did not see an Q&A already, if it exists a redirect would be great. Thanks in advance!
Here is the page if you'de like to see the source, very basic. http://www.nextepisodepgh.org/worldartproject.html
Once the user has clicked on the button you need to do a post back of the form (either directly or indirectly via ajax) to your php page. Your php would simple just grabbed the get or post variable and save it to the database.