par
mazzette » 09 juin 2007, 14:34
Ben voici mon code :
Code : Tout sélectionner
<?php require_once('../Connections/objectif.php'); ?>
<?php
// ---------------------------------------------
// Pure PHP Upload version 1.1
// -------------------------------------------
if (phpversion() > "4.0.6") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "./img/");
define("no_error", "valider.php");
define("yes_error", "erreur.php");
$_accepted_extensions_ = "gif,jpg,pdf,doc,png";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}
/* modify */
if(!empty($HTTP_POST_FILES['fichier'])){
if(is_uploaded_file($HTTP_POST_FILES['fichier']['tmp_name']) && $HTTP_POST_FILES['fichier']['error'] == 0){
$_file_ = $HTTP_POST_FILES['fichier'];
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "Votre fichier est trop lourd";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "L'extension du fichier n'est pas valide";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = "Les droits en écriture du dossier de stockage n'est pas valide";
}
if(empty($errStr)){
if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_))
{header("Location: " . no_error);}
//enregistrement dans la base
mysql_select_db($database_objectif, $objectif);
$insertoffre = "INSERT INTO offre (fichier )
VALUES ('$_name_')";
mysql_query($insertoffre, $objectif)
or die(mysql_error());
} else {
header("Location: " . yes_error);
}
} else {
header("Location: " . yes_error);
}
}
?>
<?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"] == "form")) {
$insertSQL = sprintf("INSERT INTO offre (`date`, poste, description, lieu, contact) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['poste'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['lieu'], "text"),
GetSQLValueString($_POST['contact'], "text"));
mysql_select_db($database_objectif, $objectif);
$Result1 = mysql_query($insertSQL, $objectif) or die(mysql_error());
$insertGoTo = "Offres.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BackOffice d'Objectif Emploi</title>
<link rel="stylesheet" media="screen" type="text/css" href="stylebackoffice.css"/>
<?php $pageName = "offres"; ?>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('Les informations exigées sont incomplètes ou contiennent des erreurs:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>
<body>
<div id="general">
<div id="entete"><div id="deconnection">SE DECONNECTER</div></div>
<div id="contenu">
<a href="../index.php">
<div id="logo"> </div></a>
<div id="menus"> <?php include ("menus.php");?></div>
<div id="pages">
<div id="titre"><span class="titre">Formulaire d'ajout d'une offre d'emploi</span></div>
<div id="formulaire">
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form" id="form" onsubmit="YY_checkform('form','poste','#q','0','Le champ \'Poste\' n\'est pas valide','lieu','#q','0','Le champ \'Lieu\' n\'est pas valide','description','10','1','Le champs \'Description\' doit comporter au moins 10 caractères');return document.MM_returnValue">
<table width="592" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="enteteformulaire"width="101">Date</td>
<td colspan="2"><input value="<?php echo $dateDujour=date("Y-m-d");?>"name="date" type="text" id="date" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Poste</td>
<td colspan="2"><input name="poste" type="text" id="poste" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Description</td>
<td colspan="2"><textarea name="description" id="description" rows="8"cols="60"></textarea></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Lieu</td>
<td colspan="2"><input name="lieu" type="text" id="lieu" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Contact</td>
<td colspan="2"><input name="contact" type="text" id="contact" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">FICHIER</td>
<td colspan="2"><input name="fichier" type="file" id="fichier" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td width="136"><input name="Ajouter" type="submit" id="Ajouter" value="Ajouter" /></td>
<td width="355"><input name="reinitialiser" type="reset" id="reinitialiser" value="Réinitialiser" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form">
</form>
</div>
<div id="tableauliens">
<table width="595" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="308"></td>
<td width="281" > </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a href="Offres.php"><span class="lienretour"><<retour - offres d'Emploi</span></a></td>
<td> </td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
ceci est un formulaire d'ajout pour ajouter une offre comportant un cham pde fichier pour le téléchargement
Voila... et dès que je remplis le formulaire.. il me renvoie à la page offre (celle ki liste les offres dans un tableau) mais il afiche une ligne vierge dans le tableau pour l'offre ajoutée.
Ben voici mon code :
[code]
<?php require_once('../Connections/objectif.php'); ?>
<?php
// ---------------------------------------------
// Pure PHP Upload version 1.1
// -------------------------------------------
if (phpversion() > "4.0.6") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "./img/");
define("no_error", "valider.php");
define("yes_error", "erreur.php");
$_accepted_extensions_ = "gif,jpg,pdf,doc,png";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}
/* modify */
if(!empty($HTTP_POST_FILES['fichier'])){
if(is_uploaded_file($HTTP_POST_FILES['fichier']['tmp_name']) && $HTTP_POST_FILES['fichier']['error'] == 0){
$_file_ = $HTTP_POST_FILES['fichier'];
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "Votre fichier est trop lourd";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "L'extension du fichier n'est pas valide";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = "Les droits en écriture du dossier de stockage n'est pas valide";
}
if(empty($errStr)){
if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_))
{header("Location: " . no_error);}
//enregistrement dans la base
mysql_select_db($database_objectif, $objectif);
$insertoffre = "INSERT INTO offre (fichier )
VALUES ('$_name_')";
mysql_query($insertoffre, $objectif)
or die(mysql_error());
} else {
header("Location: " . yes_error);
}
} else {
header("Location: " . yes_error);
}
}
?>
<?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"] == "form")) {
$insertSQL = sprintf("INSERT INTO offre (`date`, poste, description, lieu, contact) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['poste'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['lieu'], "text"),
GetSQLValueString($_POST['contact'], "text"));
mysql_select_db($database_objectif, $objectif);
$Result1 = mysql_query($insertSQL, $objectif) or die(mysql_error());
$insertGoTo = "Offres.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BackOffice d'Objectif Emploi</title>
<link rel="stylesheet" media="screen" type="text/css" href="stylebackoffice.css"/>
<?php $pageName = "offres"; ?>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('Les informations exigées sont incomplètes ou contiennent des erreurs:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>
<body>
<div id="general">
<div id="entete"><div id="deconnection">SE DECONNECTER</div></div>
<div id="contenu">
<a href="../index.php">
<div id="logo"> </div></a>
<div id="menus"> <?php include ("menus.php");?></div>
<div id="pages">
<div id="titre"><span class="titre">Formulaire d'ajout d'une offre d'emploi</span></div>
<div id="formulaire">
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form" id="form" onsubmit="YY_checkform('form','poste','#q','0','Le champ \'Poste\' n\'est pas valide','lieu','#q','0','Le champ \'Lieu\' n\'est pas valide','description','10','1','Le champs \'Description\' doit comporter au moins 10 caractères');return document.MM_returnValue">
<table width="592" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="enteteformulaire"width="101">Date</td>
<td colspan="2"><input value="<?php echo $dateDujour=date("Y-m-d");?>"name="date" type="text" id="date" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Poste</td>
<td colspan="2"><input name="poste" type="text" id="poste" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Description</td>
<td colspan="2"><textarea name="description" id="description" rows="8"cols="60"></textarea></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Lieu</td>
<td colspan="2"><input name="lieu" type="text" id="lieu" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">Contact</td>
<td colspan="2"><input name="contact" type="text" id="contact" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td class="enteteformulaire">FICHIER</td>
<td colspan="2"><input name="fichier" type="file" id="fichier" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td width="136"><input name="Ajouter" type="submit" id="Ajouter" value="Ajouter" /></td>
<td width="355"><input name="reinitialiser" type="reset" id="reinitialiser" value="Réinitialiser" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form">
</form>
</div>
<div id="tableauliens">
<table width="595" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="308"></td>
<td width="281" > </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a href="Offres.php"><span class="lienretour"><<retour - offres d'Emploi</span></a></td>
<td> </td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
[/code]
ceci est un formulaire d'ajout pour ajouter une offre comportant un cham pde fichier pour le téléchargement
Voila... et dès que je remplis le formulaire.. il me renvoie à la page offre (celle ki liste les offres dans un tableau) mais il afiche une ligne vierge dans le tableau pour l'offre ajoutée.