fatherthespis Posted July 18, 2007 Share Posted July 18, 2007 Hi everyone, Thank you for your patience on this one...I have never coded PHP in my life, but am trying to hack away at it for a current project I'm working on. This will probably be a completely dumb question, but I would tremendously appreciate any assistance...I've been stuck now on this one point for three days and have pulled out half my head of hair. ;-) Here's what I'm trying to do. I have a variable coming into my script via a post operation. That variable ($fromFlash) is being sent to the script from a Flash movie and just contains a website URL. I have a MySQL database containing the names of organizations with their website addresses. I need to compare my variable against that database, to see if there is a match for the website address contained in the variable; if there is a match, I need to pull the record and send the organization's name back to my Flash movie -- if there is no match, I need to send an error message. So far, I have this code: <?php require_once('../../../Connections/dbTFM.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_dbTFM, $dbTFM); $query_rsTFMGroup = "SELECT fdOrgNameFull, fdOrgNameAbbr, fdWebsite, fdTFMLink FROM tblGroupData"; $rsTFMGroup = mysql_query($query_rsTFMGroup, $dbTFM) or die(mysql_error()); $row_rsTFMGroup = mysql_fetch_assoc($rsTFMGroup); $totalRows_rsTFMGroup = mysql_num_rows($rsTFMGroup); $fromFlash = $_POST['toPHP']; $toFlash = "&toFlash="; $grpName = "&grpName="; $webLink = "&webLink="; $toFlash .= $fromFlash; $siteURL .= $row_rsTFMGroup['fdWebsite']; if ( $fromFlash != $siteURL ) { $grpName .= "THIS IS NOT A TAPS FAMILY WEBSITE"; $webLink .= "#"; } else { $grpName .= $row_rsTFMGroup['fdOrgNameAbbr']; $webLink .= $row_rsTFMGroup['fdTFMLink']; } echo $toFlash; echo $grpName; echo $webLink; mysql_free_result($rsTFMGroup); ?> As you can see, this code is not really comparing my incoming variable against the database at all...it compares it only against the first record, so unless a particular organization happens to be the first record in my database the code doesn't work. I guessed that I should be using a "while" loop, but must have messed that up because all of my variables were coming back "undefined." If anyone could help me out even just by pointing me in the right direction, I would appreciate it more than you could know. Very best wishes, Eric Ewing Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 19, 2007 Share Posted July 19, 2007 You need a WHERE condition in your SQL query. It needs to be something like: $query = "SELECT fdOrgNameFull, fdOrgNameAbbr, fdWebsite, fdTFMLink FROM tblGroupData WHERE whateverColumn = '$yourvalue'"; MySQL tutorial on selecting particular rows: http://dev.mysql.com/doc/refman/5.1/en/selecting-rows.html You might not be looking for an exact value. If you need a substring match, see the LIKE and REGEXP operators in MySQL. Quote Link to comment Share on other sites More sharing options...
fatherthespis Posted July 19, 2007 Author Share Posted July 19, 2007 Ah-ha! That was exactly it...I thought I was overlooking something basic. Thanks so very much for your assistance. Best wishes, Eric Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.