Hi,
I have been using the post web data scripts posted by Robin on the old forum in posting #9403. I have successfully sent data to a Mysql database and retrieved data from the first record of a table in my Mysql database (would like to know how to get the next records also), but I am having trouble with the function that allows you to compare an inputted username... to a username in a database. I am using the information below as posted previously:
Subject Username Date
Re: Databases, Opus Pro and web Robin Garrett 20 Oct 2004 12:25:50
TEXT FROM 9403 SERIES OF ENTRIES IN OLD FORUM
You would need to send the inputted username and password to a PHP file which stores these values to strings, then searches the database for any record where the username is the same as the inputted value. You can then compare the inputted password to that retrieved from the database and echo information back to the publication to communicate whether or not the login was a success.
The following PHP script should give you some idea of how this is achieved:
<?php
$user = $HTTP_POST_VARS['user'];
$pass = $HTTP_POST_VARS['pass'];
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "mydb";
$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "SELECT * FROM tablename WHERE username='$user'";
$result = mysql_query($query, $connect);
$resultRow=mysql_fetch_array($result );
$storedpassword=$resultRow[userpassword];
$storeduser = $resultRow[username];
if ($password==$storedpassword) {
echo "&success=1";
} else {
echo "&success=0";
}
?>
If the username and password are correct, a name-value pair of "success" and "1" is transmitted via the echo function. If the username and password do not match, the name "success" and value "0" are transmitted. You would therefore need to use the ''Destination' tab of the existing Post Web Data action to retrieve this name-value pair and store it to a variable. You can then use an If statement to trigger different actions depending on the value of the target variable, such as showing an 'Invalid Login' message or displaying the next page if the login was successful.
END OF TEXT FROM 9403 SERIES OF ENTRIES IN OLD FORUM
I think I understand this up to the point of getting the "success=1" or "success=0" into a variable in my Opus pub. Would it be possible to give a more specific example of this as was done with the prior entries on how to insert or retrieve data? It would be very helpful! Thanks.