Código PHP:
<?php require_once('Connections/conexion.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 = "index.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($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['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 = "")
{
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"] == "form2")) {
$insertSQL = sprintf("INSERT INTO Noticia (Foto, Temas, text, Video, Nombre, user_id) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Foto'], "text"),
GetSQLValueString($_POST['Temas'], "text"),
GetSQLValueString($_POST['text'], "text"),
GetSQLValueString($_POST['Video'], "text"),
GetSQLValueString($_POST['Nombre'], "text"),
GetSQLValueString($_POST['user_id'], "text"));
mysql_select_db($database_conexion, $conexion);
$Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_cuenta3 = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_cuenta3 = $_SESSION['MM_Username'];
}
mysql_select_db($database_conexion, $conexion);
$query_cuenta3 = sprintf("SELECT * FROM usuario WHERE Usuarios = %s", GetSQLValueString($colname_cuenta3, "text"));
$cuenta3 = mysql_query($query_cuenta3, $conexion) or die(mysql_error());
$row_cuenta3 = mysql_fetch_assoc($cuenta3);
$totalRows_cuenta3 = mysql_num_rows($cuenta3);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>COCINA SORDA 2.0</title>
<link href="themas/htemas.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="contenedor">
<?php include("cabecera.php"); ?>
<?php include("menu.php"); ?>
<div class="contenido">
<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td>Foto<br/><input type="text" name="Foto" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td>Titulo<br/><input type="text" name="Temas" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td>Texto<br/><textarea name="text" cols="32">te escribe</textarea></td>
</tr>
<tr valign="baseline">
<td>http://youtu.be/<input type="text" name="Video" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td><input type="submit" value="Insertar registro"></td>
</tr>
</table>
<input type="hidden" name="Nombre" value="<?php echo $row_cuenta3['Nombre']; ?> <?php echo $row_cuenta3['Apellido']; ?>">
<input type="hidden" name="user_id" value="<?php echo $row_cuenta3['id']; ?>">
<input type="hidden" name="MM_insert" value="form2">
</form>
<p> </p>
</div>
<?php include("pie.php"); ?>
</div>
</body>
</html>
<?php
mysql_free_result($cuenta3);
?>