|
-
Jun 15th, 2006, 06:12 AM
#1
Thread Starter
Frenzied Member
Re: on click
i got a weird problem
Code:
<SCRIPT LANGUAGE="JavaScript">
function processAnn () {
answer = confirm('Confirm ' + form1.textarea.value)
if (answer == 1) {
<?
$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
$result = mysql_query($query) or die("Query error<br/>" . mysql_error());
?>
}
}
</SCRIPT>
Code:
<input name="Save" type="submit" class="style11" id="Save" value="Save announcement" onclick="processAnn()" />
now evertime i refresh the page, it ust writes 'hi' to the database :S
so it keeps on doing this
$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
but it should only do that when i click 'Ok' in the confirm msgbox
-
Jun 15th, 2006, 06:17 AM
#2
Re: on click
 Originally Posted by Pouncer
i got a weird problem
Code:
<SCRIPT LANGUAGE="JavaScript">
function processAnn () {
answer = confirm('Confirm ' + form1.textarea.value)
if (answer == 1) {
<?
$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
$result = mysql_query($query) or die("Query error<br/>" . mysql_error());
?>
}
}
</SCRIPT>
Code:
<input name="Save" type="submit" class="style11" id="Save" value="Save announcement" onclick="processAnn()" />
now evertime i refresh the page, it ust writes 'hi' to the database :S
so it keeps on doing this
$query = "UPDATE `announcement` SET `Announcement` = 'hi'";
but it should only do that when i click 'Ok' in the confirm msgbox
Ajax isn't that easy.
-
Jun 15th, 2006, 06:19 AM
#3
Thread Starter
Frenzied Member
Re: on click
ok, but i dont see why it cant work properly, the page is a .php page anyway
cant i have php inside javascript?
how can i go about doing this properly then?
-
Jun 15th, 2006, 06:32 AM
#4
Re: on click
 Originally Posted by Pouncer
ok, but i dont see why it cant work properly, the page is a .php page anyway
cant i have php inside javascript?
how can i go about doing this properly then?
PHP is executed before the pages is sent to the browser. The HTML source code is the output of your PHP script. If you want PHP to execute on a Javascript event you'll either need to use Ajax (which as you are a beginner I do not recommend) or use a link:
Code:
<a href="page.php?action=updateannounce&set=hi">Update Announcement</a>
If your page you'll need to have something like this:
PHP Code:
if (isset($_GET['action'])){
switch ($_GET['action']) {
case 'updateannounce':
update_announcement(@$_GET['set']);
break;
}
}
function update_announcement($text)
{
$text=mysql_escape_string($text);
$query = "UPDATE `announcement` SET `Announcement` = '$text'";
$result = mysql_query($query) or die("Query error<br/>" . mysql_error());
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|