Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 1st, 2004, 07:15 AM
spectredigital spectredigital is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mesa, AZ, United States
Posts: 85 spectredigital User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 37 sec
Reputation Power: 2
Send a message via Yahoo to spectredigital
Compare form field value to JS array from PHP/MySQL

I'm stuck on how to go about comparing a entered value in a form field to a js array that needs to be loaded from a MySQL database. The scenario is this:


A customer is ordering something and has a coupon code, they enter the code in the box, then with Javascript I do a full form validation on all the other fields in the form. I want to be able to in the same validation be able to print out an error if the code they entered is invalid or expired, though both will be the same error message.

The SQL query would be this

php Code:
Original - php Code
  1. $sql = "SELECT couponcode FROM coupons WHERE active=='1'";


but how to load the results into a Javascript array, and then compare to the entered value has me totally lost.


Any ideas?

Reply With Quote
  #2  
Old June 2nd, 2004, 07:06 AM
Dani Dani is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 Dani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Compare form field value to JS array from PHP/MySQL

Yes, open a new window where you do the sql query check.

Put this javascript between the headtags.

<script language="JavaScript">
function validate(couponcode) {
window.open("checkcoupon.php?couponcode="+couponcode+"","check","toolbar=0,scrollbars=0,location=0,statusbar=0,menu bar=0,resizable=0,width=300,height=200");
}
</script>

Add this to your form

<input name="couponcode" type="text" value="" onBlur = "validate(document.formname.couponcode.value);">

(formname = the name of your form, maybe you should change it)

Then create a new page that is named checkcoupon.php and put this code in it.

<?
$couponcode = $_GET["couponcode"];
$numrows = mysql_num_rows(mysql_query("SELECT couponcode FROM coupons WHERE couponcode='$couponcode' and active=='1'"));

if ($numrows == 0) {
$error = "The couponcode does not exist!";
echo "<body>";
echo "$error";
}
else {
echo "<body>";
echo "<script language="JavaScript">";
echo "window.close()";
echo "</script>";
}
?>
</body>
</html>

Of course you should add somewhere code to be able to connect to your own database.

I haven't really tested it, but a think it should work.

Hope this helps you.

Reply With Quote
  #3  
Old June 2nd, 2004, 07:03 PM
spectredigital spectredigital is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mesa, AZ, United States
Posts: 85 spectredigital User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 37 sec
Reputation Power: 2
Send a message via Yahoo to spectredigital
RE: Compare form field value to JS array from PHP/MySQL

That way of doing it isnt quite what I origianlly had in mind, but I like your idea better it is more secure to do it that way. Thanks alot

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Compare form field value to JS array from PHP/MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT