I'm working on a site for coupons and I need to set up a form where the user would enter in a store name and category.
Here's the problem. I have 3 tables:
Store
store_id, store_name
category
category_id, category_name
store_category
store_id, category_id
In the form I need to submit the store_id (which does it automatically with auto_increment already), store name to the Store table.
The store_category table needs to be updated as well but must draw the new store_id generated automatically.
I'm not much of a programer. Using Dreamweaver for this project. Any help would be much appreciated.
Thanx.
Ron
PS This is the code that dreamweaver generated:
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Store (store_id, store_name) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['store_id'], "int"),
GetSQLValueString($HTTP_POST_VARS['store_name'], "text"));
mysql_select_db($database_couponshedconn, $couponshedconn);
$Result1 = mysql_query($insertSQL, $couponshedconn) or die(mysql_error());
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Store, (store_id, store_name) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['store_id'], "int"),
GetSQLValueString($HTTP_POST_VARS['store_name'], "text"));
mysql_select_db($database_couponshedconn, $couponshedconn);
$Result1 = mysql_query($insertSQL, $couponshedconn) or die(mysql_error());
}
mysql_select_db($database_couponshedconn, $couponshedconn);
$query_Recordset1 = "SELECT * FROM Store";
$Recordset1 = mysql_query($query_Recordset1, $couponshedconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_couponshedconn, $couponshedconn);
$query_Recordset2 = "SELECT * FROM Category";
$Recordset2 = mysql_query($query_Recordset2, $couponshedconn) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
mysql_select_db($database_couponshedconn, $couponshedconn);
$query_Recordset3 = "SELECT * FROM store_category";
$Recordset3 = mysql_query($query_Recordset3, $couponshedconn) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);
?>