Hey Guys,
I'm successfully logged in and I've tested the account_type check and it works.
But my question is how do i set it up so It will only start the script when I hit Submit because when i go back to the link a second time it runs a query with nothing in it!!
Code:
<?php
session_start();
$type= $_SESSION['type'];
$pagetitle = $_POST['pagetitle'];
$pagebody = $_POST['pagebody'];
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) {
$var = nl2br(htmlspecialchars($var));
$var = eregi_replace("'", "'", $var);
$var = eregi_replace("`", "'", $var);
return $var;
}
$pagetitle = filterFunction($pagetitle);
// End Filter Function --------------------------------------------------------------
include_once "scripts/connect_to_mysql.php";
if ($type == 'b') {
// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO blogposts (title, pagebody, dateposted)
VALUES('$pagetitle','$pagebody',now())") or die (mysqli_error($myConnection));
echo '<b>Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a></b>';
exit();
} else {
echo '<b> Your not an admin.</b>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creating New Page</title>
<script type="text/javascript">
function validate_form ( ) {
valid = true;
if ( document.form.pagetitle.value == "" ) {
alert ( "Please enter the page title." );
valid = false;
} else if ( document.form.linklabel.value == "" ) {
alert ( "Please enter info for the link label." );
valid = false;
} else if ( document.form.pagebody.value == "" ) {
alert ( "Please enter some info into the page body." );
valid = false;
}
return valid;
}
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
}
-->
</style></head>
<body>
<table width="100%" border="0" cellpadding="8">
<tr>
<td><h3>Creating a New Blogpost</h3></td>
</tr>
<tr>
<td>Be sure to fill in all fields, they are all required.<br /></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="5">
<form id="form" name="form" method="post" action="create_blogpost.php" onsubmit="return validate_form ( );">
<tr>
<td width="12%" align="right" bgcolor="#F5E4A9">Title</td>
<td width="88%" bgcolor="#F5E4A9"><input name="pagetitle" type="text" id="pagetitle" size="80" maxlength="64" value="<?php echo $pagetitle; ?>" /></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#DAEAFA">Page Body</td>
<td bgcolor="#DAEAFA"><textarea name="pagebody" id="pagebody" cols="88" rows="16"><?php echo $pagebody; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Create this Blogpost now" /></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>