Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/09/2014, 15:20
Musiker
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Insertar contenido estando logueado

Hola, gracias por responder. Por si ayuda a algo, diré que lo estoy haciendo en dreamweaver. Intenté anteriormente tomar el nombre del usuario mediante la variable de sesión, haciendo esto:
Código PHP:
Ver original
  1. $usuario_sesion = $_SESSION['MM_Username'];
y así poder insertarla después en la base de datos, pero no me resultó y lo borré. Sé muy poco de PHP y lo estoy haciendo como puedo con videos de youtube, foros, etc, por eso está todo tan "raro" :) Espero no confundir mucho y perdón por las molestias :)


INSERTAR.PHP
Código PHP:
Ver original
  1. <?php
  2.  
  3. $recibo_area=$_POST['editor1'];
  4.  
  5. require('connect_db.php');
  6.  
  7. mysql_query("INSERT INTO tabla(AQUÍ LA DUDA PORQUE DEBERÍA IR EL USUARIO,historias,fecha,Hora) VALUES (AQUÍ LA DUDA PORQUE DEBERÍA IR EL USUARIO, '$_REQUEST[editor1]',NOW(),current_time)",$link)
  8. or die("Problemas en el select".mysql_error());
  9.     mysql_close($link);
  10.             echo 'Se ha insertado correctamente.';
  11.  
  12. ?>

INDEX.PHP:
Código PHP:
Ver original
  1. <?php require_once('Connections/prueba.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33. ?>
  34. <?php
  35. // *** Validate request to login to this site.
  36. if (!isset($_SESSION)) {
  37. }
  38.  
  39. $loginFormAction = $_SERVER['PHP_SELF'];
  40. if (isset($_GET['accesscheck'])) {
  41.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  42. }
  43.  
  44. if (isset($_POST['textfield'])) {
  45.   $loginUsername=$_POST['textfield'];
  46.   $password=$_POST['textfield2'];
  47.   $MM_fldUserAuthorization = "";
  48.   $MM_redirectLoginSuccess = "sesion.php";
  49.   $MM_redirectLoginFailed = "dreamweaver2.php";
  50.   $MM_redirecttoReferrer = false;
  51.   mysql_select_db($database_prueba, $prueba);
  52.  
  53.   $LoginRS__query=sprintf("SELECT usuario, correo FROM concurso WHERE usuario=%s AND correo=%s",
  54.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  55.    
  56.   $LoginRS = mysql_query($LoginRS__query, $prueba) or die(mysql_error());
  57.   $loginFoundUser = mysql_num_rows($LoginRS);
  58.   if ($loginFoundUser) {
  59.      $loginStrGroup = "";
  60.    
  61.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  62.     //declare two session variables and assign them
  63.     $_SESSION['MM_Username'] = $loginUsername;
  64.     $_SESSION['MM_UserGroup'] = $loginStrGroup;      
  65.  
  66.     if (isset($_SESSION['PrevUrl']) && false) {
  67.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  68.     }
  69.     header("Location: " . $MM_redirectLoginSuccess );
  70.   }
  71.   else {
  72.     header("Location: ". $MM_redirectLoginFailed );
  73.   }
  74. }
  75. ?>
  76. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  77. <html xmlns="http://www.w3.org/1999/xhtml">
  78. <head>
  79. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  80. <title>Documento sin título</title>
  81.  
  82.   <script src="ckeditor/ckeditor.js"></script>
  83.  <script>
  84.     window.onload = function() {
  85.         CKEDITOR.replace( 'editor1' );
  86.     };
  87. </script>
  88.  
  89. </head>
  90.  
  91. <body>
  92. <div align="center">
  93.   <table width="962" height="513" border="1">
  94.     <tr>
  95.       <td colspan="3">
  96.     </tr>
  97.     <tr>
  98.       <td><div align="center"> <form method="POST" action="insertar.php">
  99.             <textarea name="editor1" id="editor1" rows="10" cols="80">
  100.                 This is my textarea to be replaced with CKEditor.
  101.             </textarea>
  102.             <script>
  103.                 // Replace the <textarea id="editor1"> with a CKEditor
  104.                 // instance, using default configuration.
  105.                 CKEDITOR.replace( 'editor1' );
  106.             </script><p>
  107.        <input type="submit"> <input type="reset"></p></p>
  108.  </form><?php
  109.             if (isset($_POST['submit'])) {
  110.                 require("insertar.php");
  111.             }?>
  112. </div></td>
  113.       <th><div align="center">
  114.     </tr>
  115.     <tr>
  116.       <td><div align="center">
  117.         <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  118.           <p>
  119.             <label for="textfield">Correo</label>
  120.             <input type="text" name="textfield" id="textfield" />
  121.           </p>
  122.           <p>
  123.             <label for="textfield2">Contraseña</label>
  124.             <input type="text" name="textfield2" id="textfield2" />
  125.           </p>
  126.           <p>
  127.             <input type="submit" name="button" id="button" value="Acceder" />
  128.           </p>
  129.         </form>
  130.       </div></td>
  131.       <td><div align="center"></div></td>
  132.       <td><div align="center"></div></td>
  133.     </tr>
  134.   </table>
  135. </div>
  136. </body>
  137. </html>