Jump to content

[SOLVED] Please help! I need to compare variable against database field...


fatherthespis

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.