php & javascript

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 676
  • Loc: Conroe, Texas

Post 3+ Months Ago

i am trying to make it once the user clicks on a field that a prompt box comes up asking for "new" information to be put in and once the user clicks ok that it inputs it into the database. all its doing is inputting nothing into the database. so if there was something there. it erases it.

It works if its hard set data but its not taking the value of X and putting it into the database.

so the value of x is the name that the user put in


Code: [ 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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Sorry, I think you're doing it wrong. You need to build a URL with the JavaScript and send the user there.

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


Then page.php would take that variable, sanitize it, and do the database editing.

For instance, in your current page/pup-up you have:

Code: [ 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>


and then in page.php you would have the following code:

PHP Code: [ 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. ?>


What you have now:

Code: [ 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. To set a variable in javascript I think you need the word var in front of the variable name var x = msg;
2. You are trying to use a JavaScript variable in your PHP. PHP does not have a variable $x set, so it's just blank (surprised you're not getting an error)


EDIT:

JAVASCRIPT Code: [ 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>

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.