Echec d'enregistrement dans la bdd
Bonjour tout le monde !
Voila mon souci : j'ai fait une page pour uploader un fichier et récupérer son chemin pour le mettre dans une base de donnée.
L'upload se fait correctement dans le dossier voulu. Sauf que je n'ai rien du tout qui s'enregistre dans ma base de donnée.
Ma base de donner : tp
Ma table : tp_telechargement
Mes colonnes : id, chemin
Voici en dessous le code de ma page :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
if (phpversion() > "5.4.3") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",30000000);
define("DESTINATION_FOLDER", "upload");
define("no_error", "ok.php");
define("yes_error", "erreur.php");
$_accepted_extensions_ = "pdf";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}
/* modify */
if(!empty($HTTP_POST_FILES['chemin'])){
if(is_uploaded_file($HTTP_POST_FILES['chemin']['tmp_name']) && $HTTP_POST_FILES['chemin']['error'] == 0){
$_file_ = $HTTP_POST_FILES['chemin'];
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "Fichier trop gros";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "Extension non valide";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = "Dossier de destination non valide";
}
if(empty($errStr)){
if(@move_uploaded_file($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
header("Location: " . no_error);
// Connexion BDD
mysql_select_db($database_maxonnex,$maxonnex);
$însertTel="INSERT INTO tp_tel (chemin) VALUES ('$_name')";
mysql_query($insertTel, $maxonnex) or die (mysql_error());
} else {
header("Location: " . yes_error);
}
} else {
header("Location: " . yes_error);
}
}
}
?>
<?php require_once('Connections/maxonnex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_maxonnex, $maxonnex);
$query_telechargement = "SELECT chemin FROM tp_tel ORDER BY `date` ASC";
$telechargement = mysql_query($query_telechargement, $maxonnex) or die(mysql_error());
$row_telechargement = mysql_fetch_assoc($telechargement);
$totalRows_telechargement = mysql_num_rows($telechargement);
?>
<!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=utf-8" />
<title>Document sans titre</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>
<label for="chemin">téléchargement du pdf</label>
<input type="file" name="chemin" id="chemin" />
</p>
<p>
<input type="submit" name="Envoyer" id="Envoyer" value="Envoyer" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($telechargement);
?> |
J'ai beau tout retourner dans tous les sens je ne trouve pas mon erreur :/
Merci d'avance pour votre aide !