par
arentx » 07 déc. 2006, 18:46
Merci,
Alors je viens d"essayer un truc mais ca marche pas... peut etre une erreur dans mon code
<?php require_once('Connections/connect.php'); ?>
<?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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO article (id_cat, id_scat, `ref`, nom_art, desi, stock, prix, photo)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_catcaché'], "text"),
GetSQLValueString($_POST['select'], "text"),
GetSQLValueString($_POST['ref'], "text"),
GetSQLValueString($_POST['nom_art'], "text"),
GetSQLValueString($_POST['desi'], "text"),
GetSQLValueString($_POST['stock'], "text"),
GetSQLValueString($_POST['prix'], "double")),
GetSQLValueString(.$_FILES['photo'] ['name']));
mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
$insertGoTo = "listart.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['id_cat'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id_cat'] : addslashes($_GET['id_cat']);
}
mysql_select_db($database_connect, $connect);
$query_Recordset1 = sprintf("SELECT id_scat, nom_scat FROM scat WHERE id_cat = %s ORDER BY id_scat ASC", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$colname_Recordset2 = "-1";
if (isset($_GET['id_cat'])) {
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $_GET['id_cat'] : addslashes($_GET['id_cat']);
}
mysql_select_db($database_connect, $connect);
$query_Recordset2 = sprintf("SELECT * FROM cat WHERE id_cat = %s", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $connect) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<?php
if(isset($_FILES['photo']))
{
// params
unset($erreur);
$extensions_ok = array('png', 'gif', 'jpg', 'jpeg');
$taille_max = 100000;
$dest_dossier = './pics/art/';
// vérifications
if( !in_array( substr(strrchr($_FILES['photo']['name'], '.'), 1), $extensions_ok ) )
{
$erreur = 'Veuillez sélectionner un fichier de type png, gif ou jpg !';
}
elseif( file_exists($_FILES['photo']['tmp_name'])
and filesize($_FILES['photo']['tmp_name']) > $taille_max)
{
$erreur = 'Votre fichier doit faire moins de 500Ko !';
}
// copie du fichier
if(!isset($erreur))
{
$dest_fichier = basename($_FILES['photo']['name']);
// formatage nom fichier
// enlever les accents
$dest_fichier = strtr($dest_fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
// remplacer les caracteres autres que lettres, chiffres et point par _
$dest_fichier = preg_replace('/([^.a-z0-1]+)/i', '_', $dest_fichier);
// copie du fichier
move_uploaded_file($_FILES['photo']['tmp_name'], $dest_dossier . $dest_fichier);
}
}
?>
<html>
<head>
<title>Ajout d'article</title>
</head>
<body>
<p> </p>
<p><?php echo $row_Recordset2['nom_cat']; ?></p>
<p>la sous cat </p>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p><!-- -->
<select name="select">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['id_scat']?>"><?php echo $row_Recordset1['nom_scat']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</p>
<p>ref :
<input type="text" name="ref">
</p>
<p>nom :
<input type="text" name="nom_art">
</p>
<p>désignation :
<input type="text" name="desi">
</p>
<p>stock :
<input type="text" name="stock">
</p>
<p>prix :
<input type="text" name="prix">
</p>
<p>photo :
<input type="file" name="photo">
</p>
<p>
<input type="submit" name="Submit" value="Envoyer">
</p>
<p>
<input name="id_catcaché" type="hidden" value="<?php echo $row_Recordset2['id_cat']; ?>">
</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
Cela me met une erreur ligne 41 mais je ne sais pas pourquoi ...
Merci,
Alors je viens d"essayer un truc mais ca marche pas... peut etre une erreur dans mon code :oops:
[php]
<?php require_once('Connections/connect.php'); ?>
<?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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO article (id_cat, id_scat, `ref`, nom_art, desi, stock, prix, photo)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_catcaché'], "text"),
GetSQLValueString($_POST['select'], "text"),
GetSQLValueString($_POST['ref'], "text"),
GetSQLValueString($_POST['nom_art'], "text"),
GetSQLValueString($_POST['desi'], "text"),
GetSQLValueString($_POST['stock'], "text"),
GetSQLValueString($_POST['prix'], "double")),
GetSQLValueString(.$_FILES['photo'] ['name']));
mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
$insertGoTo = "listart.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['id_cat'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id_cat'] : addslashes($_GET['id_cat']);
}
mysql_select_db($database_connect, $connect);
$query_Recordset1 = sprintf("SELECT id_scat, nom_scat FROM scat WHERE id_cat = %s ORDER BY id_scat ASC", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$colname_Recordset2 = "-1";
if (isset($_GET['id_cat'])) {
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $_GET['id_cat'] : addslashes($_GET['id_cat']);
}
mysql_select_db($database_connect, $connect);
$query_Recordset2 = sprintf("SELECT * FROM cat WHERE id_cat = %s", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $connect) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<?php
if(isset($_FILES['photo']))
{
// params
unset($erreur);
$extensions_ok = array('png', 'gif', 'jpg', 'jpeg');
$taille_max = 100000;
$dest_dossier = './pics/art/';
// vérifications
if( !in_array( substr(strrchr($_FILES['photo']['name'], '.'), 1), $extensions_ok ) )
{
$erreur = 'Veuillez sélectionner un fichier de type png, gif ou jpg !';
}
elseif( file_exists($_FILES['photo']['tmp_name'])
and filesize($_FILES['photo']['tmp_name']) > $taille_max)
{
$erreur = 'Votre fichier doit faire moins de 500Ko !';
}
// copie du fichier
if(!isset($erreur))
{
$dest_fichier = basename($_FILES['photo']['name']);
// formatage nom fichier
// enlever les accents
$dest_fichier = strtr($dest_fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
// remplacer les caracteres autres que lettres, chiffres et point par _
$dest_fichier = preg_replace('/([^.a-z0-1]+)/i', '_', $dest_fichier);
// copie du fichier
move_uploaded_file($_FILES['photo']['tmp_name'], $dest_dossier . $dest_fichier);
}
}
?>
<html>
<head>
<title>Ajout d'article</title>
</head>
<body>
<p> </p>
<p><?php echo $row_Recordset2['nom_cat']; ?></p>
<p>la sous cat </p>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p><!-- -->
<select name="select">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['id_scat']?>"><?php echo $row_Recordset1['nom_scat']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</p>
<p>ref :
<input type="text" name="ref">
</p>
<p>nom :
<input type="text" name="nom_art">
</p>
<p>désignation :
<input type="text" name="desi">
</p>
<p>stock :
<input type="text" name="stock">
</p>
<p>prix :
<input type="text" name="prix">
</p>
<p>photo :
<input type="file" name="photo">
</p>
<p>
<input type="submit" name="Submit" value="Envoyer">
</p>
<p>
<input name="id_catcaché" type="hidden" value="<?php echo $row_Recordset2['id_cat']; ?>">
</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
[/php]
Cela me met une erreur ligne 41 mais je ne sais pas pourquoi ...