Getting A Value via PHP?

Discussion in 'OT Technology' started by mondaynightmike, Mar 5, 2005.

  1. mondaynightmike

    mondaynightmike New Member

    Joined:
    Aug 10, 2004
    Messages:
    117,672
    Likes Received:
    0
    Location:
    DEFINITELY No *Unlinked* Cock Pics
    Hello i have this html code:

    Code:
     
       <form name="mf" action="http://www.f1modelnews.com/uni/testing.php" method="get">
     
     <!-- ****************** SELECT CPU ****************** -->  
     
     	<select name="selectcpu" onChange="update (1)">
     	 <option> > Select A CPU <</option>
     	 <option value="40.00">Intel Celeron 320 2.4GHz</option>
     	 <option value="60.00">Intel Celeron 355 2.8GHz</option>
     	 <option value="90.00">AMD Athlon 64 3000</option>
     	 <option value="90.00">AMD Sempron 3100</option>
     	 <option value="111.00">Intel Pentium 4 3.0GHz</option>
     	 <option value="135.00">Intel Pentium 4 3.2GHz</option>
     	  <option value="145.00">AMD Athlon 64 3400</option>
       </select>
     	</td>
     	<td width="14%">
     	<image name="cpupic" src="images/clear.gif">
     	</td>
     	<td width="68%">£<input type="text" readonly name="cpuprice" size="6">
     			<input type="hidden" readonly name="cpu" value="$cpu">
     
     	</td>
       </tr>
       <tr>
     
     
     	</tr>
       </table>
     
    and the .php file is this code:

    PHP:
     
     <?php
     
     $cpu 
    $_GET['cpu'];
     
     print 
    "Cpu is $cpu";
     
     
    ?>
     
    all it is doing is printing whatever i have here (in bold):

    <input type="hidden" readonly name="cpu" value="$cpu">

    How can i get it to return one of the selected values from the drop down box?
     
  2. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    remove that hidden field, it's not necessary. What you want is

    $_GET['selectCPU'];

    The value of the dropdown box will be set to the name of the dropdown box. In this case, you named the drop down selectcpu. This will only return the prices of your dropdown since you put the prices in the value. You cannot retrieve the name itself. What you should do is put the name in the values, or SKU#, barcode... and have a database that links that SKU# to that price. Then you can get both values in the php program.
     
  3. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    The HTML code needs to be in a .php file. It is reading $cpu as HTML which means nothing -- so it just spits it out as text. What you really want is:

    <input type="hidden" readonly name="cpu" value="<?=$cpu?>">

    The <?= ?> enclosure will spit out the php value.
     
  4. mondaynightmike

    mondaynightmike New Member

    Joined:
    Aug 10, 2004
    Messages:
    117,672
    Likes Received:
    0
    Location:
    DEFINITELY No *Unlinked* Cock Pics
    Basically what it is, i have a website with different computer components. i have all the boxes and prices etc..

    but the next stage is getting the values and storing them in a mysql database along with the customers name and address.

    If i can get the basic code working then i can normally expand and work on it from there.
     
  5. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    I just went to Dell, HP, Alienware, Gateway, and MPC (formerly micron). All except MPC uses radio buttons instead of drop down boxes to make their selection. I think this would be best for you to do, so that the user can see all the choices without having to drop down each box. Here is certain code taken from MPC.

    <option value="1284161[149]">200GB Serial ATA-150 8MB Cache Hard Drive (7200RPM) [Add $149.00]</option>
    <option value="1284156[199]">36GB SCSI U320 hard drive (10,000RPM) [Add $199.00]</option>
    <option value="1284158[249]">250GB Serial ATA-150 8MB Cache hard drive (7200RPM) [Add $249.00]</option>
    <option value="1338267[299]">160GB Serial ATA-150 (2x80GB) 2MB Cache hard drive (7200RPM) [Add $299.00]</option>

    As you can see, they use the format code#[price] for their use. For your example, you may want to do something like:

    <option value="Intel Celeron 320 2.4GHz">Intel Celeron 320 2.4GHz (40.00)</option>
    <option value="Intel Celeron 355 2.8GHz">Intel Celeron 355 2.8GHz (60.00)</option>

    OR

    <option value="42342">AMD Athlon 64 3000 (90.00)</option>
    <option value="22523">AMD Sempron 3100 (90.00)</option>
    <option value="12313">Intel Pentium 4 3.0GHz (111.00)</option>

    And have those above numbers in a MySQL database. Then in your php file, and this is just pseudocode now:

    <?php
    get value of CPU
    connect to mysql
    get name,prices where SKU#=$CPU
    do your calculations
    close mysql database
    ?>
     

Share This Page