Jump to content

Comparing Values


White_Lily

Recommended Posts

Hi, I have been asked to sort out a problem with related pages where the CMS lets you add pages even if there some already set.

 

I have written a little validation where it checks if the page selected has already got related pages on it... however the script skips the validation and goes and inserts the new related pages anyway...

 

if(isset($_POST['addTest']))

{ 
// Get posted values
$category = mysql_real_escape_string($_POST['catSel']);
$product_category = mysql_real_escape_string($_POST['product_category']);

$getMultiple = select("sidebar_featured_pages", "*", "category = '$category'");
$check = mysql_fetch_assoc($getMultiple);

if($category == $check["catSel"]){
$msg .= generateMsg("Sidebar Pages creation failed, the page you selected already has pages set.");
}else{ 
$addTest = insert("sidebar_featured_pages", array("", $category, $product_category));

if($addTest){
$msg .= generateMsg("Sidebar Pages created successfully.", "success");
}else{
$msg .= generateMsg("Sidebar Pages creation failed, unable to access the database.");
}
}
}

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/269892-comparing-values/
Share on other sites

select() is custom function:

 

function select($table, $rows = "*", $where = NULL, $order = NULL, $limit = NULL, $offset = NULL)
{
$queryString = "SELECT ".$rows." FROM ".$table;
if($where != null)
$queryString .= " WHERE ".$where;
if($order != null)
$queryString .= " ORDER BY ".$order;
if($limit != null)
$queryString .= " LIMIT ".$limit;
if($offset != null)
$queryString .= " OFFSET ".$offset;

$query = mysql_query($queryString);

// if query is successful
if($query)
return $query;
else
return false;
}

Link to comment
https://forums.phpfreaks.com/topic/269892-comparing-values/#findComment-1387641
Share on other sites

Basically if the value of say... 10 is in catSel AND category, then I don't want them to be able to have related pages, but if the value isn't equal then they can have related pages.

 

It's like saying if someone registers to a website and they pick a username that has already been taken, then you wouldn't want them to have that username you would want them to pick something different - that's something similar to what i am trying to achieve.

Link to comment
https://forums.phpfreaks.com/topic/269892-comparing-values/#findComment-1387662
Share on other sites

  On 10/25/2012 at 1:05 PM, PFMaBiSmAd said:

I'm going to guess your `catSel` column and your `category` column don't hold the same value. That's what your query and your php logic are testing for.

 

Have you tried var_dump() on those two values to check what's in them?

Link to comment
https://forums.phpfreaks.com/topic/269892-comparing-values/#findComment-1387855
Share on other sites

Right, I managed to find something that has finally worked!!

 

The code that gets the id's that have pages already set:

 

$allRel = select("sidebar_featured_pages", "*");

while($allRelRes = mysql_fetch_array($allRel)){
$usedCats[$allRelRes["category"]] = true;
}

 

The code that displays categories that haven't been used:

 

<select name="catSel" style="width: 300px;">
<?
$getCategories = select("pages", "id, name", "(page_switch = 1) AND (type = 2 OR type = 4 OR type = 5)");

while ($categories = mysql_fetch_array($getCategories))
{
if(!isset($usedCats[$categories['id']])){
echo "<option value='".$categories['id']."'>".$categories['name']."</option>";
}
}
?>
</select>

 

 

Thank for the help you all gave! x

Link to comment
https://forums.phpfreaks.com/topic/269892-comparing-values/#findComment-1387858
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.