Here’ my form:
[code=html]
<form action=”./Pages/Homepage/submit.php” method=”post” id=”newsite”>
<fieldset>
<legend>NEW SITE</legend>
<ul>
<li><div><label>Site Title</label><input type=”text” class=”text” name=”site_title”></div></li>
<li><div><label>URL</label><input type=”text” class=”text” name=”url”></div></li>
<li><div><label>Keywords</label><input type=”text” class=”text” name=”keywords”></div></li>
<li><div><label>Mature</label><input type=”checkbox” class=”checkbox” name=”Mature”></div></li>
<li class=”center”><div><input type=”submit” value=”Submit” class=”submit”></div></li>
</ul>
</fieldset>
</form>
Here’s the PHP to go with it:
[code=php]
<?php
$mysql = array(
‘hostname’ => ‘localhost’,
‘username’ => ‘root’,
‘password’ => ”,
‘database_name’ => ‘Lynx’,
‘table_name’ => ‘links’
);
//Database Connection
if (!@mysql_connect($mysql[‘hostname’], $mysql[‘username’], $mysql[‘password’]))
{
exit(‘<strong>Connection mistake. The database is borked: </strong> <br> <pre>’ . mysql_errno() . ‘ / ‘ . mysql_error());
}
//Database selection
if (!@mysql_select_db($mysql[‘database_name’]))
{
exit(‘<strong>Database went a-borking: </strong> <br> <pre>’ . mysql_errno() . ‘ / ‘ . mysql_error());
}
$form = array(
‘Title’,
‘URL’,
‘Keywords’,
‘Mature’
);
$max_form_len = 255;
$error=”;
//Loop through the post variable data
foreach($_POST as $key => $value)
{
//if this variable is invalid, dump it
if(!array_key_exists($key, $form))
{
continue;
}
//If this variable is empty, squawk
if (empty($_POST[$key]))
{
$error .= ‘You must enter a ‘ . ucwords(str_replace(‘_’, ‘ ‘, $key)) . ‘.<br>’;
}
//If variable exceeds maximum length.
if (strlen($_POST[$key])>$max_form_len)
{
$error .= ‘Your ‘ . ucwords(str_replace(‘_’, ‘ ‘, $key)) . ‘ exceeds the maximum allowed length.’;
$error .= ‘Please limit your ‘ . ucwords(str_replace(‘_’, ‘ ‘, $key)) . ‘ to ‘ . $max_form_len. ‘ characters (current length: ‘ . strlen($_POST[$key]) . ‘).<br>’;
continue;
}
}
if (!empty($error))
{
exit($error);
}
$result = @mysql_query(<<<sql
INSERT INTO `{$mysql[‘table_name’]}` (Title, URL, Keywords, Mature)
VALUES(‘$rating’, ‘$site_title’, ‘$url’, ‘$keywords’)
sql
);
if(!$result)
{
exit(‘<strong>An unknown MySQL error has occurred: </strong><br /><pre>’ . mysql_errno() . ‘ / ‘ . mysql_error() . “nQuery: $result”);
}
exit(‘Site successfully added.’);
?>
When ever I use that form, I get a blank row in the mySQL database. Where am I going wrong?