1 réponse
Alain_42
Messages postés
5361
Date d'inscription
dimanche 3 février 2008
Statut
Membre
Dernière intervention
13 février 2017
894
27 févr. 2009 à 12:54
27 févr. 2009 à 12:54
//il faudrait que tu nous donnes la partie du formulaire qui concerne ce POST $attributes = explode("\n", $_POST[prod_attributes]); //et pour ta requette, il faut autant de VALUES que de champs foreach($attributes AS $key => $value){ if($value!=""){ $addnewoptionvalue=mysql_query("INSERT INTO products_options_values (language_id,products_options_values_name) VALUES ('4','".$value."','')"); } }
27 févr. 2009 à 12:59
Voila le fichier complet (je pensai que seul la partie suffisait)
<?
require('includes/application_top.php');
$languages = tep_get_languages();
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
</table></td>
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?
//--- Did we submit the attribute changes?
if(isset($_POST[updateattributes])){
//I think im going to just delete all the old crap and re-insert cause I don't know how this script works yet~!
$deleteattributes=mysql_query("DELETE FROM products_attributes
WHERE products_attributes.products_id='$_GET[current_product_id]'");
if(!$deleteattributes)
die(mysql_error());
$deleteattributelinks=mysql_query("DELETE FROM products_attributes
WHERE products_attributes.products_id='$_GET[current_product_id]'");
if(!$deleteattributelinks)
die(mysql_error());
$addanewoption=mysql_query("INSERT INTO products_options (language_id,products_options_name)
VALUES ('4','Options')");
$optionid=mysql_insert_id();
$attributes = explode("\n", $_POST[prod_attributes]);
foreach($attributes AS $key => $value){
if($value!=""){
$addnewoptionvalue=mysql_query("INSERT INTO
products_options_values (language_id,products_options_values_name)
VALUES ('4','$value')");
if(!$addnewoptionvalue)
die('Damn you suck at coding. Trying to add new option value.<br><br>'.mysql_error());
$optionvalueid=mysql_insert_id();
$linkvaluewithoption=mysql_query("INSERT INTO
products_options_values_to_products_options (products_options_id,products_options_values_id)
VALUES ('$optionid','$optionvalueid')");
if(!$linkvaluewithoption)
die('Damn you suck at coding. Trying to add link value with option.<br><br>'.mysql_error());
$linkattributewithproduct=mysql_query("INSERT INTO
products_attributes (products_id,options_id,options_values_id )
VALUES ('$_GET[current_product_id]','$optionid','$optionvalueid')");
if(!$linkattributewithproduct)
die('Damn you suck at coding. Trying to link attribute with product.<br><br>'.mysql_error());
}
}
echo "You have successfully updated the attributes for this product.<br>
<a href=\"javascript:history.go(-2)\">Click here to return.</a>";
die();
}
//--- First we see if we even have any attributes for this product yet
$getattributes=mysql_query("SELECT * FROM products_attributes,products_options,products_options_values
WHERE products_attributes.products_id='$_GET[current_product_id]'
AND products_options.products_options_id=products_attributes.options_id
AND products_options_values.products_options_values_id=products_attributes.options_values_id
ORDER BY products_options_values.products_options_values_name");
$oldattributes="";
while($attribute=mysql_fetch_array($getattributes)){
$oldattributes="$oldattributes"."$attribute[products_options_values_name]"."\n";
}
echo " <table cellspacing=0 cellpadding=4>
<tr><td colspan=2><h2>Mass Attributes</h2></td></tr>
<form action=massattributes.php?action=select¤t_product_id=$_GET[current_product_id]&cPath=$_GET[cPath] method=post>
<tr><td colspan=2><textarea cols=30 rows=25 name=prod_attributes>$oldattributes</textarea></td></tr>
<tr><td><input type=submit name=updateattributes value='Save Changes'></td>
<td><a href=\"javascript:history.back()\">Cancel</a></td></tr>
</table></form>";
?>
</table></TD>
</TR>
<!-- body_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
27 févr. 2009 à 16:44
Merci