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);
?>