Copy link to clipboard
Copied
hi,
everytime i add the insert record to an existing form the redirect does not work.
no errors on server when i turn error reports on.
all it does is add a ? to the page currently on.
the code generated by dw is:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "AddSupplier")) {
$insertSQL = sprintf("INSERT INTO suppliers (SupplierName, SupplierTel, SupplierEmail) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['PartsManufacturer'], "text"),
GetSQLValueString($_POST['PartsManufacturerTel'], "text"),
GetSQLValueString($_POST['PartsManufacturerEmail'], "text"));
mysql_select_db($database_cbank, $cbank);
$Result1 = mysql_query($insertSQL, $cbank) or die(mysql_error());
$insertGoTo = "supplier_Results.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
the form code is:
<form action="" method="post" class="clear" name="AddSupplier" id="AddSupplier" >
<ol>
<li style="">
<label for="PartsManufacturer">Parts Manufacturer Name</label>
<input type="text" id="PartsManufacturer" name="PartsManufacturer" value=""/>
</li>
<li>
<label for="PartsManufacturerTel">Parts Manufacturer Tel</label>
<input type="text" id="PartsManufacturerTel" name="PartsManufacturerTel" value="" />
</li>
<li>
<label for="PartsManufacturerEmail">Parts Manufacturer Email</label>
<input type="text" id="PartsManufacturerEmail" name="PartsManufacturerEmail" value="<?" />
</li>
</ol>
<input name="DummyName" type="hidden" value="1" />
<p style="text-align:right;">
<input type="reset" value="CANCEL" />
<input type="submit" name="OK" id="OK" value="OK" />
</p>
<input type="hidden" name="MM_insert" value="AddSupplier" />
</form>
using dw cs4.
any help appreciated.
many thanks
Copy link to clipboard
Copied
Check this against your original you will see that your code was not communicating with your form.
You can not INSERT INTO suppliers (SupplierName, SupplierTel, SupplierEmail
GetSQLValueString($_POST['PartsManufacturer'], "text"),
GetSQLValueString($_POST['PartsManufacturerTel'], "text"),
GetSQLValueString($_POST['PartsManufacturerEmail']));
because the name are completely different ie SupplierName does not = PartsManufacturer etc.
you may need to make a few changes depending on the name of your database and the field names.
So you may need to do the following EX: INSERT INTO YourTable (Your field Name for name, Your field Name for Tel, Your field Name for Email) VALUES (%s, %s, %s,)",
GetSQLValueString($_POST['Your field Name for name'], "text"),
GetSQLValueString($_POST['Your field Name for Tel'], "text"),
GetSQLValueString($_POST['Your field Name for Email'], "text"));
Make sure the names match exactly i.e. case sensitive, and make sure that those names correspond to all the other areas of the code and the form.
Hope you get it working,
_________________________________________________________________________________________________________________
<?php require_once('yourDBFile/yourDBFolder.php'); ?>
<?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;
}
}
$colname_getSupplier = "-1";
if (isset($_GET['user_id'])) {
$colname_getUser = $_GET['user_id'];
}
mysql_select_db($database_cbank, $cbank);
$query_getSupplier = sprintf("SELECT suppliers_id, SupplierName, SupplierTel, SupplierEmail FROM suppliers WHERE suppliers_id = %s", GetSQLValueString($colname_getSupplier, "int"));
$getSupplier = mysql_query($query_getSupplier, $cbank) or die(mysql_error());
$row_getSupplier = mysql_fetch_assoc($getSupplier);
$totalRows_getSupplier = mysql_num_rows($getSupplier);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "AddSupplier")) {
$insertSQL = sprintf("INSERT INTO suppliers (SupplierName, SupplierTel, SupplierEmail) VALUES (%s, %s, %s,)",
GetSQLValueString($_POST['SupplierName'], "text"),
GetSQLValueString($_POST['SupplierTel'], "text"),
GetSQLValueString($_POST['SupplierEmail'], "text"));
mysql_select_db($database_cbank, $cbank);
$Result1 = mysql_query($insertSQL, $cbank) or die(mysql_error());
$insertGoTo = "supplier_Results.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>Add new user</title>
<style type="text/css">
body {
background-color:#FFF;
color:#000;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
margin:0;
padding:0;
}
label {
margin:5px 20px 0 -155px;
width:200px;
float:left;
font-size:14px;
}
input[type="submit"] {
margin-left:15px;
display:inline;
}
input[type="reset"] {
margin-left:15px;
display:inline;
}
h1 {
font-family:Tahoma, Geneva, sans-serif;
}
h1, form {
margin-left:50px;
}
form {
width:500px;
}
form p {
margin:0 0 10px 155px;
}
legend {
font-weight:bold;
}
</style>
</head>
<body>
<h1>Add New Suppliers</h1>
<form id="AddSupplier" name="AddSupplier" method="POST" action="<?php echo $editFormAction; ?>">
<fieldset>
<legend>Suppliers details</legend>
<p>
<label for="SupplierName">Parts Manufacturer Name:</label>
<input type="text" name="SupplierName" id="SupplierName" />
</p>
<p>
<label for="SupplierTel">Parts Manufacturer Tel:</label>
<input type="text" name="SupplierTel" id="SupplierTel" />
</p>
<p>
<label for="SupplierEmail">Parts Manufacturer Email:</label>
<input type="text" name="SupplierEmail" id="SupplierEmail" />
</p>
<p>
<input type="reset" name="cansel" id="cancel" value="CANCEL!" />
<input type="submit" name="add_Supplier" id="add_Supplier" value="Add Supplier!" />
</p>
</fieldset>
<input type="hidden" name="MM_insert" value="AddSupplier" />
</form>
</body>
</html>
<?php
mysql_free_result($getSupplier);
?>
Copy link to clipboard
Copied
Silken_thread wrote:
Check this against your original you will see that your code was not communicating with your form.
You can not INSERT INTO suppliers (SupplierName, SupplierTel, SupplierEmail
GetSQLValueString($_POST['PartsManufacturer'], "text"),
GetSQLValueString($_POST['PartsManufacturerTel'], "text"),
GetSQLValueString($_POST['PartsManufacturerEmail']));because the name are completely different ie SupplierName does not = PartsManufacturer etc.
That's not relevant. The names in the form don't need to be the same as the column names in the database. In fact, it's sometimes recommended to use different names as a security measure, because anyone can see the names used in a form and try to break into the database with that information.
The original poster's form fields match correctly with the values in the $_POST array, so the problem lies elsewhere.
Copy link to clipboard
Copied
deansy55 wrote:
everytime i add the insert record to an existing form the redirect does not work.
The first question that needs to be asked is whether the values are inserted correctly in the database.
This might just be a typo in the copying of your code, but there's a stray <? in the value attribute in the following section:
<li> <label for="PartsManufacturerEmail">Parts Manufacturer Email</label>
<input type="text" id="PartsManufacturerEmail" name="PartsManufacturerEmail" value="<?" />
</li>
If that's not what's causing the problem, take a look at the following article that I wrote some time ago about pages failing to redirect: http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more