Jump to content

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

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.