Bonjour,
J'ai un petit souci! Je suis débutant et j'apprend PHP/MySQL depuis 2 jours en regardant le plus de tutoriels possible.
mais ce problème, je vois pas comment faire. J'arrive a faire appraitre l'information de la table client en test via echo mais quand je clique inscription ca me dit user_id cannot be null
J'ai deux table - une clients et l'autre annnonces
| client |
annonces |
| id |
annonce_id |
| prenom |
annonce_titre |
| nom |
annonce_description |
| email |
user_id |
| password |
Dans ma page ajouter annonce, je veux ajouter le (id) du client dans le (user_id) de la table annonce quand il fait son inscription
j'y arrive pas :(
Voici le code (dsl pour le code Dreamweaver)
<?php require_once('Connections/ma_db.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;
}
}
$editFormAction = $_SERVER'PHP_SELF'];
if (isset($_SERVER'QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER'QUERY_STRING']);
}
if ((isset($_POST"MM_insert"])) && ($_POST"MM_insert"] == "annonce")) {
$insertSQL = sprintf("INSERT INTO annonces (annonce_id, user_id, annonce_titre, annonce_description) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST'annonce_id'], "int"),
GetSQLValueString($_POST'user_id'], "int"),
GetSQLValueString($_POST'annonce_titre'], "text"),
GetSQLValueString($_POST'annonce_description'], "text"));
mysql_select_db($database_ma_db, $ma_db);
$Result1 = mysql_query($insertSQL, $ma_db) or die(mysql_error());
$insertGoTo = "ok";
if (isset($_SERVER'QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER'QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_ma_db, $ma_db);
$query_rsClient = "SELECT clients.id, clients.prenom, clients.nom, clients.email FROM clients";
$rsClient = mysql_query($query_rsClient, $ma_db) or die(mysql_error());
$row_rsClient = mysql_fetch_assoc($rsClient);
$totalRows_rsClient = mysql_num_rows($rsClient);
mysql_select_db($database_ma_db, $ma_db);
$query_rsannonce = "SELECT * FROM annonces";
$rsannonce = mysql_query($query_rsannonce, $ma_db) or die(mysql_error());
$row_rsannonce = mysql_fetch_assoc($rsannonce);
$totalRows_rsannonce = mysql_num_rows($rsannonce);
?>
<!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>Ajouter annonce</title>
</head>
<body>
test echo le id: <?php echo $row_rsClient'id']; ?> le prenom <?php echo $row_rsClient'prenom']; ?> nom de famille <?php echo $row_rsClient'nom']; ?> email <?php echo $row_rsClient'email']; ?>
<form id="annonce" name="annonce" method="POST" action="<?php echo $editFormAction; ?>">
<table width="653" cellspacing="0" cellpadding="0">
<tr>
<td width="183">Titre</td>
<td width="692"><input type="text" name="annonce_titre" id="titre" /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="annonce_description" id="annonce_description" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><input name="user_id" type="hidden" /><input type="hidden" name="id" /><input type="hidden" name="annonce_id" /></td>
<td><input type="submit" name="submit" id="submit" value="Inscription" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="annonce" />
</form>
</body>
</html>
<?php
mysql_free_result($rsClient);
mysql_free_result($rsannonce);
?>