channark
13 Jun 2011, 12:38 PM
hello
i create a project to test my skills in php, when i workd in my local server 'easyphp' it works fine but when i upload it to my free host i got some probleme.
1- some form that add data to database table works fine but one of my forms it work and but the nothing in the database no data add
if (isset($_POST["envoyer"]))
{
if(empty($_POST["situation"]) || empty($_POST["age"]) || empty($_POST["nom"]) || empty($_POST["prenom"]) || empty($_POST["adress"]) || empty($_POST["ville"]) || empty($_POST["pays"]) )
{
$erreur1="Erreur vous devez remplir tous les champs";
}
else
{
$_POST['nom'] = check_str($_POST['nom']);
$_POST['prenom'] = check_str($_POST['prenom']);
$_POST['adresse'] = check_str($_POST['adresse']);
$_POST['ville'] = check_str($_POST['ville']);
$_POST['pays'] = check_str($_POST['pays']);
$_POST['tele'] = check_str($_POST['tele']);
$_POST['situation'] = check_str($_POST['situation']);
$select = mysql_query("SELECT * FROM `participon` WHERE `nom` = '".$_POST['nom']."' AND `adresse` = '".$_POST['adress']."' ");
//---rechrche si participon deja inscri
$exist = mysql_num_rows($select);
if ($exist > 0)
{
$false= " Votre nom et adresse existe deja, Vous ete deja inscrit";
}
else //if the user name doesn't exist in database
{
$addto= mysql_query("INSERT INTO `participon` SET `nom` = '".$_POST['nom']."', `prenom` = '".$_POST['prenom']."', `adresse` = '".$_POST['adress']."', `ville` = '".$_POST['ville']."', `pays` = '".$_POST['pays']."', `tele` = '".$_POST['tele']."', `situation` = '".$_POST['situation']."', `age` = '".$_POST['age']."' ");
if (isset($addto))
{
$succe="vos information sans ete ajouté avec succee";
}
else
{
$false="erreur";
}
}
}
}
note : the table name is participon and the connection is made successfully and the database is selected successfully
2- an other form allow admin to add a item it works fine but the image name (url) is add as it is (width the special caracters) so the image doesn't appear in the galerie
if (isset($_POST['subm']))
{
if ( !empty($_POST['desi']) or !empty($_POST['argent']) or !empty($_POST['somme']))
{
if(isset($_FILES['image']['tmp_name']) && $_FILES['image']['error']==0 )
{
$folder = "images/";
$file_temp=$_FILES['image']['tmp_name'];
$file_name= check_str(basename($_FILES['image']['name']));
$extentions=array(".jpg", ".png", ".jpeg", ".gif");
$extention=strrchr($file_name, '.');
$max_taille=2000000 ;
$file_taille=filesize($file_temp);
if (!in_array($extention, $extentions))
{
$erreur = "ERREUR votre fichier doit etre une image de type JPEG, JPG, GIF ou PNG";
}
if ( $file_taille > $max_taille)
{
$erreur = "votre fichier depasse la taille maximum";
}
if (!isset($erreur))
{
move_uploaded_file($file_temp, $folder.$file_name);
if ($_FILES['image']['error']==0)
{
$modif="INSERT INTO cadeaux SET designation = '".$_POST['desi']."' , argent = '".$_POST['argent']."' , somme = '".$_POST['somme']."', photo = '".$folder.$file_name."' " ;
mysql_query($modif);
//--vers page cadeaux
header("location:".$path."cadeaux.php?add=ok");
}
}
}
else
{
$modif="INSERT INTO cadeaux SET designation = '".$_POST['desi']."' , argent = '".$_POST['argent']."' , somme = '".$_POST['somme']."' " ;
mysql_query($modif);
//--vers page cadeaux
header("location: ".$path."cadeaux.php?add=ok");
}
}
else{
$erreur = "ERREUR un des champs Designation, Argent ou/et Somme est vide" ;
}
}
note : i want to know if i should us a condition if the image contain spec char return false or the code should change spec char width a valid character
check_str :
function check_str($str)
{
$str = filter_var($str, FILTER_SANITIZE_STRING);
$str = stripslashes($str);
$car_change = array('é'=>'e', 'è'=>'e', '/'=>'_', ' '=>'', '-'=>'_');
$str = strtr($str);
return $str;
}
i create a project to test my skills in php, when i workd in my local server 'easyphp' it works fine but when i upload it to my free host i got some probleme.
1- some form that add data to database table works fine but one of my forms it work and but the nothing in the database no data add
if (isset($_POST["envoyer"]))
{
if(empty($_POST["situation"]) || empty($_POST["age"]) || empty($_POST["nom"]) || empty($_POST["prenom"]) || empty($_POST["adress"]) || empty($_POST["ville"]) || empty($_POST["pays"]) )
{
$erreur1="Erreur vous devez remplir tous les champs";
}
else
{
$_POST['nom'] = check_str($_POST['nom']);
$_POST['prenom'] = check_str($_POST['prenom']);
$_POST['adresse'] = check_str($_POST['adresse']);
$_POST['ville'] = check_str($_POST['ville']);
$_POST['pays'] = check_str($_POST['pays']);
$_POST['tele'] = check_str($_POST['tele']);
$_POST['situation'] = check_str($_POST['situation']);
$select = mysql_query("SELECT * FROM `participon` WHERE `nom` = '".$_POST['nom']."' AND `adresse` = '".$_POST['adress']."' ");
//---rechrche si participon deja inscri
$exist = mysql_num_rows($select);
if ($exist > 0)
{
$false= " Votre nom et adresse existe deja, Vous ete deja inscrit";
}
else //if the user name doesn't exist in database
{
$addto= mysql_query("INSERT INTO `participon` SET `nom` = '".$_POST['nom']."', `prenom` = '".$_POST['prenom']."', `adresse` = '".$_POST['adress']."', `ville` = '".$_POST['ville']."', `pays` = '".$_POST['pays']."', `tele` = '".$_POST['tele']."', `situation` = '".$_POST['situation']."', `age` = '".$_POST['age']."' ");
if (isset($addto))
{
$succe="vos information sans ete ajouté avec succee";
}
else
{
$false="erreur";
}
}
}
}
note : the table name is participon and the connection is made successfully and the database is selected successfully
2- an other form allow admin to add a item it works fine but the image name (url) is add as it is (width the special caracters) so the image doesn't appear in the galerie
if (isset($_POST['subm']))
{
if ( !empty($_POST['desi']) or !empty($_POST['argent']) or !empty($_POST['somme']))
{
if(isset($_FILES['image']['tmp_name']) && $_FILES['image']['error']==0 )
{
$folder = "images/";
$file_temp=$_FILES['image']['tmp_name'];
$file_name= check_str(basename($_FILES['image']['name']));
$extentions=array(".jpg", ".png", ".jpeg", ".gif");
$extention=strrchr($file_name, '.');
$max_taille=2000000 ;
$file_taille=filesize($file_temp);
if (!in_array($extention, $extentions))
{
$erreur = "ERREUR votre fichier doit etre une image de type JPEG, JPG, GIF ou PNG";
}
if ( $file_taille > $max_taille)
{
$erreur = "votre fichier depasse la taille maximum";
}
if (!isset($erreur))
{
move_uploaded_file($file_temp, $folder.$file_name);
if ($_FILES['image']['error']==0)
{
$modif="INSERT INTO cadeaux SET designation = '".$_POST['desi']."' , argent = '".$_POST['argent']."' , somme = '".$_POST['somme']."', photo = '".$folder.$file_name."' " ;
mysql_query($modif);
//--vers page cadeaux
header("location:".$path."cadeaux.php?add=ok");
}
}
}
else
{
$modif="INSERT INTO cadeaux SET designation = '".$_POST['desi']."' , argent = '".$_POST['argent']."' , somme = '".$_POST['somme']."' " ;
mysql_query($modif);
//--vers page cadeaux
header("location: ".$path."cadeaux.php?add=ok");
}
}
else{
$erreur = "ERREUR un des champs Designation, Argent ou/et Somme est vide" ;
}
}
note : i want to know if i should us a condition if the image contain spec char return false or the code should change spec char width a valid character
check_str :
function check_str($str)
{
$str = filter_var($str, FILTER_SANITIZE_STRING);
$str = stripslashes($str);
$car_change = array('é'=>'e', 'è'=>'e', '/'=>'_', ' '=>'', '-'=>'_');
$str = strtr($str);
return $str;
}