Alors n'hésite pas à indenter ton code et à utiliser un éditeur qui offre la coloration syntaxique (style notepad++)Je début en php !
<?php
if ($totalRows_verifmail == 0)
{
$email = $_POST["email"] ;
//création de la requête SQL:
$sql = "INSERT INTO clients (email) VALUES ( '$email') " ;
//exécution de la requête SQL:
$requete = mysql_query($sql, $conect) or die( mysql_error() ) ;
}
else
{
echo 'mon texte';
}
?><?php require_once('Connections/csonjob.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;
}
}
$colname_verifmail = "-1";
if (isset($_POST['email'])) {
$colname_verifmail = $_POST['email'];
}
mysql_select_db($database_csonjob, $csonjob);
$query_verifmail = sprintf("SELECT email FROM clients WHERE email = %s", GetSQLValueString($colname_verifmail, "text"));
$verifmail = mysql_query($query_verifmail, $csonjob) or die(mysql_error());
$row_verifmail = mysql_fetch_assoc($verifmail);
$totalRows_verifmail = mysql_num_rows($verifmail);
?>
<?php include 'header.php'; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="textebleu">
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<tr>
<td width="50%" align="center" valign="top"><?php // Show if recordset empty
if ($totalRows_verifmail == 0)
{ // Show if recordset empty
//récupération des valeurs du champ email
$email = $_POST["email"] ;
//création de la requête SQL:
$sql = "INSERT INTO clients (email)
VALUES ( '$email') " ;
//exécution de la requête SQL:
$requete = mysql_query($sql, $csonjob) or die( mysql_error() ) ;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="15" background="images/tab2_hg.png"></td>
<td height="15" background="images/tab2_h.png"></td>
<td height="15" background="images/tab2_hd.png"></td>
</tr>
<tr>
<td width="15" background="images/tab2_g.png"></td>
<td align="center" valign="top"><p class="titrebleu"><img src="images/dequelpro.png" width="317" height="60" /></p>
<p class="titrebleu"><span class="textebleu">Un Email contenant vos identifiants de connexion<br />
vient de vous être envoyé à l'adresse suivante : </span><?php echo $_POST['email']; ?></p>
<p class="titrebleu"><span class="textebleu"><br />
</span></p></td>
<td width="15" background="images/tab2_d.png"></td>
</tr>
<tr>
<td height="15" background="images/tab2_bg.png"></td>
<td height="15" background="images/tab2_b.png"></td>
<td height="15" background="images/tab2_bd.png"></td>
</tr>
</table>
<?php } else { // Show if recordset empty ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="15" background="images/tab2_hg.png"></td>
<td height="15" background="images/tab2_h.png"></td>
<td height="15" background="images/tab2_hd.png"></td>
</tr>
<tr>
<td width="15" background="images/tab2_g.png"></td>
<td align="center" valign="top"><p class="titrebleu"><img src="images/dequelpro.png" width="317" height="60" /></p>
<p class="titrebleu"><span class="textebleu">Cette adresse existe déja dans notre base de données !<br />
<br />
Un Email de rappel contenant vos identifiants de connexion<br />
vient de vous être envoyé à l'adresse suivante :</span> <?php echo $_POST['email']; ?></p>
<p class="titrebleu"><br />
</p></td>
<td width="15" background="images/tab2_d.png"></td>
</tr>
<tr>
<td height="15" background="images/tab2_bg.png"></td>
<td height="15" background="images/tab2_b.png"></td>
<td height="15" background="images/tab2_bd.png"></td>
</tr>
</table><?php } ?>
<p> </p></td>
</tr>
</table>
<p class="titrebleu"><br />
</p>
<p class="titrebleu"> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td> </td>
</tr>
</table>
<?php
mysql_free_result($verifmail);
?>
<?php include 'footer.php'; ?>
$query_verifmail = sprintf("SELECT email FROM clients WHERE email = %s", GetSQLValueString($colname_verifmail, "text"));
print "<br>requete =>$query_verifmail<=="; // pour s'assurer de ce qu'on demande
$verifmail = mysql_query($query_verifmail, $csonjob) or die(mysql_error());
$row_verifmail = mysql_fetch_assoc($verifmail);
$totalRows_verifmail = mysql_num_rows($verifmail);
print "nb lignes==>$totalRows_verifmail<==";
et on cherchera ...
<?php
$sql = 'select count(email) as nbmail from clients where email =\''.mysql_real_escape_string($_POST['email']).'\';';
$ret = mysql_query($sql);
if ($ret === false) echo '<p>Erreur SQL : '.mysql_error().'<br />'.$sql.'</p>';
else {
$data = mysql_fetch_assoc($ret);
if ($data['nbmail'] === 0) '
// OK
}
else {
// KO
}
?>
commence par tester juste le formulaire et ça dans un fichier php voir ce que ça donne (vire tous le reste pour les tests <?php
include 'Connections/conect.php';
$sql = 'select count(email) as nbmail from clients where email =\''.mysql_real_escape_string($_POST['email']).'\';';
$ret = mysql_query($sql);echo $ret;
if ($ret === false) echo '<p>Erreur SQL : '.mysql_error().'<br />'.$sql.'</p>';
else {
$data = mysql_fetch_assoc($ret);
if ($data['nbmail'] === 0) {
// OK
}
else {
// KO
}
?>
Et voici le code erreur retourné :<?php
include 'Connections/conect.php';
$sql = 'select count(email) as nbmail from clients where email =\''.mysql_real_escape_string($_POST['email']).'\';';
$ret = mysql_query($sql);echo $ret;
if ($ret === false)
{
echo '<p>Erreur SQL : '.mysql_error().'<br />'.$sql.'</p>';
}
else
{
$data = mysql_fetch_assoc($ret);
if ($data['nbmail'] === 0)
{
// OK
}
else
{
// KO
}
?>