boas, estou um pequeno grande problema lol
basicamente tenho um formulario de produtos onde tenho titutlo, resumo(caption), preço, quantidades, etc e claro imagem
se for so a imagem consigo, se for so os dados tambem consigo, agora os 2 nao consigo :S
aqui vai o meu codigo
basicamente tenho um formulario de produtos onde tenho titutlo, resumo(caption), preço, quantidades, etc e claro imagem
se for so a imagem consigo, se for so os dados tambem consigo, agora os 2 nao consigo :S
aqui vai o meu codigo
Código:
<?php
include $_SERVER['DOCUMENT_ROOT'].'/tfc/common.php';
include $_SERVER['DOCUMENT_ROOT'].'/tfc/includes/database.php';
error_reporting(E_ALL);
//quick admin session check
//initiate myheader function
//star switch
switch($_REQUEST['req'])
{
//modify category form
case "submit_product":
if(!$_POST['product_title'] || !$_POST['product_caption'] || !$_POST['long_description'] || !$_POST['product_price'] || !$_POST['product_qty'] || !$_FILES['product_image'])
{
echo '<p align=center>Missing form information!</p>'.
'<p align=center>Please use you browser back button and complete the form.</p>';
//corpo();
exit();
}
if ($_POST['MAX_FILE_SIZE'] >= $_FILES['product_image']['size'])
{
$photo = addslashes(fread(fopen($_FILES['product_image']['tmp_name'], "r"),$_FILES['product_image']['size']));
$query = sprintf("INSERT INTO shopping_products(cat_id, product_title, product_caption, long_description, product_price, product_qty, product_image, FileType) VALUES ('%s', '%s','%s','%s','%s','%s','%s','%s')", $photo, $_FILES['product_image']['type']);
// $sql=mysql_query("INSERT INTO shopping_products (cat_id, product_title, caption, long_description, product_price, product_qty, product_image) VALUES ('{$_POST['cat_id']}', '{$_POST['product_title']}', '{$_POST['caption']}', '{$_POST['long_description']}', '{$_POST['product_price']}', '{$_POST['product_qty']}', '$photo')");
//dado por main_affection
if(isset($_FILES["product_image"]) && (trim($_FILES["product_image"]["name"])!=""))
{
$directorioFinal="/TFC/admin/images/";
$nomeFinal=time().basename($_FILES["product_image"]["name"]);
if(move_uploaded_file($_FILES["product_image"]["tmp"],$directorioFinal . $nomeFinal))
{
echo "SUCESSO!";
}else{
echo "UPS... NÃO DEU!";
}
}
if (!$query)
{
echo "Error performing query:".mysql_error();
}else{
echo '<p align=center>Products Inserted!<br> ID number:'.mysql_insert_id().'</p>';
echo '<p align=center><a href="/TFC/admin/products_insert.php">Enter Another News Product</a></p>';
}
}else{
echo "Imagem Muito Grande!!";
}
break;
default:
include $_SERVER['DOCUMENT_ROOT'].'/TFC/admin/mod_products_form.php';
break;
}
//corpo();
?>
Código:
<?php
include $_SERVER['DOCUMENT_ROOT'].'/TFC/includes/cat_list.php';
?>
<html>
<head>
</head>
<body>
<p> </p>
<form action="products_insert.php" method="post" enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1">
<tr><td colspan="2">Add Product</td></tr>
<tr>
<td width="150">Category</td>
<td><?php cat_list(NULL);?></td>
</tr>
<tr>
<td width="150">Product Name</td>
<td> <input name="product_title" type="text" id="product_title" size="50" maxlength="100"></td>
</tr>
<tr>
<td width="150">Caption</td>
<td> <input name="product_caption" type="text" id="product_caption" size="50" maxlength="100"></td>
</tr>
<tr>
<td width="150">Description</td>
<td> <textarea name="long_description" cols="70" rows="10" id="long_description"></textarea></td>
</tr>
<tr>
<td width="150">Price</td>
<td><input name="product_price" type="text" id="product_price" size="10" maxlength="7"> </td>
</tr>
<tr>
<td width="150">Qty In Stock</td>
<td><input name="product_qty" type="text" id="product_qty" size="10" maxlength="10"> </td>
</tr>
<tr>
<td width="150">Imagem</td>
<td>
<input name="product_image" type="file" id="product_image" size="50" value="Imagem" >
<input type="hidden" name="MAX_FILE_SIZE" value="96000">
<input name="req" type="hidden" id="req" value="submit_product" />
<input type="submit" name="submit" value="Submit New Product!" /></td>
</tr>
</table>
</form>
</body>
</html>