Next comes newauthor.php, which allows administrators to add new authors to the database. Again, this is just like adding new jokes, which we tackled in "Publishing MySQL Data on the Web".
<!-- newauthor.php --> <l> <head> <title> Add New Author </title> </head> <body> <?php if (isset($_POST['submit'])): // A new author has been entered // using the form below. $dbcnx = mysql_connect('localhost', 'root', 'mypasswd'); mysql_select_db('jokes'); $name = $_POST['name']; $email = $_POST['email']; $sql = "INSERT INTO Authors SET Name='$name', EMail='$email'"; if (@mysql_query($sql)) { echo('<p>New author added</p>'); } else { echo('<p>Error adding new author: ' . mysql_error() . '</p>'); } ?> <p><a href="'PHP_SELF']?>">Add another Author</a></p> <p><a href=">Return to Authors list</a></p> <?php else: // Allow the user to enter a new author ?> <form action="'PHP_SELF']?>" method="post"> <p>Enter the new author:<br /> Name: <input type="text" name="name" size="20" maxlength="255" /><br /> Email: <input type="text" name="email" size="20" maxlength="255" /><br /> <input type="submit" name="submit" value="SUBMIT" /></p> </form> <?php endif; ?> </body> <l>