only1perky Posted September 15, 2008 Share Posted September 15, 2008 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 More sharing options...
Maq Posted September 15, 2008 Share Posted September 15, 2008 Because you need to loop through the return of the query... Change: $row_rstrial = mysql_fetch_assoc($rstrial); To: while($row_rstrial = mysql_fetch_assoc($rstrial)) { Link to comment https://forums.phpfreaks.com/topic/124326-solved-compare-text-field-to-records/#findComment-642015 Share on other sites More sharing options...
only1perky Posted September 15, 2008 Author Share Posted September 15, 2008 So simple thanks a lot. Link to comment https://forums.phpfreaks.com/topic/124326-solved-compare-text-field-to-records/#findComment-642021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.