Jump to content

Another simple one....


jwwceo

Recommended Posts

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
Link to comment
Share on other sites

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 this

del.php?id=idoftheentry

then 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 helps

Stuie
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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....



Link to comment
Share on other sites

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

<?php

include '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>

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.