Radio button data failing to be inserted into MySQL.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Louloul
    New Member
    • Aug 2010
    • 7

    #1

    Radio button data failing to be inserted into MySQL.

    I have an urgent question please if any one could answer me now coz my representetion for my project is tommorrow.

    this my code
    Code:
    <html> 
    <head> 
    <title>Register</title> 
    <script type="text/Javascript"> 
    function DisableSelect() {
     
    document.form.rd1[0].disabled = false;
    document.form.rd1[1].disabled = false;
    document.form.rd1[2].disabled = true;
    document.form.rd1[3].disabled = true;
    document.form.rd1[4].disabled = true;
     
    } 
    function EnableSelect() { 
    
    document.form.rd1[0].disabled = true;
    document.form.rd1[1].disabled = true;
    document.form.rd1[2].disabled = false;
    document.form.rd1[3].disabled = false;
    document.form.rd1[4].disabled = false;
     
    }
    
    </script> 
    </head> 
    
    
    <body> 
    <form name="form" method="post" action="Register.php"> 
    <table border="1" align="center" length=90% width=50%><Caption><h2>Registration</h2></caption>
    <tr>
    <td align="center">
    <input type="radio" name="rb" ID="Radio1" VALUE="Radio1" onblur="DisableSelect()">Bac 1&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
    <input type="radio" name="rb" ID="Radio2" VALUE="Radio2" onblur="EnableSelect()">Bac 2
    </td>
    </tr>
    <tr>
    <td align="center"><input type=radio value=1  name=rd1 id=1>Sientifique&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
    <input type=radio value=2 name=rd1 id=2>Littéraire <br>
    
    <input type=radio value=3 name=rd1 id=3>ES<br>
    <input type=radio value=4 name=rd1 id=4>Science De La vie&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
    <input type=radio value=5 name=rd1 id=5>Science General<br>
    </td>
    </tr>
    <tr>
    <td align=middle>
      <input type="submit" name="submit" value="S'Inscrire">
     
    <input type="reset" name="reset" value="Effacer" align="right"></td></tr>
    
    </table>
    </form> 
    </body> 
    </html>
    and this is the code of php inorder to insert the information to the table(data base)
    but the information within the radio is not working

    Code:
    <?php session_start(); 
    include("entete.html");
    
    mysql_connect("localhost","root","") or die("Failed to open connection to MySQL server".mysql_error());
    $con=mysql_select_db("ecole") or die("Failed to select the database".mysql_error());
    
    $us=session_name();
    
    		
    $sql= mysql_query("SELECT ID_etu FROM etudiante WHERE userName_etu='$us'");
    $user=$_GET["userNom"];
    
    $branche=$_POST["rb"];
    $spec=$_POST["rd1"];
    
    $result=mysql_query("INSERT INTO etudiante ('branche','Specialite') VALUES('$branche', '$spec') where ID_etu='$idetu' ");
    if($result)
    {
    	echo("correct");
    }
    else
    {
    	echo("false".mysql_error());
    }
    
    ?>
    please any help
    Thanks
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    1. Please don't hijack other people's threads.
    2. "It's not working" isn't nearly enough information to expect a response more detailed than this one.


    Do some debugging, find out where the error was, and then let us know what you are getting as output versus what you want to get as output.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      First thing you should do when a SQL query is not working as it should be, is to print the query and see what is wrong with it.

      [code=php]<?php
      // Build the query
      $sql = "INSERT INTO whatever ...";

      // Execute the query
      $res = mysql_query($sq l);

      // Check if the worked. If not, dump the query to the output.
      if(!$res) {
      // Trigger an error, and pass the query along.
      // This would not be shown on properly configured
      // production servers, but will on development servers.
      trigger_error(" SQL Query failed: $sql", E_USER_ERROR);
      exit; // Not needed atm, but why risk it :)
      }
      else {
      // Do stuff with the data, or whatever.
      }
      ?>[/code]

      Comment

      Working...