Jump to content

dapcigar

Members
  • Posts

    58
  • Joined

  • Last visited

dapcigar's Achievements

Member

Member (2/5)

0

Reputation

  1. am getting the questions from the DB and displaying each question with the radio button options. <?php //session_start(); include('manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='comp[".$row['id']."]' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html> the other part is to save the result . <?php session_start(); if($_POST) { $answer = $_POST['answer']; $hobb = $_POST['comp']; foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; include('manpower_db.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var1','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; } ?>
  2. let me understand your question. you have an excel sheet and you want to upload it to a table in your DB right? if that is what you want to do, you can use this code to perform a mass upload. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td height="1" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#fff"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td width="60%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td align="center" valign="top"> </td></tr> <tr> <td height="40" align="center" valign="middle"><?PHP echo $msg; ?></td> </tr> <tr><td align="center" valign="top"></td></tr> <tr> <td align="center" valign="top"><form id="xlsSheet" name="xlsSheet" method="post" action="<?PHP $_SERVER['PHP_SELF']; ?>" onsubmit="return valPwd();" enctype="multipart/form-data" > <table width="497" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top" bgcolor="#999999"><table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td height="35" bgcolor="#D9ECFF" style="padding-left:50px;font-weight:bold;"> Choose a valid csv file.</td> </tr> <tr align="center"><td bgcolor="#ffffff"><br /> <table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td align="left">Upload CSV File : </td> <td align="left"><input name="filename" type="file" class="button" /> </td> </tr> <tr> <td></td> </tr> <tr> <td align="right"></a></td> </tr> </table> <br /> <input name="submit" type="submit" value="Upload File" style="background-color: #A31C21; border-radius: 6px; font-weight: bold; height: 30px; width: 125px; margin-right:35px;" /> <br /> <br /> </td></tr> <tr><td height="35" bgcolor="#D9ECFF" class="text3"> </td></tr> </table></td> </tr> </table> </form></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table> </body> </html> <?php if(isset($_POST['submit'])) { //Connect to Database $db = new PDO('mysql:host=localhost;dbname=(database name);charset=utf8', 'root', ''); //include('mysql_connect.php'); //Upload File if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h2>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h2>"; } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $count =0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import = $db->exec("INSERT into (your Table) (firstname, lastname, jobtitle, email, project, type, username, password) values('$data[0]','$data[1]','$data[2]','$data[3]', '$data[4]','$data[5]','$data[6]','$data[7]')"); $count++; } fclose($handle); //Print interted rows $msg="<h3 style='color:green;'>".$count. " Rows Imported !</h3>"; } ?> save this file as upload.php. locate your spreadsheet and upload. make sure you save your excel sheet in CSV format. Hope this helps..
  3. Hello all, Am trying to create a simple feedback form and also save the answers of each questions. i manage to get the system to save the answers but am not getting the id of my questions saved.. My code below <?php if($_POST) { $answer = $_POST['answer']; $hobb = $_POST['comp']; foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; include('manpower_db.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var1','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; } ?> <?php //session_start(); include('manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='comp[".$row['id']."]' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html>
  4. Am trying to get value from a list of data and pass the value to a modal popup to display more details. i can't find where the problem is. the button <td> <button class="btn btn-primary " data-toggle="modal" data-id="<?php echo $id ?>" data-target="#myModal" id="myButton"> View Details </button></td> the modal <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Requisition Details</h4> </div> <div class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> <!-- /.modal-content --> </div> the script <script language="javascript" type="text/javascript"> $('#myButton').click(function() { $('#myModal').modal('show') }); $('#myModal').on('shown.bs.modal', function(e) { $.ajax({ method: "POST", url: "getData.php", data: { dataId: $('#myModal').attr('data-id') }, success: function(data) { data = jQuery.parseJSON(data); $('.modal-body', '#myModal').html(data); } }); }) </script> the getdata.php <?php //dataId comes from ajax (POST) $id = filter_input(INPUT_POST, 'dataId'); include('mysql_connect.php'); $query11 = mysql_query("select * from p_requisition where id = '$id' ") or die(mysql_error()); $rows = mysql_fetch_array($query11); //you should use json_encode, and you can parse when get back data in ajax echo json_encode($rows['details']); ?> Please, Help me out..
  5. Am trying to save the result of the the selected answer with the question id. don't know how to pass the id to the DB. here's my code <?php session_start(); include('config/manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="save_feedback2.php" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='question_id' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html> Save to DB <?php session_start(); $answer = $_POST['answer']; $hobb = $_POST['question_id']; include('config/manpower_db.php'); foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; //include ('connect.php'); //include ('mysql_connect.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var2','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; ?> Please HELP!! thanks in advance
×
×
  • 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.