I'm trying to contruct a simple .php file that will all people to view, edit and add files...depending on the $action variable...IE: script.php?action=add

Here's the code I've got...I've got two problems...1: the add form won't work...it simply loads the original .php pages upon submission without sending the data to the DB...and 2: I'm trying to use an else-if command so that I can display a record from the DB in this format: script.php?action=view&id=1 - I can't quite get this to work...I have the command set like this:

else if ( $action == "view" && $ID == "$ID" ) {stuff here}

I'm aware of why this won't work, but can't figure out how to fix it...

Here's my code in full:

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
&lt;?php

// If the action is "view"...

if ( $action == "view" ) {

$db = @mysql_connect("localhost", "USERNAME", "PASSWORD");
if (!$db) {
echo( "&lt;p&gt;Unable to connect to the " .
"database server at this time.&lt;/p&gt;" );
}

mysql_select_db("mycodingdb",$db);
if (! @mysql_select_db("mycodingdb") ) {
echo( "&lt;p&gt;Unable to locate the " .
"database at this time.&lt;/p&gt;" );
}

$sql = "SELECT * FROM programmers";

// Perform the query

$result = mysql_query($sql,$db);
if (!$result) {
echo( "&lt;P&gt;Error performing query: " .
mysql_error() . "&lt;/P&gt;" );
}

while ($row = mysql_fetch_array($result)){

$ID = $row["ID"];

printf("&lt;b&gt;&lt;a href='http://www.mycoding.com/programmers.php?action=view&id=$ID'&gt;%s&lt;/a&gt;&lt;/b&gt; - %s years old" .
" - %s experience&lt;br&gt;%s" .
"&lt;br&gt;&lt;p&gt;\n", $row[1], $row[2], $row[3], $row[4]);
}
}


else if ( $action == "view" && $ID == "$ID" ) {

// Connect to and select the database

$db = @mysql_connect("localhost", "USERNAME", "PASSWORD");
if (!$db) {
echo( "&lt;p&gt;Unable to connect to the " .
"database server at this time.&lt;/p&gt;" );
exit();
}
mysql_select_db("mycodingdb",$db);
if (! @mysql_select_db("mycodingdb") ) {
echo( "&lt;p&gt;Unable to locate the " .
"database at this time.&lt;/p&gt;" );
exit();

}

// SQL query to retrieve all information
// associated with any entries in the
// database that have an ID equal to $id

$sql = "SELECT * FROM programmers " .
"WHERE ID=$id";

// Perform the query

$result = mysql_query($sql,$db);
if (!$result) {
echo( "&lt;P&gt;Error performing query: " .
mysql_error() . "&lt;/P&gt;" );
exit();
}

// Just in case there is more than one
// entry with the given ID, loop through
// "all of them" (there will usually only
// be one) so that only the values from
// the last one are retained.

while ($row = mysql_fetch_array($result)) {
$ID = $row["ID"];
$Name = $row["Name"];
$Age = $row["Age"];
$Experience = $row["Experience"];
$Languages = $row["Languages"];
$Comments = $row["Comments"];
}


// Print out the values

echo("&lt;b&gt;$Name&lt;/b&gt; - $Age years old - " .
"$Experience experience&lt;br&gt;" .
"&lt;b&gt;Languages: &lt;/b&gt;$Languages&lt;br&gt;" .
"&lt;b&gt;Comments: &lt;/b&gt;$Comments&lt;br&gt;&lt;p&gt;\n");
}


// If the action equals "add"...

else if ( $action == "add" ) {


?&gt;

&lt;form action="&lt;?php $PHP_SELF ?&gt;" method=post&gt;

Name: &lt;input type="Text" name="Name" size="30"&gt;&lt;br&gt;
Age: &lt;input type="Text" name="Age" size="2"&gt;&lt;br&gt;
Experience: &lt;input type="Text" name="Experience" value="in years" size="30"&gt;&lt;br&gt;
Languages: &lt;input type="Text" name="Languages" size="30"&gt;&lt;br&gt;
Comments: &lt;textarea name="Comments" rows="7" col="35"&gt;&lt;/textarea&gt;&lt;br&gt;
Phone: &lt;input type="Text" name="Phone" size="15"&gt;&lt;br&gt;
City: &lt;input type="Text" name="City" size="30"&gt;&lt;br&gt;
Country: &lt;input type="Text" name="Country" size="20"&gt;&lt;br&gt;
Date: &lt;input type="Text" name="Date" size="20"&gt;&lt;br&gt;

&lt;input type="submit" name="submit" value="Submit"&gt;
&lt;/form&gt;

&lt;?php

}


// If the action equals "edit"...

else if( $action == "edit" ) {

echo( "This is the edit page!");

}


// Else...

else {

echo( "Welcome to the Programmers For Hire database. Please make a selection:&lt;p&gt;
&lt;b&gt; --- &lt;a href='$PHP_SELF?action=view'&gt;View All Records&lt;/a&gt;&lt;/b&gt;&lt;br&gt;
&lt;b&gt; --- &lt;a href='$PHP_SELF?action=add'&gt;Add a Record&lt;/a&gt;&lt;/b&gt;&lt;br&gt;
&lt;b&gt; --- &lt;a href='$PHP_SELF?action=edit'&gt;Edit a Record&lt;/a&gt;&lt;/b&gt;&lt;br&gt;");

}

?&gt;
[/code]

Anyone know what's wrong?

Thanks.


------------------
Chris Bowyer
MyCoding.com: Join our mailing list for launch notification!
"I'm not an insomniac, I'm a web designer."