Sorry, I think you're doing it wrong. You need to build a URL with the JavaScript and send the user there.
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:
<script>
function msg()
{
var message=prompt("Please enter your msg","<? echo $user;?>");
if (msg!=null)
{
window.location.href = "page.php?x=" + msg;
}
}
</script>
- <script>
- function msg()
- {
- var message=prompt("Please enter your msg","<? echo $user;?>");
- if (msg!=null)
- {
- window.location.href = "page.php?x=" + msg;
- }
- }
- </script>
and then in page.php you would have the following code:
<?php
$x1 = "message"; /*this has to be hard set. it works*/
$x2 = sanitize($_GET['x']);
$database->name($user, $x1, $x2);
?>
- <?php
- $x1 = "message"; /*this has to be hard set. it works*/
- $x2 = sanitize($_GET['x']);
- $database->name($user, $x1, $x2);
- ?>
What you have now:
<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>
- <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. 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:
<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>
- <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>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8