jwwceo Posted August 28, 2006 Share Posted August 28, 2006 First off, this board is awesome. Thanks for all the help...I have a simple question....how can I make a link act like a form control. For example, i want to delete an item from the database, but instead of using a submit button, I'd like to just have a text link that says delete that does the same thing. JW Quote Link to comment Share on other sites More sharing options...
Stuie_b Posted August 28, 2006 Share Posted August 28, 2006 You could build the link in the way the form would pass the data,for example if your form was too pass the field id too a file called del.php then you could build the link like thisdel.php?id=idoftheentrythen the del.php file would get the variable of id and then delete the database entry as it would if a form passed the data.hope it helpsStuie Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 [code]<a href="delete.php?id=27">delete</a>[/code]And in delete.php[code]<?php$id = $_GET['id']; // get record # to delete.....[/code]That should point the way. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 28, 2006 Share Posted August 28, 2006 [b]edited[/b]user with the id below can know update and delete and edit all.links.[code]<?php session_start();//id example$id="0123432";echo"<a href='function.php?id=$id&cmd=delete'>delete</a>":echo"<a href='function.php?id=$id&cmd=update'>update</a>":echo"<a href='function.php?id=$id&cmd=edit'>edit</a>":?>[/code]function.php[code]<?php sesion_start();if($_GET['cmd']=='delete'){delete query where id='$id'";}elseif($_GET['cmd']=='update'){update query set xxx where id='$id'";}elseif($_GET['cmd']=="edit"){update query set xxx where id='$id'";}else{//if the user goes to the function page with no link redirect to your main page.header("location: index.php");}?>[/code] Quote Link to comment Share on other sites More sharing options...
jwwceo Posted August 28, 2006 Author Share Posted August 28, 2006 I got the delete one done...the update is a little trickier for me....what if you don't know what you value is gonna be until the link is clicked...For example, I have a text box where users can update a field...usually I would just use the sumbit button and _get to find out what they typed...but there is no submit button or method=get...theres just a text link that says update.... Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 Same basic concept - make the link to your update.php and pass the record ID that's being updated. Quote Link to comment Share on other sites More sharing options...
jwwceo Posted August 28, 2006 Author Share Posted August 28, 2006 Sorry if this sounds naive. I 'm a total newbie...but how you get the value of whatever they typed into the text box if they haven't submitted it yet.....under this design there is no additional update.php page...it needs to be updated from the link alone...Ive attached my code to see if this makes it<?phpinclude 'library/config.php';include 'library/opendb.php';error_reporting(0);$color_id = $_GET['color_id'];if($_GET['cmd']=='delete'){$query = "DELETE from colors WHERE color_id='$color_id'";$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);}// [b][color=red][font=Verdana]THIS IS WHERE I'M CONFUSED[/font][/color][/b]//if($_GET['cmd']=='update'){////$query="UPDATE colors SET color='$color', WHERE color ='$color_id'";//$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);//}if(isset($_POST['submitcolor'])) { $color=$_POST['color']; $query="INSERT INTO colors (color) VALUES ('$color')"; $result = mysql_query($query) or die("Eror: ". mysql_error(). " with query ". $query); }elseif (isset($_POST['submitkeyword'])) { $keyword=$_POST['keyword']; $query="INSERT INTO keywords (keyword) VALUES ('$keyword')"; $result = mysql_query($query) or die("Eror: ". mysql_error(). " with query ". $query); echo " <p>Your keyword has been added!</p>";}echo "<form method='post' action='addcf.php']'><TABLE><TR> <TD><INPUT TYPE='text' NAME='color' class='cartForm' size=30></TD> <td><INPUT TYPE='submit' name='submitcolor' class='cartForm' value='Add this Color' size='30'></td></TR><TR> <TD><INPUT TYPE='TEXT' NAME='keyword' class='cartForm' size=30></TD> <td><INPUT TYPE='submit' name='submitkeyword' class='cartForm' value='Add this Keyword' size='30'></td></TR><tr><td colspan='2'><hr></td></tr><tr><td colspan='2'><table><tr><td><table><tr><td colspan='3' align='center' width=150><b>COLORS</b></td></tr>";$data = mysql_query('SELECT * FROM colors') or die(mysql_error());$info = mysql_fetch_array( $data );while($info = mysql_fetch_array( $data )) {echo"<form><tr><td><input type=text class='cartForm' value='".$info['color']."' size='15'></td><td><a href='addcf.php?color_id=".$info['color_id']."&cmd=update'>Edit</a></td><td><a href='addcf.php?color_id=".$info['color_id']."&cmd=delete'>Delete</a></td></tr></form>";}echo"</table></td></tr></table></tr></TABLE></form>";?></body></html> Quote Link to comment 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.