In the "Rating" fieldset, I want to choose which sites my menu shows, whether it be my general links, mature links, or links to all.
I do have these links listed in a MySQL database, including a boolean value telling whether or not I consider them "Mature"
In the "New Site" fieldset, I want to be able to enter new sites, their keywords, URLS, Titles, and whether or not they are "mature" into my database. How do I do this with PHP?
In y
// make database connection
if(!@mysql_connect($mysql['hostname'], $mysql['username'], $mysql['password']))
{
exit('<strong>An unknown MySQL error has occurred: </strong><br /><pre>' . mysql_errno() . ' / ' . mysql_error());
}
// make database selection
if(!@mysql_select_db($mysql['database_name']))
{
exit('<strong>An unknown MySQL error has occurred: </strong><br /><pre>' . mysql_errno() . ' / ' . mysql_error());
}
// loop through post variable data
foreach($_POST as $key => $value)
{
// if invalid variable name, discard
if(!array_key_exists($key, $form))
{
continue;
}
// if variable value empty, trigger error
if(empty($_POST[$key]))
{
$error .= 'You must enter a ' . ucwords(str_replace('_', ' ', $key)) . '.<br />';
continue;
}
// if variable value length exceeds maximum length, trigger error
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 variable key is rating
if($key = 'rating')
{
// if invalid rating passed, trigger error
if(!in_array($_POST[$key], $ratings))
{
$error .= 'Invalid Rating passed';
continue;
}
// if rating is not mature, set as bool false, else, set as bool true
if($_POST[$key] != 'Mature')
{
$_POST[$key] = false;
}
else
{
$_POST[$key] = true;
}
}
// else, escape data
else
{
$_POST[$key] = @mysql_real_escape_string($_POST[$key]);
}
}
//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());
}
//Set up the variables here
$nl="\n";
$keyword = $_GET['keyword'];
$result = mysql_query("SELECT * FROM Links WHERE Keywords LIKE ('%$keyword%')") or die(mysql_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>';
}
Your database may not contain a reference to 'rating', it could be 'ratings' for example. They only way you will know for sure is to get the structure of that table that your expecting to find 'rating' in.
If the reference does not exist, you could always modify the database to add in another field.
//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());
}
//Set up the variables here
$nl="\n";
$keyword = $_GET['keyword'];
$result = mysql_query("SELECT * FROM Links WHERE Keywords LIKE ('%$keyword%')") or die(mysql_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>';
}
Bookmarks