Hello,
Forgive me if this turns out to be a stupid mistake, which it most likely will, but I am quite new to PHP and so can't see the problem.
I have created a couple of scripts, (actually borrowed to learn with), that allows me to create and maintain an FAQ section. I have created the DB with the appropriate permissions and populated it with a couple of dummy records. The faq.php script reads the records from the DB and populated the HTML table fine. BUT, when I try to add an faq back to the database with the following script, it does not work, nor do I receive any error messages. I suspect that it must be something to do with the way I am registering the globals but I am not sure. I am using mysql 3.23.51 and PHP 4.2.2 on a RH 7.3 box. Here is the script:
<?
// form not yet submitted
// display initial form
$slug = $POST['slug'];
$content = $POST['content'];
$contact = $POST['contact'];
if (!$submit)
{
?>
<table cellspacing="5" cellpadding="5">
<form action="<? echo $SERVER[$PHP_SELF] ?>" method="POST">
<tr>
<td valign="top"><b><font size="-1">Slug</font></b></td>
<td><input size="50" maxlength="250" type="text" name="slug"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Content</font></b></td>
<td><textarea name="content" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td valign="top"><font size="-1">Contact person</font></td>
<td><input size="50" maxlength="250" type="text" name="contact"></td>
</tr>
<tr>
<td colspan=2><input type="Submit" name="submit" value="Add FAQ"></td>
</tr>
</form>
</table>
<?
}
else
{
// includes
include("../conf.php");
include("../functions.php");
// set up error list array
$errorList = array();
$count = 0;
// validate text input fields
if (!$slug) { $errorList[$count] = "Invalid entry: Slug"; $count++; }
if (!$content) { $errorList[$count] = "Invalid entry: Content"; $count++; }
// set default value for contact person
if (!$contact) { $contact = $def_contact; }
// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "INSERT INTO faq (slug, content, contact, timestamp) VALUES ('$slug', '$content', '$contact', NOW())";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// print result
echo "<font size=-1>Update successful. <a href=http://www.easyonline.ca/admin/faq.edit.php>Go back to the main menu</a>.</font>";
// close database connection
mysql_close($connection);
}
else
{
// errors found
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>
Does it make a difference where in the script I register the globals?
Any help would sincerely be appreciated.
Cheers,
filch