Hello!
I have three scripts that I want to use to enable a user to edit records in a database.
Script A - selection page:
<?php
include ('common_db.php');
$link_id = db_connect();
//-----------------------PULL UP DETAILS-----------------------------------------
$selectquery = "SELECT * FROM Table";
$result = mysql_query($selectquery)
or die("Invalid query: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td bgcolor="#FFFFFF" width="50%">
<?php echo "PAGE:"; echo $row['Name']; ?>
</td>
<td bgcolor="#FFFFFF" width="50%" align="right">
<p><a href="Edit.php?action=Page&id=<?php
echo $row['IDNumber']; ?>">[EDIT]</a>
</td>
</tr>
The user clicks the "EDIT" link which takes them to script B to make alterations:
<?php
include ('common_db.php');
$link_id = db_connect();
//--------------------------------------------------------------------------------------------------
//---THIS PULLS OUT THE CORRECT DB RECORD ACCORDING TO ID IN THE URL--
//--------------------------------------------------------------------------------------------------
$selectquery = "SELECT * FROM Table WHERE IDNumber = '" . $_GET['id'] . "'";
$result = mysql_query($selectquery) or die(mysql_error());
$row = mysql_fetch_array($result)
//---------------------------------------------------------
//PUT ID INTO A SESSION FOR LATER
//---------------------------------------------------------
$_SESSION['UserID'] =$_GET['id'];
?>
<form action="Process_Editpage.php" method ="post" enctype="multipart/form-data">
<p>Change name: <input type="text" name="Name" size="25" value=" <?php echo $row['Name']; ?>" /></p>
<p>Change Email: <input type="text" name="EmailAddress" size="25" value=" <?php echo $row['Email']; ?>" /></p>
<p>Upload new profile image: <input name="ImagePath" type="file" id="ImagePath" value="<?php echo $row['ImagePath']; ?>"/></p>
<p><input type="submit" value="submit" />
</form>
The user can alter the entries in the form fields, hits submit which takes them to Script C:
//-------------------------------------------------------------------
//SOME SCRIPT HERE HANDLES THE FILE UPLOAD
//-------------------------------------------------------------------
//---------------------------------------------------------------------
//SOME SCRIPT HERE GETS THE USER'S ID NUMBER(FOR INSERTING INTO DATABASE)
//-----------------------------------------------------------------------------------------
//--------------------------------------------------------------------------
//RETRIEVE POST VARIABLES
//--------------------------------------------------------------------------
$_SESSION['Name'] = $_POST['Name'];
$_SESSION['Email'] = $_POST['Email'];
$_SESSION['ImagePath'] = $_POST['ImagePath'];
$name = $_SESSION['Name'];
$email = $_SESSION['Email'];
$image = $_SESSION['ImagePath'];
//------------------------------------------------------------------------
//RECALL THE SESSION FOR USER'S ID, PUT INTO A VARIABLE
//---------------------------------------------------------------------------
$userid = $_SESSION['UserID'];
//----------------------------------------------------------------------
//INSERT ALL THE EDITED INFO INTO THE TABLE AND OVERWRITE EXISTING DATA
//----------------------------------------------------------------------
$insertquery = "INSERT into Table WHERE IDNumber = '$userid' (Name, Email, ImagePath) VALUES ('$name', '$email', '$image')";
$insertresult = mysql_query($insertquery, $link_id) or die (mysql_error());
$nrows = mysql_affected_rows();
if ($nrows != -1)
{
echo "Insert successful!";
}
else
{
echo "Insert unsuccessful!";
}
?>
However, I keep getting Undefined index error for 'id', so id info is not being passed.
Can any help?
How else could I pass the information across the scripts, so I can use $_GET['id'] to target the appropriate record to overwrite?
Cheers!