Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Can an input type have multiple names and values

    As the title says 'Can an input type have multiple names and values?'

    I have a radio button the needs to submit 2 different names and values to be processed by a php file and the info entered in to a database.

    <form action="weapons.php" method="post">

    <input type="hidden" name="_submit_check" value="1"/>

    <table width="98%" border="1" cellpadding="3" cellspacing="1" bgcolor="#000000">
    <tr>
    <td bgcolor="#000000"><font>&nbsp;</td>
    <td bgcolor="#000000"><font><nobr>Weapon Name</nobr></font></td>
    <td bgcolor=""><font>Description</font></td>
    <td bgcolor=""><font>Price</font></td>
    <tr><td bgcolor="" valign="top"><font size="1" face="Verdana"><input type="radio" name="Weapons" value="Brass Knuckles, "><input type="hidden" name="Money" value="125"></td><td bgcolor="" valign="top"><font size="1" face="Verdana">Brass Knuckles</td><td bgcolor="" width="90%"><font size="1" face="Verdana"><strong>DMG</strong>: +5<BR><strong>Special</strong>: None<BR><strong>Restrictions:</strong>: None<BR>Want to pack a bit more in your punch? This finely crafted brass piece fits over the knuckles with a brace fitting into your palm. Perfect for gaining the upper hand in a fist fight.</td><td bgcolor="" valign="top"><font size="1" face="Verdana">$125</font>
    the section in blue is the bit i need submitted together, there are several of these on each page and at the moment when it submits it uses the last hidden value on the page not the one next to the specific item.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Not very clear. Do you want that, if a radio button is checked (let's say your with the name="Weapons" and value="Brass Knuckles"), the query should send another pair of name/value (let's say your name="Money" value="125")?

    Or both (if the radio is checked)?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    i need it to send both, so if weapons is checked it sends both weapons/brass knuckles and money/125

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    The simpler way could be to send multiple data units, separated with a delimiter, as a single value:
    Code:
    <input type="radio" name="Weapons" value="Brass Knuckles_Money_125">
    Now, at the server-side level all you have to do is to split (upon the delimiter) the value and use the sub strings accordingly. If PHP, I might show you the code.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    ok, how would i do that? would seeing the php side help?

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Could be something based on this:
    Code:
    <?php
    if(isset($_GET['Weapons'])){
    $data=explode('_',$_GET['Weapons']);
    
    $name='Weapons';
    $value=$data[0];
    $secondname=$data[1];
    $secondvalue=$data[2];
    }
    ?>
    if you method is GET. If it is POST, the global is $_POST
    Last edited by Kor; 11-18-2011 at 01:48 PM. Reason: changed the delimiter to: _
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    is the the php file used.

    <?php
    include("config.php");

    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());

    mysql_query("UPDATE userProperties SET Weapons = CONCAT(Weapons, '".$_POST['Weapons']."')
    WHERE name = '".$_POST['name']."' AND password = '".$_POST['password']."'");

    mysql_query("update userStats set Money = Money - '".$_POST['Money']."' where name = '".$_POST['name']."'");
    $res= mysql_query($update);

    ?>
    where in there would i put the code you suggest. sorry i'm new to php

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Try
    PHP Code:
    <?php
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    if(isset(
    $_POST['Weapons'])){
    $data=explode('_',$_POST['Weapons']);

    $name='Weapons';
    $value=$data[0];
    $secondname=$data[1];
    $secondvalue=$data[2];


    mysql_query("UPDATE userProperties SET Weapons = CONCAT(Weapons, '".$value."')
    WHERE name = '"
    .$_POST['name']."' AND password = '".$_POST['password']."'");

    mysql_query("update userStats set Money = Money - '".$secondvalue."' where name = '".$_POST['name']."'");
    $resmysql_query($update);
    }
    ?>
    Last edited by Kor; 11-18-2011 at 02:02 PM. Reason: php wrapping
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    In fact, you need only two values, so that:
    Code:
    <input type="radio" name="Weapons" value="Brass Knuckles_125">
    and:
    PHP Code:
    <?php
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    if(isset(
    $_POST['Weapons'])){
    $data=explode('_',$_POST['Weapons']);
    $value=$data[0];
    $secondvalue=$data[1];


    mysql_query("UPDATE userProperties SET Weapons = CONCAT(Weapons, '".$value."')
    WHERE name = '"
    .$_POST['name']."' AND password = '".$_POST['password']."'");

    mysql_query("update userStats set Money = Money - '".$secondvalue."' where name = '".$_POST['name']."'");
    $resmysql_query($update);
    }
    ?>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    Foster (11-18-2011)

  • #10
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    you my friend are a hero. i've been stuck on this for days, thank you

  • #11
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    would it be possible to do this for a 3rd and 4th value? the people who i built the site for have asked for additional data to be entered to the database with the same query


  •  

    Posting Permissions

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