Erreur script php
Résolu
slt , mon probleme est dans ce script php,
svp aidez moi maint si c'est posssible
merci
voici le script d'ajout
<?
$action_p = $_POST['action'];
if ($action_p == "ajouter"){
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$design_det=$_POST['t7'];
$exreq1="insert into promotion values('','".$code."','".$design."','".$marque."','".$categorie."','".$garantie."','".$prix."','".$prix_pro."','".$photo."','".$design_det."','".now()",'')";
mysql_query($exreq1);
echo("ajout produit promotion avec succées");
?>
<script>
parent.location("affiche.php");
</script>
<?
}
if ($action_p=="annuler")
{
?>
<script>
parent.location("affiche.php");
</script>
<? }?>
svp aidez moi maint si c'est posssible
merci
voici le script d'ajout
<?
$action_p = $_POST['action'];
if ($action_p == "ajouter"){
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$design_det=$_POST['t7'];
$exreq1="insert into promotion values('','".$code."','".$design."','".$marque."','".$categorie."','".$garantie."','".$prix."','".$prix_pro."','".$photo."','".$design_det."','".now()",'')";
mysql_query($exreq1);
echo("ajout produit promotion avec succées");
?>
<script>
parent.location("affiche.php");
</script>
<?
}
if ($action_p=="annuler")
{
?>
<script>
parent.location("affiche.php");
</script>
<? }?>
Configuration: Windows XP Internet Explorer 6.0
22 réponses
Résumé de la discussion
Un script PHP vise à ajouter un produit en promotion via une requête SQL et des valeurs POST, mais des problèmes d'identifiant et de syntaxe compromettent l'insertion. Plusieurs réponses expliquent que l'id ne doit pas être inséré s'il est auto-incrément et qu'il faut respecter le schéma de la table. D'autres évoquent des erreurs de syntaxe liées à la concaténation, aux guillemets ou à des champs manquants, et recommandent d'ajouter la date d'enregistrement dans une colonne dédiée. En cas d'échec persistant, il est conseillé de vérifier les noms de colonnes, le type des données, et d'utiliser un débogage avec des messages d'erreur.
-
ContributeurOk merci ;-)
-
ContributeurAlors c'est génial !
Quelle est la solution ?-
<?php
if (isset ($_POST['ajout']))
{
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$designation_det=$_POST['t7'];
$jour = date('Y-m-d');
$heure = date('h:i:s');
$aujourdhui = $jour." ".$heure;
include("configuration.php");
$exreq1=mysql_query("INSERT INTO produit VALUES(id,'$code','$design','$marque','$categorie','$garantie','$prix','$prix_pro','$photo','$designation_det','$aujourdhui' )");
if ($exreq1)
echo 'ajout produit avec succées';
else
echo 'erreur d ajout';
}
?> -
@di_tunisianException faire que 'id' n'est pas défini. Autant le remplacer par la valeur qu'il avait initialement : '' .
Ceci suppose que ce champ corresponde à un index (PK, U, ...) auto-increment -
@A.Nonymemerci d avoir repondu mais je ne comprends pas ce que tu me dis peux tu m expliquer les demarches a faire
fab
-
-
La meilleure chose je pense, c'est que tu devrais commencer par apprendre le php/mysql en lui même. ^^
C'est peu être un peu lourd au début, mais tu gagneras énormément de temps après!
https://openclassrooms.com/fr/
http://www.manuelphp.com/
https://www.php.net/-
-
ContributeurLà n'est pas la question mais au lieu d'attendre une solution otute faite, renseigne toi en parallèle, tu y gagneras en compètences...
Les variables de Session, qui sont stockées dans la mémoire du serveur et détruites à la fin d'un temps de non-activité de l'internaute...
Déclaration <? session_register("email"); ?> Affectation <? $email="info@mon-site.net"; ?> Lecture <? echo $email; ?> Destruction <? session_unregister("email"); ?> Destruction de toutes <? session_destroy(); ?> Il faut parfois mettre en haut de chaque page : <? // Session créée ? Sinon, en créer une nouvelle if($PHPSESSID) session_start($PHPSESSID); else session_start(); ?>
Et la lecture associée :
https://www.php.net/manual/fr/ref.session.php
Tu vas y arriver.
Fait le code toi-même et si tu as des erreurs, on t'aidera si possible ;-)
Bon courage. -
@foobar47qui t'a dis que j'essaye de chercher la solution toute seule
en tous cas merci pour ton aide -
Contributeur@foobar47J'ai pas dit que tu la cherchais toute seule...
Je te conseille de la chercher, c'est déjà ça...
Tout ne tombe pas tout cuit et tout porte à croire que tu n'as pas pris la peine de chercher étant donné que tu as posé une question 1h aprés avoir reçu une indication...
Bon courage. -
@foobar47merci pour ton aide j'ai regle le probleme
-
-
ContributeurIl faut utiliser des variables de SESSION afin que ta variable puisse être apellée depuis n'importe quelle page.
-
Bonjour,
Remplace
$exreq1='INSERT INTO produit VALUES(id,'$code','$designation','$marque','$categorie','$garantie','$prix','$prix_pro','$photo','$design_det','$aujourdhui' ');
par$exreq1='INSERT INTO produit (code,designation,marque,categorie,...) VALUES('$code','$designation','$marque','$categorie','$garantie','$prix','$prix_pro','$photo','$design_det','$aujourdhui' ');-
-
-
@foobar47le probleme mnt est dans la page modifier
je ne connais pas comment faire pour modifier des informations saisi non pas a partir de la page d'affichage mais a partir une page séparé
-
-
ContributeurAllez, va z'y, poste ici l'ensemble des fichiers concernés, formulaire et traitement.
On va regarder ça... ;-)-
bjr
voici le fichier d'ajout:
<? include("configuration.php");?>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC">
<?php
$action = $_POST['action'];
if ($action == "ajouter"){
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$design_det=$_POST['t7'];
$jour = date('Y-m-d');
$heure = date('h:i:s');
$aujourdhui = $jour." ".$heure;
$exreq1='INSERT INTO produit VALUES(id,'$code','$designation','$marque','$categorie','$garantie','$prix','$prix_pro','$photo','$design_det','$aujourdhui' ');
mysql_query($exreq1);
echo 'ajout produit avec succées';
echo '
<script>
parent.location("affiche.php");
</script>
';
}
if ($action=="annuler")
{
echo'
<script>
parent.location("affiche.php");
</script>
';
}
?>
<table width="83%" height="740" border="0" bgcolor="#FFFFFF">
<tr>
<td height="130" colspan="2"><img src="../../img/sintec_p.jpg" width="656" height="99" align="middle"></td>
</tr>
<tr>
<td width="21%" height="98"><table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Produits</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="affiche.php">Afficher
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="ajout.php">Inserer
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="modif.php">Modifier
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="supprimer.php">Supprimer
produit</a></font></p></td>
</tr>
</table></td>
<td width="79%"> </td>
</tr>
<tr>
<td height="127"> <table width="99%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Produits
promotion </strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/affiche_pro.php">Afficher
promotion</a> </font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/ajout_pro.php">Inserer
promotion</a></font></p></td>
</tr>
<tr>
<td height="23"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/modifier_pro.php">Modifier
promotion</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/supprimer_pro.php">Supprimer
promotion</a></font></p></td>
</tr>
</table></td>
<td rowspan="4"><form action="ajout.php" method="POST" name="ajout_produit" >
<table width="79%" border="1" align="center">
<tr bgcolor="#FF0000">
<td colspan="2"><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif"><strong>Insertion
des produits :</strong></font></td>
</tr>
<tr>
<td width="32%" bgcolor="#FFFFFF">Code :</td>
<td width="68%" bgcolor="#FFFFFF"> <input type="text" name="t1"> </td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Désignation :</td>
<td bgcolor="#E4E4E4"> <input type="text" name="t2"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Marque :</td>
<td bgcolor="#FFFFFF"> <select name="s1">
<option>Aopen</option>
<option>Dell</option>
<option>Seimens</option>
<option>Toshiba</option>
</select> </td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Catégorie :</td>
<td bgcolor="#E4E4E4"> <select name="s2">
<option>ordinateur</option>
<option>imprimante</option>
</select> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Garantie :</td>
<td bgcolor="#FFFFFF"> <input type="text" name="t3"></td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Prix :</td>
<td bgcolor="#E4E4E4"> <input type="text" name="t4"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Prix promotion :</td>
<td bgcolor="#FFFFFF"> <input type="text" name="t5"> </td>
</tr>
?????
<tr>
<td bgcolor="#E4E4E4">Photo :</td>
<td bgcolor="#E4E4E4"> <input type="file" / name="t6" > </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">désignation détaillée:</td>
<td bgcolor="#FFFFFF"> <textarea name="t7"></textarea> </td>
</tr>
<tr bgcolor="E4E4E4">
<td colspan="2"> <table width="52%" border="0" align="center">
<tr>
<td width="47%"><input type="hidden" name="action" value="editer"/>
<input type="submit" name="ajout" onClick="document.ajout_produit.action.value='ajouter';" value="Enregistrer"></td>
<td width="33%"><input type="reset" name="ann" onClick="document.ajout_produit.action.value='annuler';" value="Annuler"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</form></td>
</tr>
<tr>
<td height="94"><table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Magasine
& Presse</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/affiche_m_p.php">Afficher
Magasine </a></font></p></td>
</tr>
<tr>
<td height="22"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/ajout_m_p.php">Inserer
Magasine </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/modifier_m_p.php">Modifier
Magasine </a></font></p></td>
</tr>
<tr>
<td height="21"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/supprimer_m_p.php">Supprimer
Magasine </a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="106">
<table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>News</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/affiche_n.php">Afficher
News</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/ajout_n.php">Inserer
News </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/modif_n.php">Modifier
News </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/supprimer_n.php">Supprimer
News </a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="106"> <table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Redistributeur</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/affiche_redis.php">Afficher
</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/ajout_redis.php">Inserer
</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/modif_redis.php">Modifier
</a></font></p></td>
</tr>
<tr>
<td height="23"><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/supp_redis.php">Supprimer
</a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong><a href="../deconnexion.php">Déconnexion</a></strong></font></td>
<td> </td>
</tr>
</table>
</body>
</html>
-
-
ContributeurIl ne doit pas y avoir de 'id' puisque tu ne récupères et n'insères aucune variable nommé "id" !!
Le parse error est une simple erreur de syntaxe dans ton cas.
Le code est bon.
-
ContributeurEssaye ceci :
INTO `promotion` ( `code` , `design` , `marque` , `categorie` , `garantie` , `prix` , `prix_pro` , `photo` , `design_det` , `aujourdhui` ) values($code...)
ainsi de suite
je ne connais pas le nom de tes champs dans ta base donc j'ai repris le nom des variables.
A toi d'adapter en fonction de...-
tu veut dire que le script soit comme ca:
$exreq1='INSERT INTO produit (id,'$code','$designation','$marque','$categorie','$garantie','$prix','$prix_pro','$photo','$design_det')values(id,"$code","$design","$marque","$categorie","$garantie","$prix","$prix_pro","$photo","$design_det","$aujourdhui")';
;
j'ai essaye ca et toujours ne marche pas et le message d'erreur
parse error
je ne sais quoi faire pour que ce script marche correctement plz aide moi merci d'avance
-
-
ContributeurN'importe quoi ^^ !!!
Ecris ça pour ta requète :$exreq1='insert into promotion values("$code","$design","$marque","$categorie","$garantie","$prix","$prix_pro","$photo","$design_det","$aujourdhui")';
Les requètes MySQL savent lire le php, pas la peine de concatener les variables... ;-)-
-
ContributeurEt essaye de tout mettre sur une seule ligne :
succès et pas " succées" ...echo 'ajout produit avec succées'; echo ' <script> Parent.location("affiche.php"); </script> '; } if ($action=="annuler") { echo' <script> Parent.location("affiche.php"); </script> '; }
La fonction echo est apellée puis il y a un saut de ligne, c'est pas "propre".
Et encode les caractères spéciaux (accents...) dans tes messages...
Y'a-t-il encore des erreurs ? -
-
-
Contributeur@nassdakJ'ai édité ;)
-
-
Tu as encore utilisé ta fonction "now"............
-
de quels espace tu parle et le requette :
//$exreq='INSERT INTO produit VALUES(\'\',\''.$code.'\',\''.$design.'\',\''.$marque.'\',\''.$categorie.'\',\''.$garantie.'\',\''.$prix.'\',\''.$prix_pro.'\',\''.$photo.'\',\''.$design_det.'\',\''.now()'\',\'\')';
//mysql_query($exreq);
je les mis en commentaire
-
-
Et tu ne pas répondu pourquoi tu as des champs vide en début et fin de requete...
-
Pourquoi as-tu réutilisé ta fonction "now" directement dans la requête?
Et pourquoi as-tu un champ vide au début et à la fin de la requête?-
-
Moi je t'es envoyé celle la :
$jour = date('Y-m-d'); $heure = date('h:i:s'); $aujourdhui = $jour." ".$heure; $exreq1='insert into promotion values("'.$code.'","'.$design.'","'.$marque.'","'.$categorie.'","'.$garantie.'","'.$prix.'","'.$prix_pro.'","'.$photo.'","'.$design_det.'","'.$aujourdhui'")'; mysql_query($exreq1);
Et qui a été approuvé par la 1ere personne aussi :) -
@nassdakmais il affiche le meme erreur parse error
je ne sais pkoi -
Contributeur@nassdakCela devrait fonctionner !
-
@nassdakle script est devenu comme suit:
<? include("configuration.php");?>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC">
<?
$action = $_POST['action'];
if ($action == "ajouter"){
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$design_det=$_POST['t7'];
$jour = date('Y-m-d');
$heure = date('h:i:s');
$aujourdhui = $jour." ".$heure;
//$exreq='INSERT INTO produit VALUES(\'\',\''.$code.'\',\''.$design.'\',\''.$marque.'\',\''.$categorie.'\',\''.$garantie.'\',\''.$prix.'\',\''.$prix_pro.'\',\''.$photo.'\',\''.$design_det.'\',\''.now()'\',\'\')';
//mysql_query($exreq);
$exreq1='insert into promotion values("'.$code.'","'.$design.'","'.$marque.'","'.$categorie.'","'.$garantie.'","'.$prix.'","'.$prix_pro.'","'.$photo.'","'.$design_det.'","'.$aujourdhui'")';
mysql_query($exreq1);
echo 'ajout produit avec succées';
echo ' <script>
Parent.location("affiche.php");
</script>
';
}
if ($action=="annuler")
{
echo' <script>
Parent.location("affiche.php");
</script>
';
}
?>
et toujours la meme erreur parse error
-
-
Mais l'erreur ne dois pu etre la même, car nous n'utilisons plus ta fonction "now".
Quel message d'erreur s'affiche? -
Voilà, tu mix les deux et en principe ça devrait fonctionner :)
-
-
-
@foobar47le code est le suivant:
la faute dans la ligne d'insert requette parse error
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC">
<? php
include("configuration.php");
$action = $_POST['action'];
if ($action == "ajouter"){
$code=$_POST['t1'];
$design=$_POST['t2'];
$marque=$_POST['s1'];
$categorie=$_POST['s2'];
$garantie=$_POST['t3'];
$prix=$_POST['t4'];
$prix_pro=$_POST['t5'];
$photo=$_POST['t6'];
$design_det=$_POST['t7'];
$exreq='INSERT INTO produit VALUES(\'\',\''.$code.'\',\''.$design.'\',\''.$marque.'\',\''.$categorie.'\',\''.$garantie.'\',\''.$prix.'\',\''.$prix_pro.'\',\''.$photo.'\',\''.$design_det.'\',\''.now()'\',\'\')';
mysql_query($exreq);
echo 'ajout produit avec succées';
if ($action=="ajouter")
{
echo ' <script>
Parent.location("affiche.php");
</script>
';
}
if ($action=="annuler")
{
echo' <script>
Parent.location("affiche.php");
</script>
';
}
?>
<table width="83%" height="740" border="0" bgcolor="#FFFFFF">
<tr>
<td height="130" colspan="2"><img src="../../img/sintec_p.jpg" width="656" height="99" align="middle"></td>
</tr>
<tr>
<td width="21%" height="98"><table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Produits</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="affiche.php">Afficher
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="ajout.php">Inserer
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="modif.php">Modifier
produit</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="supprimer.php">Supprimer
produit</a></font></p></td>
</tr>
</table></td>
<td width="79%"> </td>
</tr>
<tr>
<td height="127"> <table width="99%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Produits
promotion </strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/affiche_pro.php">Afficher
promotion</a> </font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/ajout_pro.php">Inserer
promotion</a></font></p></td>
</tr>
<tr>
<td height="23"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/modifier_pro.php">Modifier
promotion</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../promotion/supprimer_pro.php">Supprimer
promotion</a></font></p></td>
</tr>
</table></td>
<td rowspan="4"><form action="ajout.php" method="POST" name="ajout_produit" >
<table width="79%" border="1" align="center">
<tr bgcolor="#FF0000">
<td colspan="2"><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif"><strong>Insertion
des produits :</strong></font></td>
</tr>
<tr>
<td width="32%" bgcolor="#FFFFFF">Code :</td>
<td width="68%" bgcolor="#FFFFFF"> <input type="text" name="t1"> </td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Désignation :</td>
<td bgcolor="#E4E4E4"> <input type="text" name="t2"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Marque :</td>
<td bgcolor="#FFFFFF"> <select name="s1">
<option>Aopen</option>
<option>Dell</option>
<option>Seimens</option>
<option>Toshiba</option>
</select> </td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Catégorie :</td>
<td bgcolor="#E4E4E4"> <select name="s2">
<option>ordinateur</option>
<option>imprimante</option>
</select> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Garantie :</td>
<td bgcolor="#FFFFFF"> <input type="text" name="t3"></td>
</tr>
<tr>
<td bgcolor="#E4E4E4">Prix :</td>
<td bgcolor="#E4E4E4"> <input type="text" name="t4"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Prix promotion :</td>
<td bgcolor="#FFFFFF"> <input type="text" name="t5"> </td>
</tr>
?????
<tr>
<td bgcolor="#E4E4E4">Photo :</td>
<td bgcolor="#E4E4E4"> <input type="file" / name="t6" > </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">désignation détaillée:</td>
<td bgcolor="#FFFFFF"> <textarea name="t7"></textarea> </td>
</tr>
<tr bgcolor="E4E4E4">
<td colspan="2"> <table width="52%" border="0" align="center">
<tr>
<td width="47%"><input type="hidden" name="action" value="editer"/>
<input type="submit" name="ajout" onClick="document.ajout_produit.action.value='ajouter';" value="Enregistrer"></td>
<td width="33%"><input type="reset" name="ann" onClick="document.ajout_produit.action.value='annuler';" value="Annuler"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</form></td>
</tr>
<tr>
<td height="94"><table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Magasine
& Presse</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/affiche_m_p.php">Afficher
Magasine </a></font></p></td>
</tr>
<tr>
<td height="22"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/ajout_m_p.php">Inserer
Magasine </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/modifier_m_p.php">Modifier
Magasine </a></font></p></td>
</tr>
<tr>
<td height="21"> <p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../magasine_presse/supprimer_m_p.php">Supprimer
Magasine </a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="106">
<table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>News</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/affiche_n.php">Afficher
News</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/ajout_n.php">Inserer
News </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/modif_n.php">Modifier
News </a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../news/supprimer_n.php">Supprimer
News </a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="106"> <table width="100%" border="0" align="left" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FF0000"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Redistributeur</strong></font></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/affiche_redis.php">Afficher
</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/ajout_redis.php">Inserer
</a></font></p></td>
</tr>
<tr>
<td><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/modif_redis.php">Modifier
</a></font></p></td>
</tr>
<tr>
<td height="23"><p><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><a href="../redistributeur/supp_redis.php">Supprimer
</a></font></p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong><a href="../deconnexion.php">Déconnexion</a></strong></font></td>
<td> </td>
</tr>
</table>
</body>
</html>
-
-
$jour = date('Y-m-d'); $heure = date('h:i:s'); $aujourdhui = $jour." ".$heure; $exreq1='insert into promotion values("'.$code.'","'.$design.'","'.$marque.'","'.$categorie.'","'.$garantie.'","'.$prix.'","'.$prix_pro.'","'.$photo.'","'.$design_det.'","'.$aujourdhui'")'; mysql_query($exreq1); -
version plus "propre" de ton code :
<?php $action_p = $_POST['action']; if ($action_p == "ajouter"){ $code=$_POST['t1']; $design=$_POST['t2']; $marque=$_POST['s1']; $categorie=$_POST['s2']; $garantie=$_POST['t3']; $prix=$_POST['t4']; $prix_pro=$_POST['t5']; $photo=$_POST['t6']; $design_det=$_POST['t7']; $exreq1='insert into promotion values(\'\',\''.$code.'\',\''.$design.'\',\''.$marque.'\',\''.$categorie.'\',\''.$garantie.'\',\''.$prix.'\',\''.$prix_pro.'\',\''.$photo.'\',\''.$design_det.'\',\''.now()'\',\'\')'; mysql_query($exreq1); echo 'ajout produit promotion avec succées'; echo ' <script> parent.location("affiche.php"); </script> '; } if ($action_p=="annuler") { echo ' <script> parent.location("affiche.php"); </script> '; } ?> -
L'erreur vient de l'insertion de la date.
Il faut que tu passes ta date dans une variable au préalable
$jour = date('Y-m-d'); $heure = date('h:i:s'); $aujourdhui = $jour." ".$heure; -
j'ai ecrit dans mon script la requette suivante :
$exreq1="insert into promotion values('','".$code."','".$design."','".$marque."','".$categorie."','".$garantie."','".$prix."','".$prix_pro."','".$photo."','".$design_det."','".now()",'')";
et je lui corrigé par une autre nouvelle requette :
$exreq=mysql_query("INSERT INTO produit values("$code","$design","$marque","$categorie","$garantie","$prix","$prix_pro","$photo","$design_det", now());
mais ca marche pas encore
le maessage d'erruer s'affiche comme suit : erreur fatale function now()
et encore ne fait pas l'affichage d'insertion dans ma table
les champs de la table c'est :
id int, code varchar, designation varchar, marque varchar,categorie varchar, garantie varchar, prix decimal,prix pro decimal,photo varchar, design_det varchar , date_time -
Ok.
Je pense que l'erreur vient de là :values('','".$code."','"
Pourquoi as tu mis une virgule?
Pour débugguer, tu peux faire unecho $exreq1;
Et tu executes ta requete directement dans mysql -
Bonjour,
Si tu pouvais copier l'erreur en question ça aiderais beaucoup.
Bien souvent, la solution se trouve dans le message d'erreur :)
ps:
les balises PHP ne sont plus <? ?> mais plutôt <?php ?>
- 1
- 2
Suivant