04/02/1014:16:51 1florist-e.php<?phpecho "DEBUG: Program started.<BR />";// Connect to the database.$db_server = mysql_connect("orion.csl.mtu.edu", "nilufer", "nilufer");// Check the result of the connection.if ($db_server) echo "DEBUG: Connected to database successfully.<BR />";else die ("Unable to connect to MySQL: " . mysql_error());// Select the database to work with. mysql_select_db("nilufer", $db_server) or die("Unable to select database: " . mysql_error());// ----------- NEW -----------//// Change <form action="florist-d.php" method="post">// to <form action="florist-e.php" method="post">// below//if (isset($_POST[’hdelete’]) ){ $dcompanyid = get_post(’hid’); echo "DEBUG: Will try to delete: " . $dcompanyid . "<BR />"; $query = "DELETE FROM florists WHERE CompanyId = ’$dcompanyid’"; echo "DEBUG: Query is: " . $query . "<BR />"; if (!mysql_query($query, $db_server)) echo "DELETE FAILED:" . $query. "<BR />" . mysql_error() . "<BR /><BR />";}// ----------- END -----------// Issue a query to the database: retrieve all the records (rows).// This is the string form of the query as you would type it to mysql.$query = "SELECT * FROM florists";04/02/1014:16:51 2florist-e.php// Submit the query and get the result.$result = mysql_query ($query);// Check if the command executed successfully.if (!$result) die ("Database access failed:" . mysql_error());// Get the number of rows (records).$rows = mysql_num_rows($result);// Print the number of rows.echo "DEBUG: There are " . $rows . " records in the database.<BR />";// Print each record in a loop.// Each field in a record can be accessed as an array.for ($j = 0 ; $j < $rows ; ++$j){ $row = mysql_fetch_row($result); echo <<<_END<pre> ID $row[0] Name $row[1] Address $row[2] City $row[3] Zipcode $row[4] Phone $row[5] Starting price $row[6]</pre><form action="florist-e.php" method="post"><input type="hidden" name="hdelete" value="yes" /><input type="hidden" name="hid" value="$row[0]" /><input type="submit" value = "Delete record" /> </form>_END;}// Close the connection. mysql_close($db_server);// This is a function for later (forms).function get_post($var){ return
View Full Document