PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Tue Oct 31, 2006 5:44 pm
I tried:
Code: Select all
command.innerHTML = "<? insertMessage(" + message + "); ?>";
and all it does give it the value of " + message + ". Why? I mean it's only logical that when I use another double, that javascript should know that I'm ending the string and adding a value of a variable. Why does this do this and how can I make this work?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Oct 31, 2006 5:58 pm
PHP parsed it long before Javascript even knew what was there.
edit: spelling oops.
Last edited by
feyd on Tue Oct 31, 2006 6:28 pm, edited 1 time in total.
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Tue Oct 31, 2006 6:27 pm
Oh I see. Well how do I do this correctly:
Code: Select all
<html>
<head>
<?
function insertMessage($message)
{
$connection = mysql_connect("db2.awardspace.com:3306", "figaro_figaro", "mokicat") or die(mysql_error());
mysql_select_db('figaro_figaro') or die('Could not select database');
$sql = "INSERT INTO IMGClient (message) VALUES ('$message')";
$results = mysql_query($sql, $connection);
}
?>
<script>
function onLoad()
{
command = document.getElementById("command");
}
function sendMessage(message)
{
command.innerHTML = "<? insertMessage(" + message + "); ?>";
}
</script>
</head>
<body onload="onLoad();">
<textarea id="messages" cols="50" rows="10"></textarea></br>
<textarea id="message" cols="50" rows="1"></textarea><button style="position:relative; top: -10; height:30;" onclick="return sendMessage(document.getElementById('message').value);">Send</button>
<div id="command"></div>
</body>
</html>
How do I place the value of the JS variable message in between the brackets of the php function:
Code: Select all
command.innerHTML = "<? insertMessage(" + message + "); ?>";
???
Last edited by
JellyFish on Tue Oct 31, 2006 6:34 pm, edited 2 times in total.
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Wed Nov 01, 2006 12:18 am