Jump to content

does php know which link was clicked ?


jd2007

Recommended Posts

<?php
$db=mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db(database);
for ($id=1; $id<some code; $id++) {
$query="SELECT name, worked, notworked, romno FROM games WHERE id='$id'";
$result=mysql_query($query); 
$row = mysql_fetch_row($result);
$total=$row[2]+$row[3];
echo "<span class=''><pre>  $row[1] <a href='deletegames.php'>[x]</a> <a href='editgames.php'>[-]</a>     $row[4]    This link worked for $row[2] out of $total people.  DID THIS LINK WORK FOR YOU ?</pre></span>";
echo "<br>";
}
?>

 

the above lists all games which is in a database (in admin view)... the x link is used to delete a game and [-] edit is used to edit a game...what i want now is...if admin clicks delete for a particular game...deletegames.php sends a query to database and deletes that game ? will php know for which game the delete link was clicked ? if it doesn't know, what to do ?   

Link to comment
Share on other sites

Yes. You pass a variable in the URL string. Fore example:

 

<a href="yourpage.php?yourvar=somevalue&foo=bar&id=5">your link</a>

 

yourpage.php:

<?php
$yourvar = $_GET['yourvar'];//contains somevalue
$foo = $_GET['foo']; //contains bar
$id = $_GET['id'];//contains 5;
?>

 

As you can see, you separate the differant variables in the URL with an ampersand(&)

 

 

Link to comment
Share on other sites

thanks !

this is code for worked.php:

<?php
$id = $_GET["var"];
$db=mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("ndsrom");

$query="SELECT worked FROM games WHERE id='$id'";
$result=mysql_query($query); 
$a = mysql_fetch_row($result);
$a[0]++;
$query2="UPDATE games SET worked = '$a[0]'
WHERE id = '$id'";
$result2=mysql_query($query2);
if ($result2)
{
include("index.php");

}
else
{
include("index.php");

} 
?>

 

u see when index.php is displayed , on the url on the address bar still displayed, so when anyone hits refresh, it repeats worked.php which i don't want...i only want worked.php to execute when a user clicks yes...

Link to comment
Share on other sites

Im not really sure if this is exactly what your question is, since im a little confused by that. However, when you are adding to a field in the database, there is no need to retreive the value first. You can do:

 

<?php
mysql_query("UPDATE `games` SET `worked` = `worked` + '1' WHERE id = '$id'") or die(mysql_error());
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.