-2

anyone can help me with this thank you very much in advance

This is my save.php file

<?php

include('db_connect.php');

if (isset($_POST['Set1']))
{
    $Set1 = $_POST['Set1'];
    mysql_query("INSERT INTO 'evaluation' (A1) VALUES ('$Set1')");
}
else if (isset($_POST['Set2']))
{
    $Set2 = $_POST['Set2'];
    mysql_query("INSERT INTO 'evaluation' (A2) VALUES ('$Set2')");
}
else if (isset($_POST['Set3']))
{
    $Set3 = $_POST['Set3'];
    mysql_query("INSERT INTO 'evaluation' (A3) VALUES ('$Set3')");
}
else if (isset($_POST['Set4']))
{
    $Set4 = $_POST['Set4'];
    mysql_query("INSERT INTO 'evaluation' (A4) VALUES ('$Set4')");
}
//the code continue until A30..

?>

this is my radiobutton file

   <form action="save.php" method="post">
          <h3 style="text-align:center;">B. Kerja Berpasukan</h3>
          <table class="table table-condensed" style="width:100%">
            <thead>
              <tr>
                <th>Bil.</th>
                <th id="th01">Kriteria</th>
                <th id="th02">Skala Kompetensi</th>
              </tr>
            </thead>
            <tbody>
              <tr class="danger">
                <td>1.</td>
                <td>Menunjukkan sifat-sifat bekerjasama seperti sedia 
              berkongsi maklumat dan kiraan yang telah
                    diperoleh/dilakukan</td>
                <td>
                    <label class="radio-inline">
                      <input id="r1" type="radio" name="Set6" value="1" 
required/>1
                    </label>
                    <label class="radio-inline">
                      <input id="r2" type="radio" name="Set6" value="2" 
required/>2
                    </label>
                    <label class="radio-inline">
                      <input id="r3" type="radio" name="Set6" value="3" 
required/>3
                    </label>
                    <label class="radio-inline">
                      <input id="r4" type="radio" name="Set6" value="4"     
required/>4
                    </label>
                    <label class="radio-inline">
                      <input id="r5" type="radio" name="Set6" value="5" 
required/>5
                    </label>
                </td>
              </tr>
              <tr class="danger">
                <td>2.</td>
                <td>Menunjukkan kesanggupan melaksanakan tugas dan 
             arahan/permintaan pegawai</td>
                <td>
                    <label class="radio-inline">
                      <input id="r1" type="radio" name="Set7" value="1" 
required/>1
                    </label>
                    <label class="radio-inline">
                      <input id="r2" type="radio" name="Set7" value="2"  
required/>2
                    </label>
                    <label class="radio-inline">
                      <input id="r3" type="radio" name="Set7" value="3" 
 required/>3
                    </label>
                    <label class="radio-inline">
                      <input id="r4" type="radio" name="Set7" value="4" 
 required/>4
                    </label>
                    <label class="radio-inline">
                      <input id="r5" type="radio" name="Set7" value="5" 
required/>5
                    </label>
                </td>
              </tr>
              <tr class="danger">
                <td>3.</td>
                <td>Sentiasa bertindak sebagai kumpulan seperti bersama 
               menyediakan/membantu
                    membuat tugasan/aktiviti</td>
                <td>
                    <label class="radio-inline">
                      <input id="r1" type="radio" name="Set8" value="1" 
required/>1
                    </label>
                    <label class="radio-inline">
                      <input id="r2" type="radio" name="Set8" value="2" 
required/>2
                    </label>
                    <label class="radio-inline">
                      <input id="r3" type="radio" name="Set8" value="3" 
required/>3
                    </label>
                    <label class="radio-inline">
                      <input id="r4" type="radio" name="Set8" value="4" 
required/>4
                    </label>
                    <label class="radio-inline">
                      <input id="r5" type="radio" name="Set8" value="5" 
required/>5
                    </label>
                </td>
              </tr>

            </tbody>
          </table>

my database name is 'SPPI' table to save the radiobutton value is'evaluation' the table has a field from A1 to A30

Martin
  • 22,212
  • 11
  • 70
  • 132
joshua
  • 1
  • 1
    please mention about what is your problem.are you getting any errors..?? – Vimal Apr 11 '17 at 08:49
  • 2
    Shift your SQL Connection to `MySQLi` – Naveed Ramzan Apr 11 '17 at 08:49
  • you need to insert each radio value into each row or all radio value into 1 row what you want ? – JYoThI Apr 11 '17 at 08:50
  • your php variables within the `INSERT` statements are in single quotes and will only be read as a string. what are the `(A1)`, `(A2)` etc sections to the table names? – Jason Joslin Apr 11 '17 at 08:52
  • 1
    use backticks for column name and table name instead of single quotes if put single quotes it consider as string "INSERT INTO `evaluation` (`A1`) VALUES ('".$Set1."'')" – JYoThI Apr 11 '17 at 08:54
  • Btw html `id` attributes have to have unique values. – inarilo Apr 11 '17 at 08:57
  • you need to store each value in new row or everything in one row ?? @JasonJoslin – JYoThI Apr 11 '17 at 08:59
  • Joshua you need to go away and learn some basics of MySQL and PHP before asking a question here, there's no sign you've made any attempt to research the multitude of similar questions already on StackExchange. – Martin Apr 11 '17 at 08:59
  • @JYoThI He can use the variable directly in the string since it's in double quotes. – inarilo Apr 11 '17 at 09:00
  • @inarilo do single quotes work inside double quotes with out escaping? eg `"Select blah from blah where blah = \'$variable\' "`? – Jason Joslin Apr 11 '17 at 09:01
  • @JasonJoslin you only need to escape them if you are using the same character as the enclosing character, otherwise php will treat it as the end of the string. So you don't need to escape single quotes inside a string enclosed by double quotes or vice versa. Thus `"Select blah from blah where blah = '$variable' "` will work, though it is better to enclose variables used thus in curly brackets, `"Select blah from blah where blah = '{$variable}' "`. – inarilo Apr 11 '17 at 11:55
  • my problem is, I want to save the radio button value that has been selected by the user. i dont have any error – joshua Apr 11 '17 at 16:31

2 Answers2

1

first of all do you have submit for all the set that your want to post ??If don't have it please add submit into your code for example : change the value into your desired value .

    <input type="submit" name="submit" value="submit" class="button" />
Martin
  • 22,212
  • 11
  • 70
  • 132
rixxkenzou
  • 21
  • 5
0

Some notes on your question. Please google these notes for details solutions to each point, as appropriate:

  • PHP includes do not need brackets. Remove them.

  • STOP using mysql_ functions they are DEPRECATED and have been removed in PHP7. You should be using MySQLi_ functions or better yet, PDO. Research these.

  • You need to learn to use Prepared Statements or to fully clean your user input. Currently nefarious user input can easily take over and destroy your MySQL table(s).

  • You need to close your HTML <form> tag. Your form tag should also contain a enctype="multipart/form-data" element (as well as probably an accept-charset="UTF-8")

  • You very probably need to fundamentally rethink your MySQL table structure and data architecture.

  • As suggested by nixxkenzou you need to actually submit your HTML form for your server to process the data (as to which radio buttons where selected, etc.)

  • PHP else if can be reduced to elseif

  • Read up and make full use of PHPs extensive error reporting system. Which will guide you to avoiding tedious syntax errors.

  • HTML id tags need to be unique on a page, if the id is referenced by anything (javascript, CSS, etc.) and there's more than one, it will cause you issues.

Good luck.

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
  • Why would he need to use `enctype="multipart/form-data` when he has only radio buttons? – inarilo Apr 11 '17 at 12:03
  • @inarilo not specifically for radio buttons but it's a good habit to get into for POST forms to use the correct defined encoding type. – Martin Apr 11 '17 at 12:19
  • If this was the only correct form then it would be the default, surely. I've never heard of this being required unless files are being uploaded. – inarilo Apr 11 '17 at 12:35
  • @inarilo http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – Martin Apr 11 '17 at 12:43
  • The accepted answer in that says what I said (in fact before commenting here I double checked and that was the question I read). – inarilo Apr 11 '17 at 13:02