Mostrar el autor del post
Hola, bien mi duda es como motrar el autor de un post, ya tengo el campo autor en la base de dato, pero cuendo pongo algo como esto en ver_post.php:
Alguien sabe que hacer? muchas gracias!
<?php echo $row_SacarPostGet['autor'];?>Me sale un 0 en todos los post, por mas que lo haya creado con otra cuenta...
Alguien sabe que hacer? muchas gracias!
0
Puntos
Puntos
1355
Visitas
Visitas
11
Resp
Resp
Por rhcp-hero hace 122 meses
Principiante
Respuesta #1
bueno eso es algo muy similar el codigo que tienes tienes que madar un par de parametros
Espero que te sirba de algo (:
<?php echo autor($row_SacarPostGet['autor']);?>ej yo le pado el autor eso depende tus archivo functions dode busca el autor
Espero que te sirba de algo (:
0
Puntos
Puntos
Por fc2014 hace 122 meses
Experto
Respuesta #2
si te sale un 0 con todos los autores es por que no estas guardando la id al crear el post, si dejas por aquí el código que hace el INSERT a tu base de datos te lo podemos corregir
5
Puntos
Puntos
Por alber hace 122 meses
Administrador
Respuesta #3
Aqui esta el codigo alber:
<?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; } } mysql_select_db($database_conexion, $conexion); $query_Recordset1 = "SELECT * FROM z_posts"; $Recordset1 = mysql_query($query_Recordset1, $conexion) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <?php require_once('Connections/conexion.php'); $iddelpost= $_GET['date']; $updateSQL = sprintf("UPDATE z_posts SET visitas= visitas +1 WHERE id=%s", GetSQLValueString($iddelpost, "int")); mysql_select_db($database_conexion, $conexion); $Result1 = mysql_query($updateSQL, $conexion) or die(mysql_error()); mysql_select_db($database_conexion, $conexion); $query_SacarPostGet = sprintf("SELECT * FROM z_posts WHERE id=%s",$iddelpost,"int"); $SacarPostGet = mysql_query($query_SacarPostGet, $conexion) or die(mysql_error()); $row_SacarPostGet = mysql_fetch_assoc($SacarPostGet); $totalRows_SacarPostGet = mysql_num_rows($SacarPostGet); mysql_free_result($SacarPostGet); ?>Gracias fc2014 por responder, pero no me funciono...
0
Puntos
Puntos
Por rhcp-hero hace 122 meses
Principiante
Respuesta #4
necesito el INSERT que esta en el archivo que tienes puesto como action del form de la pagina agregar.php, revisalo y lo veras ahí
0
Puntos
Puntos
Por alber hace 122 meses
Administrador
Respuesta #5
Aca te lo dejo, no se si es esto lo que buscabas:
Muchas gracias y saludos.
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table width="380" height="271" > <tr valign="baseline"> <td align="left" valign="middle">Titulo:<br /><input name="titulo" type="text" id="editurk" value="" size="32" /> <div id="notic"> <p> <a href="agregarn.php">Noticias</a></div> <div id="musica"><p> Musica</div> <br /> <br /> <div id="tupac">Tu post se publicara en el inicio.</div> <br /></td> </tr> <tr valign="baseline"> <td> <form action"" method="POST"> <textarea class="tinyMCE" name="mensajes" id="tinyMCE"></textarea> </form> <br /> </td> </tr> <tr valign="baseline"> <td>Etiquetas (Separarlas por una coma)<br /> <input name="keywords" type="text" id="editurk" value="" size="32" /> <br /> <br /></td> </tr> <tr valign="baseline"> <td>Categoria<br /> <select name="categoria"> <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Cat 1</option> <option value="2" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Cat 2</option> <option value="3" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Cat 3</option> </select> <br /> <br /></td> </tr> <tr valign="baseline"> <td><input name="agrr" type="submit" id="agrr" value="Agregar Post" /></td> </tr> </table> <input type="hidden" name="seo" value="" /> <input type="hidden" name="descripcion" value="" /> <input type="hidden" name="autor" value="<?php echo $_SESSION['MM_Username'];?>" /> <input type="hidden" name="fecha" value="Publicado el <?php echo date("d/m/Y") . " a las " . date("H:i:s")?>" /> <input type="hidden" name="MM_insert" value="form1" /> </form>Discula si no es eso, pasa que soy medio nuevo y no entiendo..
Muchas gracias y saludos.
0
Puntos
Puntos
Por rhcp-hero hace 122 meses
Principiante
Respuesta #6
rhcp-hero
Chequea que en tu archivo conexion.php (o el archivo que se encuentra en la carpeta Connection) tengas
Saludos :)
Chequea que en tu archivo conexion.php (o el archivo que se encuentra en la carpeta Connection) tengas
$_SESSION['MM_Username'];De forma correcta, y si lo tienes, revisa la página de iniciar sesión y chequea que esté bien colocado eso. Si no, muestra el código donde creas el post.
Saludos :)
Respuesta #7
Mmm no, me fije en conections y esta todo bien, sino me fijo algun tutorial en youtube o en internet. Gracias igual por responder!!
0
Puntos
Puntos
Por rhcp-hero hace 122 meses
Principiante
Respuesta #8
Coloca el código de el archivo donde creas el post bro :)
Respuesta #9
Aca te dejo lo que esta antes del head:
<?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 = "user/postcuenta.php.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 require_once('Connections/conexion.php'); ?> <?php require_once('Connections/conexion.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; } } ?> <?php mysql_select_db($database_conexion, $conexion); $query_SacarPostHome = "SELECT * FROM z_posts ORDER BY z_posts.id DESC"; $SacarPostHome = mysql_query($query_SacarPostHome, $conexion) or die(mysql_error()); $row_SacarPostHome = mysql_fetch_assoc($SacarPostHome); $totalRows_SacarPostHome = mysql_num_rows($SacarPostHome); ?> <?php $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } ?> <?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO z_posts (titulo, seo, keywords, descripcion, mensajes, categoria, autor, fecha) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['titulo'], "text"), GetSQLValueString($_POST['titulo'], "text"), GetSQLValueString($_POST['keywords'], "text"), GetSQLValueString($_POST['mensajes'], "text"), GetSQLValueString($_POST['mensajes'], "text"), GetSQLValueString($_POST['categoria'], "int"), GetSQLValueString($_POST['autor'], "int"), GetSQLValueString($_POST['fecha'], "text")); mysql_select_db($database_conexion, $conexion); $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error()); $insertGoTo = "user/publicado.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <!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=iso-8859-1" /> <title>Crear Post</title> <script src="ckeditor/ckeditor.js"></script> <link rel="shortcut icon" type="image/x-icon" href="img/12.ico"> <link rel="stylesheet" type="text/css" href="css/estilos.css"/> <link href='http://fonts.googleapis.com/css?family=Istok+Web:400,700' rel='stylesheet' type='text/css'>Y esto esta abajo del head:
<body background="img/back.jpg" id="all"> <div id="principal"> <div id="head"><a href="index.php"><img src="img/log.png" name="logo" width="275" height="72" id="logo" /></a><br /> </div> <?php include("inc/menu.php"); ?> <div id="lefttt"> <div id="section_ll"> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table width="380" height="271" > <tr valign="baseline"> <td align="left" valign="middle">Titulo:<br /><input name="titulo" type="text" id="editurk" value="" size="32" /> <tr valign="baseline"> <td> <form action"" method="POST"> <textarea class="ckeditor" name="mensajes" id="kkeditor"></textarea> </form> <br /> </td> </tr> <tr valign="baseline"> <td>Etiquetas (Separarlas por una coma)<br /> <input name="keywords" type="text" id="editurk" value="" size="32" /> <br /> <br /></td> </tr> <tr valign="baseline"> <td>Categoria<br /> <select name="categoria"> <option value="null" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>-Seleccionar Categoria-</option> <option value="null" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>-----------------------</option> <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Categoria 1</option> </select> <br /> <br /></td> </tr> <tr valign="baseline"> <td><input name="agrr" type="submit" id="agrr" value="Agregar Post" /></td> </tr> </table> <input type="hidden" name="seo" value="" /> <input type="hidden" name="descripcion" value="" /> <input type="hidden" name="autor" value="<?php echo $_SESSION['MM_Username'];?>" /> <input type="hidden" name="fecha" value="Publicado el <?php echo date("d/m/Y") . " a las " . date("H:i:s")?>" /> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> </div> </div> </div> </body> </html> <?php mysql_free_result($SacarPostHome); ?>
0
Puntos
Puntos
Por rhcp-hero hace 122 meses
Principiante
Respuesta #10
Hola rhcp-hero, creo que ya vi el problema..
En ésta línea
Saludos.
En ésta línea
<input type="hidden" name="autor" value="<?php echo $_SESSION['MM_Username'];?>" />Estás metiendo el nombre de usuario del usuario que está haciendo el post. Mientras que en el código PHP arriba del head, aproximadamente en la línea 103 donde dice ésto
GetSQLValueString($_POST['autor'], "int"),Estás queriendo insertar un valor numérico "int", cambia ese "int" por "text" y prueba y nos comentas :)
Saludos.
Respuesta #11
Hola Jose, gracias por la respuesta, lo prove pero sigue saliendo 0, igual gracias porque eso tambien me generaria problemas cuando pueda solucionar esto
0
Puntos
Puntos
Por rhcp-hero hace 122 meses
Principiante