By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

PHP or Javascript for this?

P: n/a

I'm wanting to create an hyperlink that will execute a mysql_query and
then refresh the current page if it's clicked on. I've similar things
created via javascript but didn't know if such was possible with PHP.

May 20 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You could do it like

---
<?

if (isset($_GET['q']) && $_GET['q']=='y')
{
mysql_query(...);
header("Location: ?");
}

echo "<a href='?q=y'>Execute Query</a>";

?>
---

However, using this technique all the GET-variables would be cleared.
Also, I personally would use two PHP-Files, if you don't need to use the
returned data from the query in the first script:

--- file1.php
<?

echo "<a href='query.php'>Execute Query</a>";

?>
--- file2.php
<?

mysql_query(...);
[Do sth.]
header("Location: file1.php");

?>
---

Akhenaten schrieb:
I'm wanting to create an hyperlink that will execute a mysql_query and
then refresh the current page if it's clicked on. I've similar things
created via javascript but didn't know if such was possible with PHP.
May 20 '07 #2

P: n/a
On May 20, 3:23 pm, Philipp Grassl <p.gra...@gmx.atwrote:
You could do it like

---
<?

if (isset($_GET['q']) && $_GET['q']=='y')
{
mysql_query(...);
header("Location: ?");

}

echo "<a href='?q=y'>Execute Query</a>";

?>
---

However, using this technique all the GET-variables would be cleared.
Also, I personally would use two PHP-Files, if you don't need to use the
returned data from the query in the first script:

The problem is I do need the return data. I guess a good example would
be something similar to a voting poll. If you haven't voted then the
"vote" img will be displayed. Clicking on it will execute a mysql
update. The page will then refresh with the vote results in place of
the vote image.

May 20 '07 #3

P: n/a
Akhenaten wrote:
On May 20, 3:23 pm, Philipp Grassl <p.gra...@gmx.atwrote:
>You could do it like

---
<?

if (isset($_GET['q']) && $_GET['q']=='y')
{
mysql_query(...);
header("Location: ?");

}

echo "<a href='?q=y'>Execute Query</a>";

?>
---

However, using this technique all the GET-variables would be cleared.
Also, I personally would use two PHP-Files, if you don't need to use the
returned data from the query in the first script:


The problem is I do need the return data. I guess a good example would
be something similar to a voting poll. If you haven't voted then the
"vote" img will be displayed. Clicking on it will execute a mysql
update. The page will then refresh with the vote results in place of
the vote image.
There are several ways you can do it. For instance, you can store the
$_GET variables in $_SESSION. You can add the variables when building
your "vote" link. You can put them as hidden fields in a form that is
submitted when they click on the link...

All kinds of things you can do. Which way is best is for you to decide.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 21 '07 #4

P: n/a
On May 21, 12:50 am, Akhenaten <jonko...@gmail.comwrote:
I'm wanting to create an hyperlink that will execute a mysql_query and
then refresh the current page if it's clicked on. I've similar things
created via javascript but didn't know if such was possible with PHP.
These all are long methods take a function for displaying image and
for sucessfull message

like:

if (isset($_GET['q']) && $_GET['q']=='y')
{
mysql_query(...);
display("message");
}
else
display();

function display($msg){
if(is_empty($msg){
then logic for displaying image
}else{
logic for displaying the sucessfull message.
}
}

make sure all the variables in the function should be global variables.

May 21 '07 #5

P: n/a
Ravi wrote:
On May 21, 12:50 am, Akhenaten <jonko...@gmail.comwrote:
>I'm wanting to create an hyperlink that will execute a mysql_query and
then refresh the current page if it's clicked on. I've similar things
created via javascript but didn't know if such was possible with PHP.

These all are long methods take a function for displaying image and
for sucessfull message

like:

if (isset($_GET['q']) && $_GET['q']=='y')
{
mysql_query(...);
display("message");
}
else
display();

function display($msg){
if(is_empty($msg){
then logic for displaying image
}else{
logic for displaying the sucessfull message.
}
}

make sure all the variables in the function should be global variables.
You should not use global variables. If you need a variable in a
function, you should pass it as a parameter.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 21 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.