Jump to content


Photo

Another simple one....


  • Please log in to reply
6 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 12:41 AM

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

#2 Stuie_b

Stuie_b
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationNewcastle, UK

Posted 28 August 2006 - 12:45 AM

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
It's all in the manual :D

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 12:45 AM

<a href="delete.php?id=27">delete</a>

And in delete.php

<?php
$id = $_GET['id']; // get record # to delete
.....

That should point the way.

Legend has it that reading the manual never killed anyone.
My site

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 August 2006 - 12:50 AM

edited


user with the id below can know update and delete and edit all.

links.
<?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>":
?>

function.php
<?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");

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 01:24 AM

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





#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 01:31 AM

Same basic concept - make the link to your update.php and pass the record ID that's being updated.
Legend has it that reading the manual never killed anyone.
My site

#7 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 01:42 AM

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);

}

// THIS IS WHERE I'M CONFUSED
//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>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users