par
tchobec » 10 sept. 2006, 22:03
Bonsoir,
2 ème question depuis que je débute.
J'ai une page formulaire (insert_individu.php) qui insère les données dans une Bdd, jusque là pas de soucis, et qui les renvoit vers une autre page (insert_naissance.php) où je souhaite afficher certaines données provenant du formulaire et insérer d'autres données dans une autre table.
Au départ, dans le fichier insert_naissance.php, j'avais un pb de variable non définie (résolu), puis une erreur "
parse error" sur la ligne 7(résolu), maintenant j'ai une erreur "
Erreur de syntaxe près de ''"' à la ligne 1" la ligne de vérification (6) me donne "
nom=" (vide) et la ligne de vérification (11) me donne le résultat suivant :
SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE '";.
Je crois que l'erreur vient de l'absence de donnée dans la variable $nom avec laquelle je test mais je ne vois pas comment récupérer celle-ci autrement que de cette manière après avoir validé le formulaire.
Pour info, au cas où je serai à côté de la plaque, je souhaite récupérer dans cette page certaines infos des dernières données insérées dans la base.
voici les codes :
fichier insert_individu.php (formulaire)
<?php require_once('Connections/genealogie.php'); ?>
<?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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert_individu")) {
$insertSQL = sprintf("INSERT INTO liste_individus (Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['sosa'], "int"),
GetSQLValueString($HTTP_POST_VARS['generation'], "int"),
GetSQLValueString($HTTP_POST_VARS['nom'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom1'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom2'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom3'], "text"),
GetSQLValueString($HTTP_POST_VARS['sexe'], "text"),
GetSQLValueString($HTTP_POST_VARS['photo'], "int"));
mysql_select_db($database_genealogie, $genealogie);
$Result1 = mysql_query($insertSQL, $genealogie) or die(mysql_error());
$insertGoTo = "insert_naissance.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>INSERTION DES DONNEES</title>
</head>
<body bgcolor="#9999FF">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3" align="center"><strong><font size="4">FORMULAIRE D'INSERTION
DES DONNEES INDIVIDUELLES</font></strong></td>
</tr>
</table>
</div>
<form action="<?php echo $editFormAction; ?>" method="POST" name="insert_individu" id="insert_individu">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="104">NOM :</td>
<td width="445"><input name="nom" type="text" id="nom" maxlength="15"></td>
<td></td>
</tr>
<tr>
<td width="104">PRENOMS :</td>
<td width="445"><input name="prenom1" type="text" id="prenom1" maxlength="15">
<input name="prenom2" type="text" id="prenom2" maxlength="15"> <input name="prenom3" type="text" id="prenom3" maxlength="15">
</td>
<td></td>
</tr>
<tr>
<td width="104">SEXE :</td>
<td width="445"><select name="sexe" id="sexe">
<option value="M">MASCULIN</option>
<option value="F">FEMININ</option>
</select></td>
</tr>
<tr>
<td width="104">SOSA :</td>
<td width="445"><input name="sosa" type="text" id="sosa" maxlength="5">
</td>
</tr>
<tr>
<td width="104">GENERATION </td>
<td width="445"><input name="generation" type="text" id="generation" maxlength="2">
</td>
</tr>
<tr>
<td width="104">PHOTO :</td>
<td width="445"> <select name="photo" id="photo">
<option value="O">OUI</option>
<option value="N">NON</option>
</select></td>
<td width="120"><input type="submit" name="Submit" value="Insérer"></p>
</td>
</tr>
</table>
</div>
<input type="hidden" name="MM_insert" value="insert_individu">
</form>
</body>
</html>
fichier insert_naissance.php
<?php require_once('Connections/genealogie.php'); ?>
<?php
/* Récupération de variables insert_individu.php */
$nom = isset($_POST['nom']) ? $_POST['nom'] : "";
/*test résultat variable */
echo("<p>". $nom ."</p>\n");
/* Requête */
mysql_select_db($database_genealogie, $genealogie);
$query_data_last_individu = "SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE '". $nom .'";';
/* Vérification par affichage de la requête dans le navigateur :
SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE "contenu de $nom";
*/
echo("<p>". $query_data_last_individu ."</p>\n");
/*Suite du code*/
$data_last_individu = mysql_query($query_data_last_individu, $genealogie) or die(mysql_error());
$row_data_last_individu = mysql_fetch_assoc($data_last_individu);
$totalRows_data_last_individu = mysql_num_rows($data_last_individu);
?>
<html>
<head>
<title>RENSEIGNEMENTS NAISSANCE</title>
</head>
<body bgcolor="#9999FF">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3" align="center"><strong><font size="4">FORMULAIRE D'INSERTION DES DONNEES INDIVIDUELLES</font></strong></td>
</tr>
</table>
</div>
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">Vous venez d'insérer l'individu suivant dans la base
de données</td>
</tr>
<tr>
<td> </td>
<td colspan="2"><strong><?php echo $row_data_last_individu['Nom'] ." ". $row_data_last_individu['Prenom1'] ." ". $row_data_last_individu['Prenom2'] ." ". $row_data_last_individu['Prenom3']; ?></strong></td>
</tr>
<tr>
<td width="9%"> </td>
<td width="11%">Sosa </td>
<td width="80%"><?php echo $row_data_last_individu['Sosa']; ?></td>
</tr>
<tr>
<td> </td>
<td>Génération</td>
<td><?php echo $row_data_last_individu['Generation']; ?></td>
</tr>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($data_last_individu);
?>
Quelles solutions pour effectuer ce traitement.
Merci.
Bonsoir,
2 ème question depuis que je débute.
J'ai une page formulaire (insert_individu.php) qui insère les données dans une Bdd, jusque là pas de soucis, et qui les renvoit vers une autre page (insert_naissance.php) où je souhaite afficher certaines données provenant du formulaire et insérer d'autres données dans une autre table.
Au départ, dans le fichier insert_naissance.php, j'avais un pb de variable non définie (résolu), puis une erreur "[i]parse error[/i]" sur la ligne 7(résolu), maintenant j'ai une erreur "[i]Erreur de syntaxe près de ''"' à la ligne 1[/i]" la ligne de vérification (6) me donne "[i]nom=[/i]" (vide) et la ligne de vérification (11) me donne le résultat suivant :
[i]SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE '";[/i].
Je crois que l'erreur vient de l'absence de donnée dans la variable $nom avec laquelle je test mais je ne vois pas comment récupérer celle-ci autrement que de cette manière après avoir validé le formulaire.
Pour info, au cas où je serai à côté de la plaque, je souhaite récupérer dans cette page certaines infos des dernières données insérées dans la base.
voici les codes :
[b]fichier insert_individu.php (formulaire)[/b]
[php]<?php require_once('Connections/genealogie.php'); ?>
<?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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert_individu")) {
$insertSQL = sprintf("INSERT INTO liste_individus (Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['sosa'], "int"),
GetSQLValueString($HTTP_POST_VARS['generation'], "int"),
GetSQLValueString($HTTP_POST_VARS['nom'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom1'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom2'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenom3'], "text"),
GetSQLValueString($HTTP_POST_VARS['sexe'], "text"),
GetSQLValueString($HTTP_POST_VARS['photo'], "int"));
mysql_select_db($database_genealogie, $genealogie);
$Result1 = mysql_query($insertSQL, $genealogie) or die(mysql_error());
$insertGoTo = "insert_naissance.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>INSERTION DES DONNEES</title>
</head>
<body bgcolor="#9999FF">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3" align="center"><strong><font size="4">FORMULAIRE D'INSERTION
DES DONNEES INDIVIDUELLES</font></strong></td>
</tr>
</table>
</div>
<form action="<?php echo $editFormAction; ?>" method="POST" name="insert_individu" id="insert_individu">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="104">NOM :</td>
<td width="445"><input name="nom" type="text" id="nom" maxlength="15"></td>
<td></td>
</tr>
<tr>
<td width="104">PRENOMS :</td>
<td width="445"><input name="prenom1" type="text" id="prenom1" maxlength="15">
<input name="prenom2" type="text" id="prenom2" maxlength="15"> <input name="prenom3" type="text" id="prenom3" maxlength="15">
</td>
<td></td>
</tr>
<tr>
<td width="104">SEXE :</td>
<td width="445"><select name="sexe" id="sexe">
<option value="M">MASCULIN</option>
<option value="F">FEMININ</option>
</select></td>
</tr>
<tr>
<td width="104">SOSA :</td>
<td width="445"><input name="sosa" type="text" id="sosa" maxlength="5">
</td>
</tr>
<tr>
<td width="104">GENERATION </td>
<td width="445"><input name="generation" type="text" id="generation" maxlength="2">
</td>
</tr>
<tr>
<td width="104">PHOTO :</td>
<td width="445"> <select name="photo" id="photo">
<option value="O">OUI</option>
<option value="N">NON</option>
</select></td>
<td width="120"><input type="submit" name="Submit" value="Insérer"></p>
</td>
</tr>
</table>
</div>
<input type="hidden" name="MM_insert" value="insert_individu">
</form>
</body>
</html>
[/php]
[b]fichier insert_naissance.php[/b]
[php]<?php require_once('Connections/genealogie.php'); ?>
<?php
/* Récupération de variables insert_individu.php */
$nom = isset($_POST['nom']) ? $_POST['nom'] : "";
/*test résultat variable */
echo("<p>". $nom ."</p>\n");
/* Requête */
mysql_select_db($database_genealogie, $genealogie);
$query_data_last_individu = "SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE '". $nom .'";';
/* Vérification par affichage de la requête dans le navigateur :
SELECT Ref_individu, Sosa, Generation, Nom, Prenom1, Prenom2, Prenom3, Sexe FROM liste_individus WHERE Nom LIKE "contenu de $nom";
*/
echo("<p>". $query_data_last_individu ."</p>\n");
/*Suite du code*/
$data_last_individu = mysql_query($query_data_last_individu, $genealogie) or die(mysql_error());
$row_data_last_individu = mysql_fetch_assoc($data_last_individu);
$totalRows_data_last_individu = mysql_num_rows($data_last_individu);
?>
<html>
<head>
<title>RENSEIGNEMENTS NAISSANCE</title>
</head>
<body bgcolor="#9999FF">
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3" align="center"><strong><font size="4">FORMULAIRE D'INSERTION DES DONNEES INDIVIDUELLES</font></strong></td>
</tr>
</table>
</div>
<div align="center">
<table width="69%" bgcolor="#99CCFF">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">Vous venez d'insérer l'individu suivant dans la base
de données</td>
</tr>
<tr>
<td> </td>
<td colspan="2"><strong><?php echo $row_data_last_individu['Nom'] ." ". $row_data_last_individu['Prenom1'] ." ". $row_data_last_individu['Prenom2'] ." ". $row_data_last_individu['Prenom3']; ?></strong></td>
</tr>
<tr>
<td width="9%"> </td>
<td width="11%">Sosa </td>
<td width="80%"><?php echo $row_data_last_individu['Sosa']; ?></td>
</tr>
<tr>
<td> </td>
<td>Génération</td>
<td><?php echo $row_data_last_individu['Generation']; ?></td>
</tr>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($data_last_individu);
?>
[/php]
Quelles solutions pour effectuer ce traitement.
Merci.