Results 1 to 10 of 16
Thread: js function help?
-
js function help?
6 Mar 2009 @ 16.30 Hi all,
i need help using php within my js function
here is my function
but it doesnt work, i have included the file on my php page and added the relivant code to a buttonCode:function checkimg(){ if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. $sql="UPDATE ratings SET used_ips = NULL, total_value = 0, total_votes = 0 WHERE id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp')"; $query = mysql_query($sql); alert('Your vote has been counted! Thank you for voting'); unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here alert('Sorry, you have provided an invalid security code'); } }
but nothing happens, and ideasCode:<input type="Button" name="Button" value="Button" onclick="checkimg();"/>
cheers all
Luke
-
7 Mar 2009 @ 18.07 Umm.... checkimg() is a PHP function, but your accessing it as a javascript function. PHP cannot be run from a users machine, only on the server. So you have a few option:
- Make the checkimg() function javascript
- Use the form to submit an HTTP request to the server, and the server handles the PHP
- Use Javascript AJAX to send a request to the server
HTML Code:<form method="POST" action="checkimg.php"> <input type="Button" name="Button" value="Button" /> </form>
-
9 Mar 2009 @ 14.08 hi mate, i never knew you could do that lol
will give it a go see how i get on
thanks for your help
Luke
-
9 Mar 2009 @ 15.02 Great help CV, cheers,
Oh, and Luke; happy birthday for today ;o)
-
-
9 Mar 2009 @ 16.20 @ CV,
Hi mate,
have tried what you suggested but i cant get anything to work
here is my form page
and my checkimg.php page codePHP Code:<?php
session_start();
require('functions.php');
require('_drawrating.php');
include_once('db101.php');
require('checkimg.php');?>
<link rel="stylesheet" type="text/css" href="stylesheets/common_stylesheet.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/stores_stylesheet.css" />
<link rel="stylesheet" type="text/css" href="css/rating.css" />
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<style type="text/css">
<!--
.apDiv1 {
width:200px;
height:115px;
float:left;
}
.style2 {font-size: 12px}
-->
</style>
<div id="subcontent" style="position:absolute; border: 7px solid black; background-color: white; width: 294px; height:361px; padding: 8px;">
<form method="POST" action="checkimg.php">
<div id="apDiv1">
<table width="294" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="167"><span class="ratingscat_head">Value for money</span></td>
<td width="119"><span class="storeRatings_Individual"><?php print rating_bar('valuetemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">Ease of use</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('easeofusetemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">Delivery time</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('deliverytemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">P&P costs</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('delchargetemp',5)?></span></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><label for="label"><span class="style2">Please Enter Security Code: </span></label></td>
</tr>
<tr>
<td colspan="2"><input id="security_code" name="security_code" type="text" /></td>
</tr>
<tr>
<td><?php echo $message101; ?></td>
<td> </td>
</tr>
<tr>
<td><input type="Button" name="Button" value="Button" />
</td>
<td><a href="javascript:dropdowncontent.hidediv('subcontent')">Close</a></td>
</tr>
</table>
</form>
<P>
</div>
<script type="text/javascript">
//Call dropdowncontent.init("anchorID", "positionString", glideduration, "revealBehavior") at the end of the page:
dropdowncontent.init("ratelink", "right-bottom", 600, "mouseover")
dropdowncontent.init("contentlink", "left-top", 300, "click")
</script>
any ideas why this isnt working?PHP Code:<?php
function checkimg (){;
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$sql="UPDATE ratings
SET
used_ips = NULL,
total_value = 0,
total_votes = 0
WHERE
id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp')";
$query = mysql_query($sql);
$message101 = 'Your vote has been counted! Thank you for voting';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
$message101 = 'Sorry, you have provided an invalid security code';
}
}
?>
cheers
LukeLast edited by ljackson; 9 Mar 2009 at @ 16.36.
-
9 Mar 2009 @ 16.42 ok i added this to the form page
and im getting an error message sayingPHP Code:ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL);
which is strange as you can see above it is clearly definedCode:Notice: Undefined variable: message101 in /customers/kernow-connect.com/kernow-connect.com/httpd.www/form.php on line 69

any ideas?
Luke
ok i have defined the varible in the form page which gets rid of the error but the page still isnt checking the image?Last edited by ljackson; 9 Mar 2009 at @ 17.16.
-
9 Mar 2009 @ 20.09 The checkimg.php file only contains a function. Functions are only run when called. Since you never call the function, it won't run. Just take out the function and you'll be good.
Also, as it is now out of the function, it will run when called by form.php with the code require('checkimg.php');
Also, since checkimg is a standalone file, you'll need to connect to the database in it, since it isn't associated with form.php anymore.
-
9 Mar 2009 @ 20.31 hi mate, i think i have done what you suggested above and im now getting a message saying "
Notice: Undefined index: security_code in /customers/kernow-connect.com/kernow-connect.com/httpd.www/checkimg.php on line 17"
i tried adding require('form.php'); to my checkimg.php file but it gave more errors about session value already being defined or something similar.
this is what my new checkimg.php file looks like
any ideasPHP Code:<?php
$user_name = "";
$password = "";
$database = "";
$server = "";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if (!$db_found) {
die('Could not connect: ' . mysql_error());
}
mysql_query("SET NAMES 'utf8'");
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$sql="UPDATE ratings
SET
used_ips = NULL,
total_value = 0,
total_votes = 0
WHERE
id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp')";
$query = mysql_query($sql);
$message101="Your vote has been counted! Thank you for voting";
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
$message101="Sorry, you have provided an invalid security code";
}
?>
Cheers
-
9 Mar 2009 @ 22.00 Then that means that $_SESSION['security_code'] isn't defined. You can use isset() to check if it is defined without passing an error.
Similar Threads
-
ASP Mail function
By stu2000 in forum PHP, ASP & JavaReplies: 1Last Post: 28 Sep 2011, @ 07.02 -
help pls... javascript click option in same function
By oldgoat in forum Javascript LibrariesReplies: 6Last Post: 19 Dec 2010, @ 16.16 -
redirecting a page with additional function
By Dre in forum General Design & Development IssuesReplies: 2Last Post: 31 Aug 2010, @ 17.20 -
I will be so grateful - assigning function to links not working
By Jack Franklin in forum Javascript LibrariesReplies: 2Last Post: 19 May 2009, @ 16.14 -
PHP Copy() function
By stu2000 in forum PHP, ASP & JavaReplies: 3Last Post: 20 Jan 2009, @ 19.52



LinkBack URL
About LinkBacks











Help needed please
Can you link to a web page showing the problem? That makes it much...