like in my other post:
http://www.phpbuilder.com/board/showthread.php?threadid=10248607
i was helped by cgraz with the error i got. now what i want to do is using a loop, create a link for each data entry into the sql made that links back to the same page but specifies an id to be edited.
as a result of this i need the function's to be dynamic being wrote as:
function $id() {
here is the error that i got:
Parse error: parse error, expecting `T_STRING' in /home/user3/public_html/dir2/dir11/edit2sql.php on line 38
and here is the code:
<?
require ("../../cgi-bin/connect2test.php");
# processed when form is submitted back onto itself
if ($REQUEST_METHOD=="POST") {
# setup SQL statement
$SQL = " UPDATE sqlxml SET";
$SQL = $SQL . " name = '$name', ";
$SQL = $SQL . " description = '$description' ";
$SQL = $SQL . " WHERE id = '$id' ";
# execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);
# check for errors
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
echo ("<P><B>Data Entry Updated</B></P>\n");
} else { # display edit form (not post method)
# setup SQL statement to retrieve link that we want to edit
$SQL = " SELECT * FROM sqlxml ";
$SQL = $SQL . " WHERE id = '$id' ";
# execute SQL statement
$ret = mysql_db_query($db,"$SQL",$cid) or die(mysql_error());
$row = mysql_fetch_array($ret);
$name = $row["name"];
$id = $row["id"];
$description = $row["description"];
echo "Please chooae a data entry to edit:<br>";
# create url link for each data entry
while ($row = mysql_fetch_array($ret)) {
echo "<a href='$PHP_SELF&id=$id'>Edit Data Entry id: $id. With the Name: $name</a>";
# LINE BELOW THIS = LINE 38
function $id() {
# form here
print "<FORM NAME='edit2sql' ACTION='edit2sql.php' METHOD='POST'>
<INPUT TYPE='hidden' NAME='id' VALUE='$id'><TABLE>
<TR><TD><B>Name:</B> </TD><TD><INPUT TYPE='text' NAME='name' VALUE='$name' SIZE=40></TD></TR>
<TR><TD VALIGN=TOP><B>Description: </B> </TD><TD> <TEXTAREA NAME='description' ROWS=5 COLS=40>$description</TEXTAREA></TD></TR>
<TR><TH COLSPAN=2><P><INPUT TYPE='submit' VALUE='Update Data'></P></TH></TR>
</TABLE></FORM>";
}
}
}
mysql_close($cid);
# loop multiple switches for functions
switch($_REQUEST['id']){
while ($row = mysql_fetch_array($ret)) {
case "$id":
$id();
break;
}
}
?>