SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    making a custom script, not sure where to start..

    Hey everyone, thanks for reading.

    Im going to start making a custom script, but not sure how to do it.

    I have basic php knowledge but this one i need some guidance with.

    I will have a form where a user enters a numerical value into, namely a USD$ amount. I want the script to call the database, see if the same amount is stored, and if so, echo a GBP value for it.

    this will not be a currency converter, the numbers will be set.

    for example, if the user enters $50.00 into the script, it will see if there is $50 in the db, if so, it echo's the set amount, for example, 25.00

    there will be several different values, and users will be enterring only a certain amount each time.

    How would I go about doing this? I have absolutely no idea!

    I hope I have explained it enough, if anyone can help I'd be really gratefull!

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Location
    ATLANTA GA
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you mentioned PHP one could assume you plan to use a mySQL database. You didn't request help for the database so I assume you have already created it. Simple layout of the lookup table might be 2 columns, one named "usd" and one named "gbp" or whatever you want to call it.

    There are 100s, maybe 1000s of sample PHP scripts around the net that cover the basics of connecting to a mySQL database, authenticating and run a query to select data. No reason to discuss any of that here since you'll benefit greatly from looking for the information and learning from it.

    Not trying to put you off, but the best information I can give you is to point you in the right direction ~ sort of "teaching you to fish..."

    Let us know how you make out!

    Milt

  3. #3
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Milt, although I appreciate you are trying to make me look for the answer, I really do not know what exactly I am loking for, would it be "relational database php"? or am I completely way off here?

  4. #4
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply create a table, lets call it "tblMoney" which has 3 columns, [ID], [usd], [gbp].

    Enter in your values and build up your database eg.
    1 | 50 | 25
    2 | 75 | 50
    etc.

    Then simply query the database from you php script and select the matching [gbp] value for the [usd] the user chooses.

    eg. "SELECT gbp FROM tblMoney WHERE usd = '$usrValue'"


  5. #5
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Philm, thats just what I needed to know!

    I have a database setup now, id # 1 has a gbp value of 50 and usd of 100 for testing, when i use the following php though:

    Code:
    <?php
    include 'db.php';
    
    $usrValue = 100 ;
    
    $get = mysql_query("SELECT gbp FROM crncy where usd = $usrValue") or die("Mmm pie:" . mysql_error());
    while ($row = mysql_fetch_row($get)) {
    
    	echo $usrValue ;
    	}
    ?>
    It echos 100..

    What have I done wrong?

    Thanks in advance

    Tjobbe


    MYSQL Database dump:

    Code:
    # phpMyAdmin SQL Dump
    # version 2.5.6
    # http://www.phpmyadmin.net
    #
    # Host: localhost
    # Generation Time: Nov 24, 2005 at 05:01 PM
    # Server version: 4.0.18
    # PHP Version: 4.3.6
    # 
    # Database : `tblmoney`
    # 
    
    # --------------------------------------------------------
    
    #
    # Table structure for table `crncy`
    #
    
    CREATE TABLE `crncy` (
      `id` tinyint(4) NOT NULL auto_increment,
      `gbp` text NOT NULL,
      `usd` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=2 ;
    
    #
    # Dumping data for table `crncy`
    #
    
    INSERT INTO `crncy` VALUES (1, '50', '100');

  6. #6
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're just echoing out $usrValue, not the value coming from the DB.

    Try this...
    PHP Code:
    include 'db.php';
       
       
    $usrValue 100 ;
       
       
    $get mysql_query("SELECT gbp FROM crncy WHERE usd = $usrValue") or die("Mmm pie:" mysql_error());
       
       
    $theMoney mysql_fetch_array($get);
       
       echo 
    $theMoney["gbp"]; 

  7. #7
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    brilliant, thanks so much Philm!

  8. #8
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now, one more thing!

    I'd like the user to be able to fill in an input box, type submit, which sends them to the above script.

    So far I have:

    Code:
    <form action="display.php" method="post">
    <input name="usrValue" type="text" />
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
    </form>
    How do I tell the script what usrvalue is? i.e the data from the text field?

  9. #9
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, got it:

    $usrValue=$_POST['usrValue'];

    Thanks for all your help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •