Jump to content

[SOLVED] Compare text field to records


only1perky

Recommended Posts

Hi guys could someone please help me out.

I'm new to php so I'm sure I'm missing something so obvious it's untrue but hey.

 

I'm trying compare the text from a form to records in my database for a simple promo code script.

 

For example: if the text is 12345 and this matches one of the records in my database is will output data from another record.

 

At the moment I have this code:

 

$query_rstrial = "SELECT promo_codes.promo_code, promo_codes.promo_offer, promo_codes.percent FROM promo_codes";

$rstrial = mysql_query($query_rstrial, $connuser) or die(mysql_error());

 

$row_rstrial = mysql_fetch_assoc($rstrial);

 

$totalRows_rstrial = mysql_num_rows($rstrial);

 

 

 

 

if($_POST['utype']=='Basic' && $_POST['promocode'] == $row_rstrial['promo_code'])

$type_val="0";

elseif($_POST['utype']=='Bronze' && $_POST['promocode'] == $row_rstrial['promo_code'])

$type_val= 25 - (25 * $row_rstrial['percent']) ;

elseif($_POST['utype']=='Silver' && $_POST['promocode'] == $row_rstrial['promo_code'])

$type_val= 45 - (45 * $row_rstrial['percent']) ;

elseif($_POST['utype']=='Gold' && $_POST['promocode'] == $row_rstrial['promo_code'])

$type_val= 90 - (90 * $row_rstrial['percent']) ;

elseif($_POST['utype']=='Diamond' && $_POST['promocode'] == $row_rstrial['promo_code'])

$type_val= 150 - (150 * $row_rstrial['percent']) ;

 

 

else{

if($_POST['utype']=='Basic')

$type_val="0";

elseif($_POST['utype']=='Bronze')

$type_val= "25";

elseif($_POST['utype']=='Silver')

$type_val= "45";

elseif($_POST['utype']=='Gold')

$type_val= "90";

elseif($_POST['utype'])

$type_val= "150";

 

}

 

This code works when I enter the matching code to the first record of the table (trial20). However if I enter the code matching the second record (trial10) it does nothing.

Hope this makes sense and someone out there can give me a nudge in the right direction.

 

Cheers in advance.

 

 

Link to comment
https://forums.phpfreaks.com/topic/124326-solved-compare-text-field-to-records/
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.