I have a PHP code that monitors my credits for our clients. If the client reaches 0 credits the php should not go to the desired page but to a page that will direct him to a notification page that he is low or has no credits
<script>
function validateForm()
{
var x=document.forms["lbs_trace"]["lbs_case"].value;
var y=document.forms["lbs_trace"]["lbs_reason"].value;
var count = 0;
if (!(x==null || x==""))
{
count++;
}
if (!(y==null || y==""))
{
count++;
}
if(count < 2){
alert("Please complete CASE / RA number and REASON for trace");
return false;
}
}
</script>
<?php
// Database Passwords
$host="localhost"; // Host name
$username="stingin_epanic"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="TEST_credits"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM TEST_credits WHERE id='1'");
?>
<?php
$crds=0;
while($rows=mysql_fetch_array($result)){
?>
<span class="blue11" style="font-size: 12px"><span class="blue11" style="font-size:
12px"> </span>
<label for="credit"></label>
<input type="text" name="credit" value="<?php echo $rows['credits']; ?>" id="credit"
/>
<?php
if($rows['credits'] > 0)
{
$crds=1;
}
}
if($crds==0)
{
header("Location:../main.php");
}
?>
</span>
<form method="post" action="../lbs/lbs_record.php" name="lbs_trace" onsubmit="return
validateForm()">
I had it working great all I added was the validateForm() to make sure that the fields are completed. Previously I just posted the form and it worked. Could this be the reason?