spires Posted July 15, 2006 Share Posted July 15, 2006 Hi, Does anyone know how to send muliple values through a link?I can send idbut i also want to send the name and description.to send the id i am using [code]<A HREF="edit.php?id='.$row['id'].'" class="link">Edit</a>[/code]And $_GET['id']; on the page it goes to.How can i add the other values to this line of code? :D Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/ Share on other sites More sharing options...
hvle Posted July 15, 2006 Share Posted July 15, 2006 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 &[code]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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58504 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58505 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 Hi, thanks for you help. I cant seem to get it to work. I have used [code]<a href="edit.php?id='.$row['id'].'&name='.$row['name'].'&description='.$row['description'].'" class="link">Edit</a>[/code]on the main page and:[code]if (isset($_GET['id'])) { $name = $_GET['name']; $id=$_GET['description']; }[/code]Could you pleade tell me what i'm doing wrong?You can test it out your self. Goto [url=http://www.spirestest.com/nicky/gallery/select_edit.php]http://www.spirestest.com/nicky/gallery/select_edit.php[/url]Thank for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58508 Share on other sites More sharing options...
hvle Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58511 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 Hisorry, 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[code]<?phpinclude('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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58514 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58516 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 Hi Heres a sample link [url=http://www.spirestest.com/nicky/gallery/select_edit.php]http://www.spirestest.com/nicky/gallery/select_edit.php[/url]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? Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58519 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Here, i'll post the code a bit redone and you can tell me if it works. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58522 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 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. [url=http://www.spirestest.com/nicky/gallery/select_edit.php]http://www.spirestest.com/nicky/gallery/select_edit.php[/url]Any more ideas?[code]<?phpinclude('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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58526 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Instead of relying on links to edit the name and description, pull it out of the database.[code]<?phpinclude("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.'; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58527 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 WOW, it works. What was i doing wrong? :D Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58529 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 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_OYou 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. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58531 Share on other sites More sharing options...
spires Posted July 15, 2006 Author Share Posted July 15, 2006 ok. thanks for your help/ ;D :D Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58544 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Anytime, dear. Quote Link to comment https://forums.phpfreaks.com/topic/14677-sending-multiple-values-through-a-link/#findComment-58546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.