PDA

View Full Version : image upload location to db



wolfdogg
10-27-2006, 06:03 PM
whats wrong with this following picture?

Do i need an UPDATE , INSERT, include a WHERE statement?

what i am trying to do is have a session variable called $productid_session_variable passed to this page from an original record insert page where the bulk of the product is inserted, then to this page on submit, where it shoudl grab teh sessin, and use it to place the image URL location relative to the upload directory/ into the right row..

the datbase column is called 'image_file_1'

I have 3 opinions on the way this should work here, let me post these 3 atleast, and maybe someone can tell me whice one is full proper, or atleast half-proper:lol: .

heres the initial product insert page where the product information is uploaded just before its handed off to the image upload/insert page.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "veh_entry")) {
$insertSQL = sprintf("INSERT INTO product (description, price, `year`, make, model, miles, email, phone, phone_alt, cntct_name, terms, registration_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW() )",
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['price'], "int"),
GetSQLValueString($_POST['year'], "text"),
GetSQLValueString($_POST['make'], "text"),
GetSQLValueString($_POST['model'], "text"),
GetSQLValueString($_POST['mileage'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['pphone'], "text"),
GetSQLValueString($_POST['aphone'], "text"),
GetSQLValueString($_POST['cname'], "text"),
GetSQLValueString($_POST['terms'], "text"));

mysql_select_db($database_db, $dbc);
$Result1 = mysql_query($insertSQL, $dbc) or die(mysql_error());

$insertGoTo = "http://root/main/vehicle/template.php?page=add_img1";
if (isset($_SERVER['QUERY_STRING']))
{
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
//header(sprintf("Location: %s", $insertGoTo));
header("Location: $insertGoTo");

}

$_SESSION['$productid_session_variable'] = mysql_insert_id($dbc); // get last id on an insert query

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "veh_entry")) {
$insertSQL = sprintf("INSERT INTO product_category (product_id,category_id) VALUES ($productid_session_variable,%s)",
GetSQLValueString($_POST['category'], "int"));

mysql_select_db($database_db, $dbc);
$Result1 = mysql_query($insertSQL, $dbc) or die(mysql_error());
}

mysql_select_db($database_db, $dbc);
$query_rs_prod_cat = "SELECT category_id FROM product_category";
$rs_prod_cat = mysql_query($query_rs_prod_cat, $dbc) or die(mysql_error());
$row_rs_prod_cat = mysql_fetch_assoc($rs_prod_cat);
$totalRows_rs_prod_cat = mysql_num_rows($rs_prod_cat);

mysql_select_db($database_db, $dbc);
$query_rs_shop_product = "SELECT * FROM product";
$rs_shop_product = mysql_query($query_rs_shop_product, $dbc) or die(mysql_error());
$row_rs_shop_product = mysql_fetch_assoc($rs_shop_product);
$totalRows_rs_shop_product = mysql_num_rows($rs_shop_product);

and heres the 3 choices i came up with for the 2nd web page, the one that the product insert is handed off to for an addition of an image, and carries its session with it;

$_SESSION['$productid_session_variable'] = mysql_insert_id($dbc); // get last id on an insert query

$query = "UPDATE product (image_file_1) VALUES ('$filename') WHERE 'product_id' = $productid_session_variable LIMIT 1";

mysql_select_db($database_db, $dbc);
$result = mysql_query($query, $dbc) or die(mysql_error()); //run the query
if (my_affected_rows() ==1)
Choice 2 on teh query(THE INSERT plus a WHERE)

$query = "INSERT INTO product (image_file_1) VALUES ('$filename') WHERE 'product_id' = $productid_session_variable LIMIT 1";
and the 3rd option is(THE INSERT minus the WHERE)

$query = "INSERT INTO product (product_id, image_file_1) VALUES ('$productid_session_variable', '$filename') LIMIT 1";

ok, i switched this portion of the code around a bit, i improvised and found that the SESION variable was probably sitting in the wrong place,
so i moved it down a bit if i remember correctly, and then i created a variable for the session to call it inside VALUE() because calling the session like this VALUE($_Session['this_session'] was not working,

so it woudl seem that the session was never active,

heres what i have now

$_SESSION['productid_session_variable'] = mysql_insert_id($dbc); // get last id on an insert query
$productid_var= $_SESSION['productid_session_variable'];

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "veh_entry"))
{
$insertSQL = sprintf("INSERT INTO product_category ('product_id', 'category_id') VALUES ($productid_session_variable, %s)",
GetSQLValueString($_POST['category'], "int"));

mysql_select_db($database_dbc, $dbc);
$Result1 = mysql_query($insertSQL, $dbc) or die(mysql_error());



$insertGoTo = "http://rootdomain.com/main/vehicle/template.php?page=add_img1";
if (isset($_SERVER['QUERY_STRING']))
{
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
//header(sprintf("Location: %s", $insertGoTo));
header("Location: $insertGoTo");
}

\
can somebody help me figure out which one of the 3 options i can use for the query? or another if you have one better?
T.I.A.(thanks in advance)

wolfdogg
11-02-2006, 06:54 PM
this is a real great forum, no replies? whats up wtih that?