Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

sequence of html and php

html php code database sql

  • Please log in to reply

#1
panda123

panda123

    New Member

  • Member
  • Pip
  • 3 posts
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;
}
</style>
</head>
<body>
<form method="post">
  <h4>Answer all the questions on the scale (1)Strongly agree to (5)Strongly disagree </h4>
  <table width="1000" border="1" cellpadding="10">
    <tbody>
      <tr>
        <th style="width:50% ; text-align:center" scope="col">Questions</th>
        <th style="width:10% ; text-align:center" scope="col">Strongly agree</th>
        <th style="width:10% ; text-align:center" scope="col">Agree</th>
        <th style="width:10% ; text-align:center" scope="col">Neutral</th>
        <th style="width:10% ; text-align:center" scope="col">Disagree</th>
        <th style="width:10% ; text-align:center" scope="col">Strongly disagree</th>
      </tr>
      <tr>
        <td>1.People are clear about their role and performance levels expected of them.</td>
        <td><input type="radio" name="q1" value="q1a">
          1</td>
        <td><input type="radio" name="q1" value="q1b">
          2</td>
        <td><input type="radio" name="q1" value="q1c">
          3</td>
        <td><input type="radio" name="q1" value="q1d">
          4</td>
        <td><input type="radio" name="q1" value="q1e">
          5</td>
      </tr>
      <tr>
        <td>2.People understand how their role fits with the responsibilities of others.</td>
        <td><input type="radio" name="q2" value="q2a">
          1</td>
        <td><input type="radio" name="q2" value="q2b">
          2</td>
        <td><input type="radio" name="q2" value="q2c">
          3</td>
        <td><input type="radio" name="q2" value="q2d">
          4</td>
        <td><input type="radio" name="q2" value="q2e">
          5</td>
      </tr>
      <tr>
        <td>3.People understand the contribution they are making to organisational objectives.</td>
        <td><input type="radio" name="q3" value="q3a">
          1</td>
        <td><input type="radio" name="q3" value="q3b">
          2</td>
        <td><input type="radio" name="q3" value="q3c">
          3</td>
        <td><input type="radio" name="q3" value="q3d">
          4</td>
        <td><input type="radio" name="q3" value="q3e">
          5</td>
      </tr>
      <tr>
        <td>4.People are clear about the behaviours expected of them in achieving their objectives.</td>
        <td><input type="radio" name="q4" value="q4a">
          1</td>
        <td><input type="radio" name="q4" value="q4b">
          2</td>
        <td><input type="radio" name="q4" value="q4c">
          3</td>
        <td><input type="radio" name="q4" value="q4d">
          4</td>
        <td><input type="radio" name="q4" value="q4e">
          5</td>
      </tr>
      <tr>
        <td>5.Values and attributes are aligned with each other and support critical behaviour such as customer service or innovation.</td>
        <td><input type="radio" name="q5" value="q5a">
          1</td>
        <td><input type="radio" name="q5" value="q5b">
          2</td>
        <td><input type="radio" name="q5" value="q5c">
          3</td>
        <td><input type="radio" name="q5" value="q5d">
          4</td>
        <td><input type="radio" name="q5" value="q5e">
          5</td>
      </tr>
      <tr>
        <td>6.People feel the organisational systems are 'in sync' with their objectives.</td>
        <td><input type="radio" name="q6" value="q6a">
          1</td>
        <td><input type="radio" name="q6" value="q6b">
          2</td>
        <td><input type="radio" name="q6" value="q6c">
          3</td>
        <td><input type="radio" name="q6" value="q6d">
          4</td>
        <td><input type="radio" name="q6" value="q6e">
          5</td>
      </tr>
      <tr>
        <td>7.People believe they are given space to try new ideas or ways of doing things.</td>
        <td><input type="radio" name="q7" value="q7a">
          1</td>
        <td><input type="radio" name="q7" value="q7b">
          2</td>
        <td><input type="radio" name="q7" value="q7c">
          3</td>
        <td><input type="radio" name="q7" value="q7d">
          4</td>
        <td><input type="radio" name="q7" value="q7e">
          5</td>
      </tr>
      <tr>
        <td>8.Knowledge-sharing enables people to learn from one another.</td>
        <td><input type="radio" name="q8" value="q8a">
          1</td>
        <td><input type="radio" name="q8" value="q8b">
          2</td>
        <td><input type="radio" name="q8" value="q8c">
          3</td>
        <td><input type="radio" name="q8" value="q8d">
          4</td>
        <td><input type="radio" name="q8" value="q8e">
          5</td>
      </tr>
      <tr>
        <td>9.Cross-functional working enables people to learn from others' experiences.</td>
        <td><input type="radio" name="q9" value="q9a">
          1</td>
        <td><input type="radio" name="q9" value="q9b">
          2</td>
        <td><input type="radio" name="q9" value="q9c">
          3</td>
        <td><input type="radio" name="q9" value="q9d">
          4</td>
        <td><input type="radio" name="q9" value="q9e">
          5</td>
      </tr>
      <tr>
        <td>10.People watch for changes within the external world that might impact on the organisation.</td>
        <td><input type="radio" name="q10" value="q10a">
          1</td>
        <td><input type="radio" name="q10" value="q10b">
          2</td>
        <td><input type="radio" name="q10" value="q10c">
          3</td>
        <td><input type="radio" name="q10" value="q10d">
          4</td>
        <td><input type="radio" name="q10" value="q10e">
          5</td>
      </tr>
    </tbody>
  </table>
  <input type="submit" id="submit" name="submit">
</form>
</body>
</html>
 
<?php
$servername = "localhost";
$username = "prathama";
$password = "surveyres";
$dbname = "survey";
 
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 
// Create database
$sql = "CREATE DATABASE alignment";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database:alignment " . $conn->error;
}
 
$conn->close();
 
// create table
$sql = "CREATE TABLE survey (
sid INT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
q1 VARCHAR(20) NOT NULL,
q2 VARCHAR(20) NOT NULL,
q3 VARCHAR(20) NOT NULL,
q4 VARCHAR(20) NOT NULL,
q5 VARCHAR(20) NOT NULL,
q6 VARCHAR(20) NOT NULL,
q7 VARCHAR(20) NOT NULL,
q8 VARCHAR(20) NOT NULL,
q9 VARCHAR(20) NOT NULL,
q10 VARCHAR(20) NOT NULL,
)";
 
if ($conn->query($sql) === TRUE) {
    echo "Table survey created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}
 
$conn->close();
 
 
//insert values
$sql = "INSERT INTO survey (sid, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10,)
VALUES (' ', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')";
 
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
 
$conn->close();
?>

  • 0

Advertisements


#2
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts

Hey there Panda and welcome to Geeks to Go,

 

Please excuse me, but what is your question? Like what is the problem exactly?  :geek: I haven't been through the code yet, but if you can be a little more specific about the issue you're experiencing, I'm sure we can help!

 

Peace Out :cool:


  • 0

#3
panda123

panda123

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts

i have five radio buttons for each of the ten questions. how do i insert which radio button is selected by a user for each question in the database. one row should have the ID and ten answers for ten questions for one user. i want such multiple column entries for multiple users. 


  • 0

#4
Angoid

Angoid

    Malware Expert

  • Expert
  • 233 posts
Your form does not have an action.  This line:
 
<form method="post">
 
needs to look more like this:
 
<form method="post" action="somescript.php">
 
Then, when you click the Submit button, the script at somescript.php will execute and you can pick up your variables from the $_POST array and use those to populate rows in your database tables.
 
Have a look at the W3Schools page on HTML forms:

  • 0

#5
panda123

panda123

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts

ss1.png Thanks a lot.I could connect to the php form and then to the database. But only the first answer is getting saved into the database and all the other values are showing zero. Can u suggest something. i have created one id auto inc table and ten tables to store ten answers


Edited by panda123, 13 May 2016 - 12:45 AM.

  • 0

#6
Angoid

Angoid

    Malware Expert

  • Expert
  • 233 posts
You only need to run the script to create the database once. Don't run it every time as you don't want to create database tables more than once (that script should be a stand-alone script you run once to initialise your tables and then delete from the server when you've finished with it).
Actually, the second time you run it, it may give errors anyway as the tables will already exist.

Your INSERT statement should be in your somescript.php file (that I suggested in my earlier post) and you're not picking the values from your form up.

$sql = "INSERT INTO survey (sid, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10,)
VALUES (' ', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
You're not picking the values for q1, q2, ... q10 up from $_POST, binding your parameters and then executing it.

http://www.w3schools..._statements.asp

Incidentally, you have a lot of straight-line code that might become difficult to maintain. You may do better using more loops.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP