Jump to content


Photo

sending multiple values through a link


  • Please log in to reply
14 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 02:28 PM

Hi,

Does anyone know how to send muliple values through a link?
I can send id
but i also want to send the name and description.

to send the id i am using
<A HREF="edit.php?id='.$row['id'].'" class="link">Edit</a>

And $_GET['id']; on the page it goes to.

How can i add the other values to this line of code?
:D


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 02:35 PM

yes, you can send as many as you wanted as long as your link is shorter than 1024 characters.
it however, need to separate by &

href="link.php?id=idvalue&name=namevalue&description=descriptionvalue"

so, a link would look like this:
<a href="link.php?id=idvalue&name=namevalue&description=descriptionvalue" class="link">edit</a>


Life's too short for arguing.

#3 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 02:41 PM

Yea, and then on the page you just process as many links as you have.
if (isset($_GET['var'])) {
  $var = $_GET['var'];
}

Just remember that sending links through the URL isn't very secure, and you should always validate $_GET variables as much as you can depending on the type of information you will recieve, because they would be very easy to use in a malicious manner. I usually use the is_numeric() function to check ID's.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 02:52 PM

Hi, thanks for you help.

I cant seem to get it to work.
I have used
<a href="edit.php?id='.$row['id'].'&name='.$row['name'].'&description='.$row['description'].'" class="link">Edit</a>

on the main page and:

if (isset($_GET['id'])) {
	    $name = $_GET['name'];
		$id=$_GET['description'];
		}

Could you pleade tell me what i'm doing wrong?

You can test it out your self.
Goto http://www.spirestes...select_edit.php

Thank for all your help.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#5 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 02:58 PM

you should follow pixy's practice, but for now, you can use these to test the code:

$id = $_GET['id'];
$name = $_GET['name'];
$description = $GET['description'];

put these in edit.php before printing out the values.
Life's too short for arguing.

#6 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 03:03 PM

Hi

sorry, No luck.
(what is pixy's practise?)


I know the $id is getting through, is just the other values.
this is the code for my edit page


<?php
include('db.php');
echo $id;
$arrErrors = array();

if (!empty($_POST['submit'])) {
	if ($_POST['description']=='') 
		$arrErrors['description'] = 'Description.';
	if ($_POST['name']=='') 
		$arrErrors['name'] = 'Name.';
	
	
	if (count($arrErrors) == 0) {
		
	$id = $_GET['id'];
	$name = $_GET['name'];
	$description = $_GET['description'];
		
		
		

		
		
		$result = mysql_query("UPDATE image SET description = '$description', name = '$name' WHERE  id = '$id' LIMIT 1") or die(mysql_error());
			if ($result) {
				$link_home = '<div class="error">Your details have been updated.<br><a href="select_edit.php" class="link">Return to edit list</a>.';
				
				} else {
					$UNtaken = '<div class="error">Sorry, Your details have not been updated.';
				}
				
				
		}  else {
			if (empty($title) || empty($art)) {
				$strError = '<div class="error">error';
       			foreach ($arrErrors as $error) {
           				 $strError .= "<li>$error</li>";
       			 }
       		 $strError .= '</div>';
			}
			
		
		
		}

}


		

?>


<html>
<head>
<title>New News</title>

<link href="../css/nicky.css" rel="stylesheet" type="text/css">
</head>

<body>

<center>
<a href="select_edit.php" class="link">back</a>
<table width="250px" bgcolor="#EEEEEE" class="TLRB_border">
<tr>
<td>
	<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
	<?php echo "<INPUT type='hidden' name='id' value='".$_POST['id']."'>"; ?>				
	<table width="190px" align="center" bgcolor="#FFFFFF">
	<tr>
		<td colspan="2">Edit News</td>
	</tr>
	<tr>
		<td class="loginBox_text">Name:</td>
	<td>
		<input name="name" Type="text" id="name" size="15" value="<?php echo $_POST['name']?>">
	</td>
	</tr>
	<tr>
		<td class="loginBox_text">Description:</td>
	<td>
		<textarea name="description" cols="30" wrap="PHYSICAL" id="description" value="<?php echo $_POST['description']?>"></textarea>	
	</td>
	</tr>
	<td colspan="2" align="right">
		<input type="submit" name="submit" value="Submit">
	</td>
	</table>
	</form>	
</td>
<tr>
<td>

<center>
<?php echo $strError; ?>
<?php echo $UNtaken; ?>
<?php echo $link_home; ?>
<?php echo $hitch; ?>
<?php echo $final; ?>
</center>



</td>
</tr>
</tr>
</table>

</center>

</body>
</html>

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#7 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 03:06 PM

Can you give us a sample link? Maybe it's going over the maximum number of characters.

Whenever you're using $_GET method to get variables, check that they're set first.
if (isset($_GET['id'])) {
    if (!is_numeric($_GET['id'])) {
        echo 'You are using an invalid id';
        // include footers
        die();
    }
    else {
        $is = $_GET['id'];
    }
}

That, of course, only works when you're doing numeric values, but it's the same principle.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#8 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 03:10 PM

Hi

Heres a sample link http://www.spirestes...select_edit.php
Then click on edit and edit the details.

Delete works fine.

i have echoed them out on the edit page. which means that they are getting through.

I just i cant seem to edit the details in the database?
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#9 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 03:13 PM

Here, i'll post the code a bit redone and you can tell me if it works.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#10 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 03:24 PM

OK, the values are now displaying inside the text feilds.

and when you click submit, it displays the new code in the top left hand corner. (as it should)

But, its not affecting the database.
http://www.spirestes...select_edit.php

Any more ideas?

<?php
include('db.php');
echo $id;
echo $name;
echo $description;

$arrErrors = array();

if (!empty($_POST['submit'])) {
	if ($_POST['description']=='') 
		$arrErrors['description'] = 'Description.';
	if ($_POST['name']=='') 
		$arrErrors['name'] = 'Name.';
	
	
	if (count($arrErrors) == 0) {
		
	$id = $_GET['id'];
	$name = $_GET['name'];
	$description = $_GET['description'];
		
		
		

		
		
		$result = mysql_query("UPDATE image SET description = '$description', name = '$name' WHERE  id = '$id' LIMIT 1") or die(mysql_error());
			if ($result) {
				$link_home = '<div class="error">Your details have been updated.<br><a href="select_edit.php" class="link">Return to edit list</a>.';
				
				} else {
					$UNtaken = '<div class="error">Sorry, Your details have not been updated.';
				}
				
				
		}  else {
			if (empty($title) || empty($art)) {
				$strError = '<div class="error">error';
       			foreach ($arrErrors as $error) {
           				 $strError .= "<li>$error</li>";
       			 }
       		 $strError .= '</div>';
			}
			
		
		
		}

}


		

?>


<html>
<head>
<title>New News</title>

<link href="../css/nicky.css" rel="stylesheet" type="text/css">
</head>

<body>

<center>
<a href="select_edit.php" class="link">back</a>
<table width="250px" bgcolor="#EEEEEE" class="TLRB_border">
<tr>
<td>
	<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
	<?php echo "<INPUT type='hidden' name='id' value='".$_POST['id']."'>"; ?>				
	<table width="190px" align="center" bgcolor="#FFFFFF">
	<tr>
		<td colspan="2">Edit News</td>
	</tr>
	<tr>
		<td class="loginBox_text">Name:</td>
	<td>
		<input name="name" Type="text" id="name" size="15" value="<?php echo $name; ?>">
	</td>
	</tr>
	<tr>
		<td class="loginBox_text">Description:</td>
	<td>
		<textarea name="description" cols="30" wrap="PHYSICAL" id="description" ><?php echo $description; ?></textarea>	
	</td>
	</tr>
	<td colspan="2" align="right">
		<input type="submit" name="submit" value="Submit">
	</td>
	</table>
	</form>	
</td>
<tr>
<td>

<center>
<?php echo $strError; ?>
<?php echo $UNtaken; ?>
<?php echo $link_home; ?>
<?php echo $hitch; ?>
<?php echo $final; ?>
</center>



</td>
</tr>
</tr>
</table>

</center>

</body>
</html>

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#11 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 03:27 PM

Instead of relying on links to edit the name and description, pull it out of the database.

<?php
include("db.php");
// I dont know what the echo $id is for...
if (isset($_GET['id'])) {
    if (!is_numeric($_GET['id'])) {
        die('You are trying to use an invalid link');
    }
    else {
        $id = $_GET['id'];
    }
}

if (isset($_POST['submitted'])) {
    $errors = array();
    if (empty($_POST['name'])) {
        $errors[] = 'You did not enter a name for the image.';
    }
    else {
        $name = $_POST['name'];
    }
    if (empty($_POST['desc'])) {
        $errors[] = 'You did not enter a description';
    }
    else {
         $desc = $_POST['desc'];
    }
    $id = $_POST['id'];
    if (empty($errors)) { // No errors, so update DB
        $query = "UPDATE image SET name='$name', description='$desc' WHERE id='$id'";
        $result = mysql_query($query);
        if ($query) {
             echo 'The image named '.$name.' was sucessfully updated.';
        }
        else {
             echo mysql_error();
        }
    }
    else {
         foreach ($errors as $msg) {
             echo '<li> '.$msg.'</li>'; 
         }
    }
}
else {
    $query = "SELECT name, description FROM image WHERE id='$id'";
    $result = mysql_query($query);
    if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result, MYSQL_NUM);
        echo '<form action="thisfile.php" method="post">
        <b>Name:</b> <input type="text" name="name" value="'.$row[0].'"><br>
        <b>Description:</b><br>
        <textarea name="desc">'.$row[1].'</textarea><br>
        <input type="submit" name="submit" value="Submit">
        <input type="hidden" name="id" value="'.$id.'">
        <input type="hidden" name="submitted" value="TRUE">
        </form>';
    }
    else {
        echo 'We could not select that from the database.';
    }
}
?>

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#12 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 03:35 PM

WOW, it works.

What was i doing wrong?

:D
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#13 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 03:38 PM

Just relying on $_GET too much. When I first started coding I thought that using the $_GET method looked cool so I tried to use it with EVERYTHING. O_O

You should consider actually spacing your code in a reasonable way. It looks like it's all just floating around in cyberspace--it makes it much easier to debug.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#14 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 15 July 2006 - 03:57 PM

ok.
thanks for your help/

;D :D
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#15 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 04:01 PM

Anytime, dear.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users