Cant find error in code
Max Resnikoff Sep 13, 2014 3:21 PMThis code adds to the database, but it wont redirect me back to the inventory page.
I have set it to in the server behaviours but it doesnt want to redirect.
Here is my page code:
<?php require_once('Connections/drama_database.php'); ?>
<title>Add New Book</title>
<?php error_reporting(0);
ini_set('display_errors', 0);
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "bookadd")) {
$insertSQL = sprintf("INSERT INTO books (title, author, `description`, topic, location, lc) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['author'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['topic'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['labelcode'], "int"));
mysql_select_db($database_drama_database, $drama_database);
$Result1 = mysql_query($insertSQL, $drama_database) or die(mysql_error());
$insertGoTo = "bookinventory.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_drama_database, $drama_database);
$query_bookadd = "SELECT * FROM books";
$bookadd = mysql_query($query_bookadd, $drama_database) or die(mysql_error());
$row_bookadd = mysql_fetch_assoc($bookadd);
$totalRows_bookadd = mysql_num_rows($bookadd);
session_start();?>
<!--HEADER CONTENT START -->
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryTooltip.js" type="text/javascript"></script>
<style type="text/css">
bookinv {
font-size: 10px;
}
</style>
<link href="SpryAssets/SpryTooltip.css" rel="stylesheet" type="text/css" />
<head>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
</html>
<style type="text/css">
body{ margin:0px; background:#FFF;}
.header {
height:165px;
background:#FFF;
border:1px solid#CCC;
position:fixed;
width:100%;
top:0px;
}
#form1 table {
font-size: 9px;
}
#form1 table {
font-size: 10px;
}
#form1 table {
font-size: 12px;
}
#form1 table {
font-size: 14px;
}
.d {
font-size: 16px;
font-weight: bold;
}
.s {
font-size: 18px;
font-weight: bold;
}
</style>
</head>
<div class="header"><?php include('defaultheader.php');?></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<!--HEADER CONTENT END -->
<div align="center">
<h1>Add New Book</h1>
</div>
<div align="center">
<form action="<?php echo $editFormAction; ?>" id="bookadd" name="bookadd" method="POST">
<table width="417" border="0">
<tr>
<td width="93" class="formtag">Title</td>
<td width="314"><span id="sprytextfield1">
<label for="title"></label>
<input name="title" type="text" class="formfield" id="title" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td class="formtag">Author</td>
<td><span id="sprytextfield2">
<label for="author"></label>
<input name="author" type="text" class="formfield" id="author" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td class="formtag">Description</td>
<td><span id="sprytextfield3">
<label for="description"></label>
<textarea name="description" class="formfielddesc" id="description"></textarea>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td class="formtag">Topic</td>
<td><span id="sprytextfield4">
<label for="topic"></label>
<input name="topic" type="text" class="formfield" id="topic" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td class="formtag">Location</td>
<td><label for="location"></label>
<select name="location" class="formfield" id="location">
<!--Connection to Other Table-->
<option id="0">-- Select Location --</option>
<?php
require("Connections/drama_database.php");
$getallbooklocation = mysql_query("SELECT * FROM booklocation");
while($viewallbooklocation = mysql_fetch_array($getallbooklocation)){
?>
<option id="<?php echo $viewallbooklocation['id']; ?>"><?php echo $viewallbooklocation['location'] ?></option>
<?php } ?>
<!--Connection to Other Table-->
</select></td>
</tr>
<tr>
<td class="formtag">Label Code</td>
<td><span id="sprytextfield5">
<label for="labelcode"></label>
<input name="labelcode" type="text" class="formfield" id="labelcode" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td class="formtag"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input name="addbook" type="submit" class="button" id="addbook" value="Add Book" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="bookadd" />
</form>
</div>
<?php
mysql_free_result($bookadd);
?>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "integer");
</script>


