Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2005-12-14, 06:43 AM
Junior Member
 
Join Date: Dec 2005
Posts: 7
markad
Default

Hi,

I need to construct a PHP script that submits data posted from a web form and checks it against existing data in a mySQL database to see if it matches then echo's back a message to the user saying whether its a match or not.

I've got the query; $guessquery = "SELECT * FROM guesses WHERE guess..etc

Could I use a session to indicate the data inputted by the user? Also where would I go from there? Thats abouts as far as i've got!

Any help appreciated, thanks.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2005-12-14, 09:15 AM
Member
 
Join Date: Aug 2004
Location: GA-USA
Posts: 56
usedtire
Default

Code:
/*print the form */
?>

<form method="post"><input type="hidden" name="complete" value=1>
<input type="text" name=guess value="your guess">
<input type="submit" value="submit">
</form>

<?
/*query the database */
if ($_REQUEST['complete'] == 1)
  {
   $query = mysql_query("select * from login where username = '".$_REQUEST['guess']."'");
   $result = mysql_num_rows($query);
   if ($result != 0) /*check your results */
    {
     echo "You have found your result.";
 
    }
   else
    echo 'Guess again';
  }
?>
There are cleaner ways to do it I am sure, but this is basically what you asked for.

You will obviously need to connect to your database.
__________________
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
-- (Terry Pratchett, Hogfather)
Reply With Quote
  #3 (permalink)  
Old 2005-12-15, 12:02 PM
Junior Member
 
Join Date: Dec 2005
Posts: 7
markad
Default

Hi, thanks for your reply script works well. All I want to do with it now is pass the results of that query to another page. How it works is the customer submits their guess, they then can get taken to a payments page, submit their card details, and these are validated and returned together with the charge. So I want the result of the guess query to come up on this same page. Would I just use the name of the form from the guess i.e. 'complete', as in the form below then do; $complete = $POST['complete'];? Thanks.
Reply With Quote
  #4 (permalink)  
Old 2005-12-19, 07:52 AM
Member
 
Join Date: Aug 2004
Location: GA-USA
Posts: 56
usedtire
Default

I would recommend that you use sessions or maybe someone else would recommend an better way.

Sessions are simple enough. If you are going to be passing the same variable around alot then you should use them.

Code:
session_start(); #required for you to use sessions, recommeded to be the first line of your code

$_SESSION['complete'] = $POST['complete'];
You are passing your HTML post to a PHP session. And that's it. Use this object as you would any other.
__________________
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
-- (Terry Pratchett, Hogfather)
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:50 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.