FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
Newby needs help....verify two text field on Submit click
Message  

Reply with quote
Post Newby needs help....verify two text field on Submit click 
Here's what I have to do after a user clicks the Submit button:
1.  Verify an IDNumber is valid
2.  Verify a password entry is correct

I'm using mySQL as a backend, and the table has two columns:  IDNumber and video.

If 1. and 2. are correct, I update a field, video, to 1 in order to give someone credit for seeing a training video.

I've done a recordset for the first text box in order to return a 1 or 0 to validate the IDNumber, Recordset2.TotalRecords

What I don't know how to do is to take the recordset for the IDNumber, compare it with a variable for the password, and post a value to a label (lblWarning) that the user has issues the the IDNumber or password.........or to tell them they now have credit for seeing the video.

I'm trying the following for a start but getting syntax errors:
<?PHP
If (Recordset2.TotalRecords=1) {lblWarning = "This is a valid IDNumber"}
?>

View user's profile Send private message

Reply with quote
Post  
Can you post your full code so I can see exactly what is going on in the script?

View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger

Reply with quote
Post  
Sure...here it is:

****************************************

<?php require_once('Connections/conn.php'); ?>
<?php
mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM table1";
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset2 = "1";
if (isset($_POST['Znumber'])) {
  $colname_Recordset2 = (get_magic_quotes_gpc()) ? $_POST['Znumber'] : addslashes($_POST['Znumber']);
}
mysql_select_db($database_conn, $conn);
$query_Recordset2 = sprintf("SELECT Znumber FROM table1 WHERE Znumber = %s", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $conn) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

$colname_rsVideoSeenvalue = "1";
if (isset($_POST['Znumber'])) {
  $colname_rsVideoSeenvalue = (get_magic_quotes_gpc()) ? $_POST['Znumber'] : addslashes($_POST['Znumber']);
}
mysql_select_db($database_conn, $conn);
$query_rsVideoSeenvalue = sprintf("SELECT videoseen FROM table1 WHERE Znumber = %s", $colname_rsVideoSeenvalue);
$rsVideoSeenvalue = mysql_query($query_rsVideoSeenvalue, $conn) or die(mysql_error());
$row_rsVideoSeenvalue = mysql_fetch_assoc($rsVideoSeenvalue);
$totalRows_rsVideoSeenvalue = mysql_num_rows($rsVideoSeenvalue);

$colname_rsFindvideoseen = "1";
if (isset($_POST['Znumber'])) {
  $colname_rsFindvideoseen = (get_magic_quotes_gpc()) ? $_POST['Znumber'] : addslashes($_POST['Znumber']);
}
mysql_select_db($database_conn, $conn);
$query_rsFindvideoseen = sprintf("SELECT videoseen FROM table1 WHERE Znumber = %s", $colname_rsFindvideoseen);
$rsFindvideoseen = mysql_query($query_rsFindvideoseen, $conn) or die(mysql_error());
$row_rsFindvideoseen = mysql_fetch_assoc($rsFindvideoseen);
$totalRows_rsFindvideoseen = mysql_num_rows($rsFindvideoseen);
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Video Credit Form</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body>
<p>This Friday page was created at <b>
<?php echo date("h:i:s a", time()); ?>
</b> on the computer running PHP.</p>


 <form name="form1" method="post" action="">
 <Table>
 <TR>
        <TD>Enter your ZNumber:</TD>
    <TD><input name="Znumber" type="text" id="Znumber">
         </TD>
 </TR>
 <TR>
        <TD>Enter the password:</TD>
    <TD><input name="Password" type="text" id="Password"></TD>
 </TR>
</Table>
   <input name="Submit" type="submit" onClick="MM_validateForm('Znumber','','R','txtPassword','','R');return document.MM_returnValue" value="Submit">
       <P>
   <?PHP
          if(isset($totalRows_Recordset2)){
         $IDFound = "This is a valid IDNumber";
         $IDNotFound = "This is not a valid IDNumber";
         If ($totalRows_Recordset2==1)
            {echo $IDFound;}
         Else
            {echo $IDNotFound;}
        }
      ?>
     </P>

 </form>
 <p><?php echo $totalRows_Recordset2 ?>&nbsp;&nbsp;   <?php echo $row_rsFindvideoseen['videoseen']; ?>
</p>

</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

mysql_free_result($rsVideoSeenvalue);

mysql_free_result($rsFindvideoseen);
?>

*******************************************

I've got it working now, but my:
<?PHP
             if(isset($totalRows_Recordset2)){
         $IDFound = "This is a valid IDNumber";
         $IDNotFound = "This is not a valid IDNumber";
         If ($totalRows_Recordset2==1)
            {echo $IDFound;}
         Else
            {echo $IDNotFound;}
        }
      ?>
...this always shows "This is not a valid IDNumber" when the user first sees the page.  How can I resolve this?  Can I run this only on a click even of the Submit button....or do some hiding of the variable?  Any suggestions are welcomed.  I'm coming from ASP.NET, and this is a bit different.  Would like to handle it from the click event..........but don't know how.

View user's profile Send private message

Reply with quote
Post  
The reason you are seeing the "This is not a valid IDNumber" is because when you are checking against the isset( $totalRows_RecordSet2 ) statement, it is always going to return true because you are always setting it to something, even if it is zero.  The best way that I can think of is to protect the first part of the code to look for the $_POST[ 'Submit' ] and make sure that it is set before doing anything.  That way until the user hits the Submit button, the top piece of code is not executed.

Understand what I mean?

View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger

Reply with quote
Post  
Yeah, thanks Outkast!

I just used the following, and it worked:

if (isset($_POST['Znumber'])) {
         $IDFound = "This is a valid IDNumber";
         $IDNotFound = "This is not a valid IDNumber";
         If ($totalRows_Recordset2==1)
            {echo $IDFound;}
         Else
            {echo $IDNotFound;}
        }

View user's profile Send private message

Reply with quote
Post  
You can do that as well.  Good luck with everything else!

View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com