Jump to content

Form inserting zeros into table


topshelfbleu

Recommended Posts

I have a form that is posting a value from a radio button as well as 16 Hidden values.

The form action goes to file2- which is successfully conecting and processing but instead of inserting the correct values I'm just seeing a row of zeros.

 

I don't know where to start looking!

 

This is the code from the posting form :

---

 

<?php // query.php
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);

if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database)
    or die("Unable to select database: " . mysql_error());


$result = mysql_query("SELECT qid,question,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9 FROM tblquestions WHERE qid = '1'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // Question Number
echo $row[1]; // Question
echo $row[2]; // oc1
echo $row[3]; // oc2
echo $row[4]; // oc3
echo $row[5]; // oc4
echo $row[6]; // oc5
echo $row[7]; // oc6
echo $row[8]; // oc7
echo $row[9]; // pcs1
echo $row[10]; // pcs2
echo $row[11]; // pcs3
echo $row[12]; // pcs4
echo $row[13]; // pcs5
echo $row[14]; // pcs6
echo $row[15]; // pcs7
echo $row[16]; // pcs8
echo $row[17]; // pcs9


?>
  <p>Hello </p>
<?php 

echo $row[0]; // Question Number

?>
  <form id="form1" name="form1" method="post" action="./uinputprocess.php">
    <table width="800" border="0">
      <tr>
        <td colspan="6"><p>Question
          <?php 

echo $row[0]; // Question Number

?>
        </p>
        <?php 

echo $row[1]; // Question

?>
        .</td>
      </tr>
      <tr>
        <td width="126"><p align="center"> </p>
        <p align="center">Strongly Disagree        </p></td>
        <td width="65"><p align="center"> </p>
        <p align="center">Disagree        </p></td>
        <td width="145"><p align="center"> </p>
        <p align="center">Unsure but Doubtful        </p></td>
        <td width="152"><p align="center"> </p>
        <p align="center">Unsure but Probable        </p></td>
        <td width="67"><p align="center"> </p>
        <p align="center">Agree        </p></td>
        <td width="219"><p align="center"> </p>
        <p align="center">Strongly Agree        </p></td>
      </tr>
      <tr>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "1"  />
        </div></td>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "2"  />
        </div></td>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "3"  />
        </div></td>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "4"  />
        </div></td>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "5"  />
        </div></td>
        <td><div align="center">
          <input type= "radio" name= "ans" value = "6"  />
        </div></td>
      </tr>
      <tr>
        <td colspan="6"> </td>
      </tr>
      <tr>
        <td colspan="6"><p>Hidden Fields Here > 
          <input type="hidden" name="oc1" id= <?php 

"echo $row[2];"

?> />   <input type="hidden" name="oc2" id= <?php 

"echo $row[3];"

?> />   <input type="hidden" name="oc3" id= <?php 

"echo $row[4];"

?> />   <input type="hidden" name="oc4" id= <?php 

"echo $row[5];"

?> />   <input type="hidden" name="oc5" id= <?php 

"echo $row[6];"

?> />   <input type="hidden" name="oc6" id= <?php 

"echo $row[7];"

?> />   <input type="hidden" name="oc7" id= <?php 

"echo $row[8];"

?> />   <input type="hidden" name="psc1" id= <?php 

"echo $row[9];"

?> />   <input type="hidden" name="psc2" id= <?php 

"echo $row[10];"

?> />   <input type="hidden" name="psc3" id= <?php 

"echo $row[11];"

?> />   <input type="hidden" name="psc4" id= <?php 

"echo $row[12];"

?> />   <input type="hidden" name="psc5" id= <?php 

"echo $row[13];"

?> />   <input type="hidden" name="psc6" id= <?php 

"echo $row[14];"

?> />   <input type="hidden" name="psc7" id= <?php 

"echo $row[15];"

?> />   <input type="hidden" name="psc8" id= <?php 

"echo $row[16];"

?> />   <input type="hidden" name="psc9" id= <?php 

"echo $row[17];"

?> />
        </p>
          <p>Pin 
            <label for="textfield"></label>
            <input name="textfield" type="password" id="textfield" size="20" maxlength="5" />
          </p></td>
      </tr>
      <tr>
        <td colspan="6"><p>
          <input type="submit" name="button" id="button" value="Submit" />
        </p>
        <p> </p></td>
      </tr>
    </table>
  </form>

 

And this is the code from the processing file

 

 <?php // query.php
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);

if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database)
    or die("Unable to select database: " . mysql_error());

$pin =$_POST['pin'];
$qid =$_POST['qid'];
$oc1 =$_POST['oc1'];
$oc2 =$_POST['oc2'];
$oc3 =$_POST['oc3'];
$oc4 =$_POST['oc4'];
$oc5 =$_POST['oc5'];
$oc6 =$_POST['oc6'];
$oc7 =$_POST['oc7'];
$psc1 =$_POST['psc1'];
$psc2 =$_POST['psc2'];
$psc3 =$_POST['psc3'];
$psc4 =$_POST['psc4'];
$psc4 =$_POST['psc5'];
$psc6 =$_POST['psc6'];
$psc7 =$_POST['psc7'];
$psc8 =$_POST['psc8'];
$psc9 =$_POST['psc9'];
$ans =$_POST['ans'];

$enter_sql= "INSERT INTO tblresults (pin,qid,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9) VALUES ('$pin','$qid','$oc1','$oc2','$oc3','$oc4','$oc5','$oc6','$oc7','$psc1','$psc2','$psc3','$psc4','$psc5','$psc6','$psc7','$psc8','$psc9')";
$enter_query =mysql_query($enter_sql) or die (mysql_error());
?>
<body>
<p>Thank you - You have successfully entered your answer</p>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.