Thread: Radio Buttons

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3

    Radio Buttons


    The values are not being posted to the database. Any suggestions?

    Code:
    <div class="btn-group" data-toggle="buttons-radio">
                                            <button name="votifier" type="button" id="votifier" class="btn active" value="0">No</button>
                                            <button name="votifier" type="button" id="votifier" class="btn" value="1">Yes</button>
                                        </div>
    PHP Code:
    $votifier $_POST['votifier'];
    $sql=mysql_query("INSERT INTO servers (serverName, serverIP, serverOwner, serverWebsite, serverDesc, serverUptime, serverPlayersOnline, serverPlayersTotal, serverDateAdded, votifierIP, votifierPort, votifierKey, doVotifier) VALUES ('$serverName', '$serverIP', '$serverOwner', '$serverWebsite', '$serverDesc', '$serverUptime', '$serverPlayersOnline', '$serverPlayersTotal', '$today', '$votifierIP', '$votifierPort', '$votifierKey','$votifier')");
    //The other $items are defined else where in the document 
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    Do a var_dump( $_POST ); and show us the results.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,616
    Rep Power
    595
    For one thing you should stop using the deprecated MySQL extensions and switch to PDO and prepared statements. Your code is open to injection attacks. My personal experience has not been good mixing single and double quotes. It is also poor programming practice to put you query string as a literal in a query. Build it into a variable and echo the resulting string to make sure it contains what you expect.
    PHP Code:
    $query="INSERT INTO servers (serverName, serverIP, serverOwner, serverWebsite, serverDesc, serverUptime, serverPlayersOnline, serverPlayersTotal, serverDateAdded, votifierIP, votifierPort, votifierKey, doVotifier) VALUES ('".$serverName."', '".$serverIP."', '".$serverOwner."', '".$serverWebsite."', '."$serverDesc."', '."$serverUptime."', '".$serverPlayersOnline."', '."$serverPlayersTotal."', '."$today."', '".$votifierIP."', '".$votifierPort."', '".$votifierKey."','".$votifier."')";
    echo 
    "$query<br />"
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by navnav
    Do a var_dump( $_POST ); and show us the results.
    I got the following

    array(12) { ["serverName"]=> string(4) "fdsa" ["serverIP"]=> string(4) "fdsa" ["serverOwner"]=> string(7) "Craytor" ["serverWebsite"]=> string(4) "fsad" ["MAX_FILE_SIZE"]=> string(7) "1000000" ["serverDesc"]=> string(4) "fsda" ["votifierIP"]=> string(4) "fdsa" ["votifierPort"]=> string(0) "" ["votifierKey"]=> string(0) "" ["recaptcha_challenge_field"]=> string(185) "03AHJ_Vusb4enxyKmURjqdQWUvlaXSjICW9W-UDap7hVkkdDgqV0a6tZHTIAlk2jIJLM0YXVyAIksKgaolPcXvI4vWi0LzHZbuNE9eYKAVMjUAm8eu_30XjvOQeH5kCXitxqC3zxN 1i34o8jJR1TLa6zoW1sctc2acpeQIouSLwb6rEHi_2DRWS8o" ["recaptcha_response_field"]=> string(14) "onshipho clear" ["submit"]=> string(6) "Submit" }
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    Where's the submit button HTML? Do you even have a submit button?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by navnav
    Where's the submit button HTML? Do you even have a submit button?
    ... Yeah...

    It is at the end...

    Code:
    <input name="submit" type="submit" class="btn" />
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    and this is all in a <form>?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by navnav
    and this is all in a <form>?
    Yes.

    Code:
    <form action="inc/doAddServer.inc.php" enctype="multipart/form-data" method="post">
                            <div class="control-group">
                                <label class="control-label" for="inputName">Server Name</label>
                                    <div class="controls">
                                        <input type="text" id="inputName" name="serverName" placeholder="Some Server">
                                    </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="inputIP">Server IP</label>
                                    <div class="controls">
                                        <input type="text" id="inputIP" name="serverIP" placeholder="mc.someserver.com:25565">
                                    </div>
                            </div>
                                <input type="hidden" name="serverOwner" value="<?php echo $_SESSION['usr']; ?>">
                            <div class="control-group">
                                <label class="control-label" for="inputWebsite">Server Website</label>
                                    <div class="controls">
                                        <input type="text" id="inputWebsite" name="serverWebsite" placeholder="http://someserver.com">
                                    </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="serverImg">Server Image Banner</label>
                                    <div class="controls">
                                        <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                                        <input name="serverImg" type="file">
                                    </div>
                            </div>
                            <!--<div class="control-group">
                                <label class="control-label" for="inputEmail">Email</label>
                                    <div class="controls">
                                        <input type="text" placeholder="Text input">
                                    </div>
                            </div>-->
                            <div class="control-group">
                                <label class="control-label" for="inputDescription">Server Description</label>
                                    <div class="controls">
                                        <textarea id="inputDescription" name="serverDesc" rows="7" style="width: 500px;"></textarea>
                                    </div>
                            </div>
                            </hr>
                            <h3>-- Optional --</h3>
                            <h5>Votifier Information</h5>
                            <div class="control-group">
                                <label class="control-label" for="votifier">Enable Votifier</label>
                                    <div class="controls">
                                        <div class="btn-group" data-toggle="buttons-radio">
                                            <button name="votifier" type="button" id="votifier" class="btn active" value="0">No</button>
                                            <button name="votifier" type="button" id="votifier" class="btn" value="1">Yes</button>
                                        </div>
                                    </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="votifierIP">Votifier IP (Your server IP)</label>
                                    <div class="controls">
                                        <input type="text" id="votifierIP" name="votifierIP" placeholder="mc.someserver.com">
                                    </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="votifierPort">Votifier Port</label>
                                    <div class="controls">
                                        <input type="text" id="votifierPort" name="votifierPort" placeholder="8192">
                                    </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="votifierKey">Public Votifier Key</label>
                                    <div class="controls">
                                        <textarea id="votifierKey" name="votifierKey" rows="7" style="width: 500px;"></textarea>
                                    </div>
                            </div>
    
                            <h3>--------------</h3>
                            <?php
                                 require_once('./inc/recaptchalib.php');
                                  $publickey = "6LdFEN4SAAAAAHcWfDznVRJ_k6pcDiRR-iH53430"; // you got this from the signup page
                                  echo recaptcha_get_html($publickey);
                            ?>
                            <input name="submit" type="submit" class="btn" />
                      
                        </form>
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    Try
    Code:
    <input type="radio" name="votifier" id="votifier" class="btn active" value="No">NO<br>
    <input type="radio" name="votifier" id="votifier" class="btn active" value="Yes">YES
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by navnav
    Try
    Code:
    <input type="radio" name="votifier" id="votifier" class="btn active" value="No">NO<br>
    <input type="radio" name="votifier" id="votifier" class="btn active" value="Yes">YES
    Okay... That kinda works...

    rray(13) { ["serverName"]=> string(4) "fsda" ["serverIP"]=> string(4) "fdsa" ["serverOwner"]=> string(7) "Craytor" ["serverWebsite"]=> string(4) "fdsa" ["MAX_FILE_SIZE"]=> string(7) "1000000" ["serverDesc"]=> string(4) "fdsa" ["votifier"]=> string(3) "Yes" ["votifierIP"]=> string(0) "" ["votifierPort"]=> string(0) "" ["votifierKey"]=> string(0) "" ["recaptcha_challenge_field"]=> string(185) "03AHJ_VutFdSgFU8AfYjgggeOb3qy0ffhIxaddY78-s6h_YbN7soIg5VFyAfV1Q-o5p4mKn0Il8fipUoIhh1qOf02tjxqPyGwCQ07JP8PPHTAW5QvqsN6StaXAAcYeEVa6XUO8vTqwQqztDawq1-uyshbdhhTl2h_54eBBlq0oTkKzgfelLTkFhCc" ["recaptcha_response_field"]=> string(11) "Grp illiNYo" ["submit"]=> string(6) "Submit" }

    But is there a way that I can use the format I used?
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    Yup

    Code:
    <input type="radio" name="votifier" class="votifier" class="btn active" value="0">NO<br>
    <input type="radio" name="votifier" class="votifier" class="btn active" value="1">YES
    Notice how I've changed id="votifier" to class="votifier". IDs cannot be used on more than one element per document. If you want to use the same CSS styles on multiple elements, use classes.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by navnav
    Yup

    Code:
    <input type="radio" name="votifier" class="votifier" class="btn active" value="0">NO<br>
    <input type="radio" name="votifier" class="votifier" class="btn active" value="1">YES
    Notice how I've changed id="votifier" to class="votifier". IDs cannot be used on more than one element per document. If you want to use the same CSS styles on multiple elements, use classes.
    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo