Hi,
posting to this forum for the first time, so bare with me.
I'm having trouble getting the script described here to work. This is what I've got:
1 php page with a form, collecting data (working)
1 php page with a pulldown menu for deleting desired row (working)
1 php page with a pulldown menu for choosing desired row (working)
1 php page with a form for editing chosen row (not working)
Here's the function for the pulldown menu where the user chooses which row to edit:
function show1() {
$name=$_POST['name'];
if ($name == "") {
$name = $_GET['name'];
$pop = $_GET['pop'];
$terr = $_GET['terr'];
$org = $_GET['org'];
}
$sql2="select * from country_des where name='$name'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);
if ($no==0) {
echo "The description of '$name' has not been found in the database";
} else {
echo "The description of '$name' ";
}
}
Here's the function I'm using for the page that does not work:
function update() {
$name = $_POST['name'];
if ($name == "") {
$name = $_GET['name'];
$pop = $_GET['pop'];
$terr = $_GET['terr'];
$org = $_GET['org'];
}
$sql2="select * from country_des where name='$name'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);
if ($no==0) {
echo "no such thing";
} else {
echo "<table><tr>";
}
while($resultline = mysql_fetch_array($result2)){
echo "<form action='?page==submit' method=post>";
echo "Short Country Description"<br/>;
echo "Country:";
echo "<input type=text name=newname value=";
echo $resultline ['name' ];
echo ">";
echo "<br/>Population (millions):";
echo "<input type=text name=newpop value=";
echo $resultline ['pop' ];
echo ">";
echo "<br/>Territory (sq km):";
echo "<input type=text name=newterr value=";
echo $resultline ['terr' ];
echo ">";
echo "<br/>Organisation:
echo "<input type=text name=neworg value=";
echo $resultline ['org' ];
echo ">";
echo "<input type=submit name=submit value=Save>";
echo "</form>";
}
if($page=="submit"){
$sql = "update country_des set
name='$newname',pop='$newpop',terr='$newterr',org='$neworg' where name='name'";
$result = mysql_query($sql) or die('insert fails');
echo "The data has been saved";
}
}
When submit is pressed I get the error message
"The description of '$name' has not been found in the database";
which comes from the first function. (Of course with the name inserted instead of '$name'.)
And nothing happens: the row is not edited and when chosen from the pulldown menu again it is found.
Can anyone see where the fault is? Thanks in advance.