PHP & javascript

  • demonmaestro
  • Gold Member
  • Gold Member
  • Avatar de Usuario
  • Registrado: Jun 21, 2006
  • Mensajes: 480
  • Loc: Conroe, Texas
  • Status: Offline

Nota Octubre 20th, 2012, 5:01 am

Estoy tratando de hacerlo una vez que el usuario hace clic en un campo que sale pidiendo "nueva" información poner en un cuadro de mensaje y una vez que el usuario hace clic ok entradas en la base de datos. todos su haciendo nada introduce en la base de datos. así que si había algo allí. lo borra.

Funciona si sus duro configurar datos pero su no tomando el valor de X y ponerlo en la base de datos.

por lo que el valor de x es el nombre que el usuario ponga en


Código: [ Select ]
      <script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");

if (msg!=null)
 {
     
     x="" + msg + "";
 <? $x1= "message"; /*this has to be hard set. it works*/
   $x2= $x ;
 $database->name($user, $x1, $x2);?>
 }
}
</script>
  1.       <script>
  2. function msg()
  3. {
  4. var message=prompt("Please enter your msg","<? echo $user;?>");
  5. if (msg!=null)
  6.  {
  7.      
  8.      x="" + msg + "";
  9.  <? $x1= "message"; /*this has to be hard set. it works*/
  10.    $x2= $x ;
  11.  $database->name($user, $x1, $x2);?>
  12.  }
  13. }
  14. </script>
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Octubre 20th, 2012, 5:01 am

  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Octubre 20th, 2012, 6:12 am

Lo siento, creo que está haciendo mal. Necesita crear una dirección URL con JavaScript y enviar el usuario allí.

JAVASCRIPT Código: [ Select ]
window.location.href = "page.php?x=" + msg;


Luego page.php sería tomar esa variable, lo Desinfecte y hacer la edición de base de datos.

Por ejemplo, en su actual página/pup-up tienes:

Código: [ Select ]
<script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");

if (msg!=null)
{
   window.location.href = "page.php?x=" + msg;
}
}
</script>
  1. <script>
  2. function msg()
  3. {
  4. var message=prompt("Please enter your msg","<? echo $user;?>");
  5. if (msg!=null)
  6. {
  7.    window.location.href = "page.php?x=" + msg;
  8. }
  9. }
  10. </script>


y luego en page.php usted tendría el siguiente código:

PHP Código: [ Select ]
<?php
$x1 = "message"; /*this has to be hard set. it works*/
$x2 = sanitize($_GET['x']);
$database->name($user, $x1, $x2);
?>
  1. <?php
  2. $x1 = "message"; /*this has to be hard set. it works*/
  3. $x2 = sanitize($_GET['x']);
  4. $database->name($user, $x1, $x2);
  5. ?>


Lo que tienes ahora:

Código: [ Select ]
   <script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");

if (msg!=null)
{
  
   x="" + msg + "";
<? $x1= "message"; /*this has to be hard set. it works*/
  $x2= $x ;
$database->name($user, $x1, $x2);?>
}
}
</script>
  1.    <script>
  2. function msg()
  3. {
  4. var message=prompt("Please enter your msg","<? echo $user;?>");
  5. if (msg!=null)
  6. {
  7.   
  8.    x="" + msg + "";
  9. <? $x1= "message"; /*this has to be hard set. it works*/
  10.   $x2= $x ;
  11. $database->name($user, $x1, $x2);?>
  12. }
  13. }
  14. </script>


1. Para establecer una variable en javascript creo que necesita la palabra var delante del nombre de la variable var x = msg;
2. Intenta utilizar una variable de JavaScript en PHP. PHP no tiene una variable $x establece, así su justa en blanco (con sorpresa que no está recibiendo un error)


EDITAR:

JAVASCRIPT Código: [ Select ]
      <script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");
 
if (msg!=null)
 {
     
     x="" + msg + "";
 [b]<?[/b] $x1= "message"; /*this has to be hard set. it works*/
   $x2= $x ;
 $database->name($user, $x1, $x2);?>
 }
}
</script>
 
I think you put the starting PHP tags too early... I think you meant to put them here....
 
      <script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");
 
if (msg!=null)
 {
     
    [b]<?[/b]  x="" + msg + "";
 $x1= "message"; /*this has to be hard set. it works*/
   $x2= $x ;
 $database->name($user, $x1, $x2);?>
 }
}
</script>
  1.       <script>
  2. function msg()
  3. {
  4. var message=prompt("Please enter your msg","<? echo $user;?>");
  5.  
  6. if (msg!=null)
  7.  {
  8.      
  9.      x="" + msg + "";
  10.  [b]<?[/b] $x1= "message"; /*this has to be hard set. it works*/
  11.    $x2= $x ;
  12.  $database->name($user, $x1, $x2);?>
  13.  }
  14. }
  15. </script>
  16.  
  17. I think you put the starting PHP tags too early... I think you meant to put them here....
  18.  
  19.       <script>
  20. function msg()
  21. {
  22. var message=prompt("Please enter your msg","<? echo $user;?>");
  23.  
  24. if (msg!=null)
  25.  {
  26.      
  27.     [b]<?[/b]  x="" + msg + "";
  28.  $x1= "message"; /*this has to be hard set. it works*/
  29.    $x2= $x ;
  30.  $database->name($user, $x1, $x2);?>
  31.  }
  32. }
  33. </script>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 243 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC