Hi guys, this is the exact problem.
I have a form which I wanna pass the variable to a php script. I know variables are not passed to server side scripts unless a page is posted or reloaded.
But I dunno, if anybody has a way of going around this- there are always ways to go around issues😃 it's just dat I anit opportuned to know this.
🙂)And I really need your help.
<html>
<head>
<title>Welcome to Vibe Downloads.com</title>
<script src="xmlhttp.js"></script>
<script language="JavaScript" type="text/JavaScript">
function validateform(formobject)
{
var formreturnvalue = true;
//Check for Empty Voucher
if (formobject.voucher.value == "")
{
window.alert("Type your Voucher name, Please!");
formobject.voucher.focus();
formreturnvalue = false;
return formreturnvalue;
}
if (formobject.voucher.value != "")
{
<?php
// connect to database
include 'db.php';
//*************Problem is here *******************
// I wanna pass the value of the HTML form voucher to my PHP script for processing
$v = $_POST['voucher']; //I think voucher will still be empty cos page has not yet being posted, Is there another way around this?
?>
window.alert("<?php echo $v;?>");
<?php
$res = mysql_query("SELECT Voucherno FROM Vouchers WHERE Voucherno = '$v' AND VoucherStatus = Used");
if (mysql_num_rows($res) > 0)
{
$VoucherStatus = 'Used';
}
else
{
$VoucherStatus = 'Invalid';
}
mysql_close($link);
?>
var VoucherStatus = "<?php echo $VoucherStatus;?>";
if (VoucherStatus == "Used")
{
//window.alert(VoucherStatus);
formreturnvalue = false;
return formreturnvalue;
}
if (VoucherStatus == "Invalid")
{
window.alert(VoucherStatus);
formreturnvalue = false;
return formreturnvalue;
}
formreturnvalue = true;
return formreturnvalue;
}
return formreturnvalue;
}
</script>
</head>
<center>
<body >
<?php
if ((!isset($_POST['registersubmit'])))
{//
?>
<form name="myform" action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
<br>
<table>
<tr>
<td align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Voucher No.</font></td>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
<input type="text" name="voucher">
</font></td>
</tr>
<tr align="center">
<td colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"><br>
<input name="registersubmit" type="submit" value="Register" onClick="return validateform(myform)">
<input name="reset" type="reset" value="reset">
</font></td>
</tr>
</table>
</form>
<?php
}
else
{
//Save Customer info to database here
// SaveContact();
//Send Ringtone here
// SendRingTone();
?>
</table>
</body>
</center>
</html>