aiuto con dreamweaver

atarux77

Nuovo Utente
11 Feb 2010
2
0
0
ciao a tutti.
Ho realizzato una pagina di log in collegata a database mysql con dreamweaver, il ilog rimanda a una pagina x inserisre dei post. il mio problema e che avrei bisogno di recuperare l'id dell'utente loggato x inserirlo nel post ma nn ne sono capace :-(

le due pagine sono queste

login

<?php require_once('Connections/rooms.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

mysql_select_db($database_rooms, $rooms);
$query_Recordset1 = "SELECT * FROM utenti";
$Recordset1 = mysql_query($query_Recordset1, $rooms) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['nome_room'])) {
$loginUsername=$_POST['nome_room'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "inserimentopost.php";
$MM_redirectLoginFailed = "loginfailed.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_rooms, $rooms);

$LoginRS__query=sprintf("SELECT nome_room, password FROM utenti WHERE nome_room=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $rooms) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!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" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body>
<table width="100%" border="1">
<tr>
<td width="25%"> </td>
<td width="50%"><table width="100%" border="1">
<tr>
<td> </td>
</tr>
<tr>
<td><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="100%" border="1">
<tr>
<td>utente</td>
<td><label>
<input type="text" name="nome_room" id="nome_room" />
</label></td>
</tr>
<tr>
<td>password</td>
<td><label>
<input type="password" name="password" id="password" />
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Invia" />
</label></td>
</tr>
</table>
</form>

</td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td width="25%"> </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>



e la pagina del form





<?php require_once('Connections/rooms.php'); ?><?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "loginfailed.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO post (id_room, titolo, testo) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['hiddenField'], "int"),
GetSQLValueString($_POST['titolo'], "text"),
GetSQLValueString($_POST['testo'], "text"));

mysql_select_db($database_rooms, $rooms);
$Result1 = mysql_query($insertSQL, $rooms) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO post (titolo, testo) VALUES (%s, %s)",
GetSQLValueString($_POST['titolo'], "text"),
GetSQLValueString($_POST['testo'], "text"));

mysql_select_db($database_rooms, $rooms);
$Result1 = mysql_query($insertSQL, $rooms) or die(mysql_error());
}

mysql_select_db($database_rooms, $rooms);
$query_post = "SELECT * FROM post";
$post = mysql_query($query_post, $rooms) or die(mysql_error());
$row_post = mysql_fetch_assoc($post);
$totalRows_post = mysql_num_rows($post);

$colname_Recordset1 = "-1";
if (isset($_POST['$UserName'])) {
$colname_Recordset1 = $_POST['$UserName'];
}
mysql_select_db($database_rooms, $rooms);
$query_Recordset1 = sprintf("SELECT id_room FROM utenti WHERE nome_room = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $rooms) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_rooms, $rooms);
$query_Recordset2 = "SELECT * FROM post";
$Recordset2 = mysql_query($query_Recordset2, $rooms) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?><!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" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body>
<table width="100%" border="1">
<tr>
<td width="25%"> </td>
<td width="25%"><table width="100%" border="1">
<tr>
<td> </td>
</tr>
<tr>
<td><form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="100%" border="1">
<tr>
<td>titolo</td>
<td><label>
<input type="text" name="titolo" id="titolo" />
</label></td>
</tr>
<tr>
<td>testo</td>
<td><label>
<textarea name="testo" id="testo" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Invia" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td width="25%"> </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($post);

mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>




spero che qualcuno sia in grado di aiutarmi.
grazie a chiunque risponda
 
puoi crearti una sessione che contenga l'id dell'utente loggato
 

Discussioni simili