Hi Guys,
Can anyone help me with this passing variable problem?
At the moment i am trying to pass an $id value from one php page to a form which then gets inserted into the database.
The problem is that the value inserted into the database does not equal the value that it should, it always equals "0".
Here's what i've got so far.
On the php page that sends the variable to the edit.php page i have the following script:
PHP:-----------------------------------------
<br><a href="edit.php?CatParent=<?=$id?>">Add new category</a>
This all works fine, when you goto the edit.php page the url displays the correct CatParent $id.
This page contains a form. What i want to do is pass the correct $id value to the database when the form is submitted.
Here is my code for the edit.php page:
PHP:-----------------------------------------
<?
include ("include/header.inc.php");
?>
<h1>Edit / add categories</h1>
<?php
include("include/dbconnect.php");
if($submit){
$CatParent= "$id";
$sql = "insert into categories(CatParent, CatName)
values('$CatParent','$CatName')";
$result = mysql_query($sql);
if($result){
echo "<br>Information entered into database.\n";
}
else{
echo "<br><font color=\"red\"><b>ERROR:</b> Your data was not added to the database</font>\n";
}
}
else if($update){
$sql = "UPDATE $table SET CatID='$CatID',CatParent='$CatParent',CatName='$CatName' WHERE CatID=$CatID";
$result = mysql_query($sql);
if($result){
echo "<br>Information updated.\n";
}
else{
echo "<br><font color=\"red\"><b>ERROR:</b> Your data could not be updated</font>\n";
}
}
else if($id){
$result = mysql_query("SELECT * FROM $table WHERE CatID=$id",$db);
$myrow = mysql_fetch_array($result);
?>
<form method="post" action="edit.php">
<table width="380" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>
<input type="hidden" name="CatID" value="<?php echo $myrow["CatID"]?>">
<input type="hidden" name="CatParent" value="<?php echo $myrow["CatParent"]?>">
Category Name: </td>
<td>
<input type="Text" name="CatName" size="35" value="<?php echo $myrow["CatName"]?>">
</td>
</tr>
</table>
<input type="Submit" name="update" value="Update information">
</form>
<?
}
else
{
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="380" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>
<input type="hidden" name="active" value="yes">
Category Name: </td>
<td>
<input type="Text" name="CatName" size="35">
</td>
</tr>
</table>
<input type="Submit" name="submit" value="Enter information">
</form>
<?
}
?>
The $update form works fine, i just can't pass the correct $id for a new entry..... ie($submit)
Sorry for the long post but i am completly confused.
Cheers,
micmac