Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verify Two Text Box Values 3

Status
Not open for further replies.

lanm

Programmer
Jul 7, 2005
244
US
This should be very simple, but I'm having a bit of trouble.

I have two text boxes, a numberID and a password.
I need to:
1. Verify the numberID is a vaild ID in my table from an SQL query (I'm doing that now with a recordset)
2. Make sure the password is valid
3. If numberID is valid, and password is correct, Update column to 1 from value of 0.

This is a simple application, but I am VERY new to PHP. I did it in ASP.NET but it's not supported on the server.
Any suggestions, sampel code or articles would be appreciated.

Thanks! I'm diggin' in my PHP books as we speak.
 
Any suggestions, sampel code or articles would be appreciated.
Insufficient data for a meaningful answer.

PHP supports many database servers through server-specific database function families. These include but are not limited to Firebird/Interbase, IBM DB2, Microsoft SQL Server, MySQL, Oracle and PostgreSQL. PHP also supports ODBC, which gives it access to other database systems non-natively.

Which database are you using?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

I'm using mySQL as the backend. The table has two fields:
1. IDNumber
2. video

"video" shows whether they've seen a training video or not.

I've gotten to where I can do the following:
1. Verify if the IDnumber entered is in the table by a recordset count
2. See if they've seen the video or not

Now...I need to do the following (and this is where I'm not sure to start):
1. Store a password as a variable (shouldn't be hard to do)
2. Do an If Else statement and look at the recordsets in order to post some text on a label to alert the user, or if the condition is right...update "video" to 1 in order to give credit.

Thanks!
 
The table has two fields:
1. IDNumber
2. video

"video" shows whether they've seen a training video or not.
I assume that the above should have read something like "Two of the table's fields are:"


1. Store a password as a variable (shouldn't be hard to do)
I'm not sure what you mean by this. Are all users going to use the same password?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, there are two columns in the table, IDNumber and video.

Yes, they'll have the password from a previous page, and need to type it in the textbox.

I tried an "If" statement off one of my recordsets to put a value in a label, and can't get the syntax right:
<?PHP
If ({Recordset2.TotalRecords})=1 {lblWarning = "You have one record"}
?>

I'm assuming the above "If" statement goes before the <!DOCTYPE HTML PUBLIC.....declaration.
 
Yes, there are two columns in the table, IDNumber and video.
Be precise and explicit. Are you saying:[ul][li]there are exactly two columns in this table, or[/li][li]are there more than two, but that two of them are called "IDNumber" and "video"[/li][/ul]? Because it makes a difference with what the database will support. If it's the former, you have a good database schema for tracking whether a particular video has ever been viewed, regardless of the number of times or by whom or when it was viewed.

they'll have the password
Who's the "they" to which you keep referring? Your users? There will be a password on page1, and when entered in page2 with a valid video ID, the user is granted access?



I'm not sure what you mean here:

{Recordset2.TotalRecords}





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, only two fields in the table.

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"}
?>

 
Let's discuss the recordset "Recordset2". Before I can advise you on how to use it, I have to know what it is. How did you initialize Recordset2?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I believe You are mixing scripting languages, PHP doesnt have a function by the name of lblWarning, Where did you get it from??? Javascript?? Vbscript??
 
Recordset2 is getting the count of the IDNumber the user enters into the first text box. It does a select statement on the table for the IDNumber. This is how I see if the IDNumber is valid or not.
 
vacuntia,

I don't know if I need to make it say lblWarning.Text (like in ASP.NET) or something like that. I'm used to ASP.NET, and this is my first PHP application.

The label, lblWarning, is what I'll use to tell this user if they've got problems or if the update is successful.

Any suggestions!

Thanks!
 
Ianm said:
Recordset2 is getting the count of the IDNumber the user enters into the first text box. It does a select statement on the table for the IDNumber. This is how I see if the IDNumber is valid or not.
I inferred that. Post a code snippet, please. As vacunita has pointed out, although PHP understands OO programming, few of its builtin functions return objects. So I need to know what exactly $Recordset2 [note: all PHP variables must begin with "$"] is.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ohh I get it, you coming from an object oriented environment.
like ASP.NET.
PHP has no equivalent of labels, you display messages to the page via "ECHO" of "fprint". or assigning values to variables
converting lblWarning into a variable and then echoing or printing it out wherever you need it.
Code:
$lblWarning="This is a valid IDNumber";
then
Code:
echo $lblWarning;

wiull print the message to the page.
 
I think we need to take this from the beginning don't you Sleipnir??
Why don't show us your textboxes and your query, and we can go from there.

 
Thanks to both of you so much. Yeah, it's a bit tricky going away from OO...I'm excited though. Any good PHP books for newbies???????

Here's the code for the whole page:

<?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);
?>
<?PHP
If ([Recordset2.TotalRecords]==1) {lblWarning=="You have one record"};
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.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);
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>
<label id=lblWarning>This is the label!</label>
</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);
?>
 
Okay, first a little technical stuff...

Examining the lines:

$Recordset2 = mysql_query($query_Recordset2, $conn) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

In them $Recordset2 takes on the value of a handle to a MySQL recordset. It is not a recordset, merely a handle to one. In many ways, it's similar to a file handle in that you use this value and specialized functions to access the actual data in the recordset.

$row_Recordset2 take on an associative array representing a single row of data from the recordset accessed through the recordset handle $Recordset1. The column names from the query will be the array indeces. Since this is the first time mysql_fetch_assoc() has been called against the recordset handle $Recordset2, the array will be the first row from the recordset. Successive calls of mysql_fetch_assoc() against $Recordset2 will fetch successfile rows from the recordset until there are no more rows to be had -- at which time mysql_fetch_assoc() returns the boolean value FALSE.

$totalRows_Recordset2 will be an integer representing the number of rows in the recordset to which $Recordset2 is a handle.

None of these values are objects. The most complex datastructure in any of the variables is the associative array in $row_Recordset2. As I have said before, although PHP understands OO stuff, very few of its builtin functions return objects.

And even if they were objects, PHP reserves the "." operator strictly for string concatenation. PHP uses "->" to designate subcomponents of an object.


So, if you want to reference that value that is the total number of records in the recordset referenciable through the handle $Recordset2, you would use mysql_num_rows(). But that's already been done, and the value stored in $totalRows_Recordset2.


As far as book recommendations go, I didn't use one to learn PHP. I can strongly recommend, however, the PHP online manual at It is one of the best-written pieces of documentation available on the internet.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I just used the following:
<?PHP
$IDFound = "This is a valid IDNumber";
$IDNotFound = "This is not a valid IDNumber";
If ($totalRows_Recordset2==1)
{echo $IDFound;}
Else
{echo $IDNotFound;}
?>

This works, but when the page first loads(shows to the user), the $IDNotFound will always display.
 
I dont wan't to make you change all you're code. But o my god, its like trying to hammer in a nail with a steam roller.
Assuming everything else works. this line:
Code:
if ([Recordset2.TotalRecords]==1) {lblWarning=="You have one record"};
This will never produce anything. You are coding ASP and tryign to get to parse through PHP.

first of all:
All variables in PHP begin with a "$". Second recordset2.totalrecords is not a valid variable.

in any case it would be $recordset2_totalrecords. and even then it has been given no value anywhere.

From whst I se you wan't to check how many records you have from the recordset2 query. In that particular Query you create this variable which holds the rows:
Code:
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
so that is the one you should be checking.
You're if statement would be:
Code:
If ([$totalRows_Recordset2]==1) {echo "You have one record";}

See the difference???

Ppost back with any questions

 
So you found out everythin I just posted before so,
For that if statement:

you have to check whether the $total_rows_Recordset2 is set
Code:
if(isset($total_rows_Recordset2))

Try this:
Code:
<?PHP
if(isset($totalRows_Recordset2==1)){
         $IDFound = "This is a valid IDNumber";
         $IDNotFound = "This is not a valid IDNumber";
         If ($totalRows_Recordset2==1)
            {echo $IDFound;}
         Else
            {echo $IDNotFound;}
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top