Forum Moderators: coopster

Message Too Old, No Replies

modify form

Small problem...help the noob:)

         

transmutated

4:35 am on Jul 8, 2005 (gmt 0)

10+ Year Member


Simple problem...I just cant find a resource of information. Alright, here it is...

I have a web page with the contents of a database dumped onto it with a link next to each of the rows. I want the link to modify the data. Each link is unique to that rows id number. Now, the problem is when the link is clicked, my information doesnt send over to the modify form link.

Alright, my theory on it all...I am almost certain that the the problem is in the first few lines of code.

if (isset($_POST['submit']))

How do I change that to grab the rows id number from the URL. I know what I currently have is for a submit button...please help.

maxi million

6:20 am on Jul 8, 2005 (gmt 0)

10+ Year Member



welcome to WebmasterWorld.com

if you are sending the info over thru the link, in the script you are modifying you ud need to use $_GET in place of $_POST to retrieve the data from the url

example

the link is:
/modify.php?id=2

in modify.php you should have:
if(isset($_GET['id']))
{
//modify the row where the row_id=$_GET['id'];
}
of course another alternative ud be to use $_REQUEST['id'] here instead of $_GET['id']

the way i remember this is
GET from the URL
POST from the form
REQUEST from everywhere!

hope this helps
:)

transmutated

8:13 pm on Jul 9, 2005 (gmt 0)

10+ Year Member



Hmmm, still having problems. I tried replacing $_POST['submit'] with $_GET['rowID']. Heres my modify.php:

include "mysql.class.php";
if (isset($_GET['rowID'])) {
$rowID = $_GET['rowID'];
$mysqldb = new mysql("localhost","yada","yada","hr");
$mysqldb->connect();
$mysqldb->select();
$query = "SELECT first, last, id, dept FROM employee WHERE rowID='$rowID'";
$result = mysql_query($query);
list($first,$last,$id,$dept) = mysql_fetch_row($result);
include "modifyform.php";
include "mysql.class.php";

}

Theres a problem in there somewhere becuase it isnt including my modifyform.php. Here that is:

if (isset($_POST['submit'])) {
$rowID = $_POST['rowID'];
$first = $_POST['first'];
$last = $_POST['last'];
$id = $_POST['id'];
$dept = $_POST['dept'];

$mysqldb = new mysql("localhost","yada","yada","hr");
$mysqldb->connect();
$mysqldb->select();
$query = "UPDATE employee SET first='$first', last='$last', id='$id', dept='$dept' WHERE rowID='$rowID'";
$result = mysql_query($query);
include "mysql.class.php";

if ($result)
echo "<p>The product has been successfully updated.</p>";
else
echo "<p>There was a problem updating the product.</p>";
}

The form information is:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="rowID" value="<?php echo $rowID;?>">

}

Sorry for all of the code. This is just mind numbing. This is my first attempt at PHP. I just cant see where I'm going wrong.