
dapcigar
Members-
Posts
58 -
Joined
-
Last visited
Everything posted by dapcigar
-
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>'; } ?>
-
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..
-
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>
-
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..
-
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
-
So sorry if that sounds like i didn't appreciate his effort. trust me i do. I should really apologize for my comment. it was harsh. i was only giving a feedback not to undermine him. i really need to fix this issue.
-
Didn't work..
-
Hello all, Am trying to retrieve a table from the DB, allow user select multiple options and also put the level . i was able to save the Data of the selected checkboxes but i cant get the level to save. my display code <form action="save_comp.php" method="post"> <?php include ('mysql_connect.php'); $sql = mysql_query("SELECT * FROM competency WHERE department = '$department'"); while($row = mysql_fetch_array($sql)) { echo "<tr>"; echo "<td>"; echo"<input type='checkbox' name='comp[]' value= ".$row['id']." /> ".$row['competency']." <br /> </td>"; echo"<td> <select name='level[]'> <option></option> <option>level 1</option> <option>level 2</option> <option>level 3</option> <option>level 4</option> <option>level 5</option> </select> </td> "; } echo "</tr>"; ?> <input name="submit" type="submit" value="submit" /> </form> <?php echo" </table>"; Code to save to DB <?php session_start(); $id = $_SESSION['user_id']; //$id = 3; $hobb = $_POST['comp']; $level = $_POST['level']; include ('mysql_connect.php'); $N = count($hobb); echo("<p>You selected $N Hobbies(s): "); for($i=0; $i < $N; $i++) { $var1=$hobb[$i]; $var2 = $level[$i]; include ('mysql_connect.php'); $table = "INSERT INTO competency_result (user_id,competency_id,level) ". "VALUES ('$id', '$var1', '$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); }
-
Am trying to import a csv file into mysql. below is the code am using. <?php //connect to the database include('mysql_connect.php');//select the table // if ($_FILES[csv] > 0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //loop through the csv file and insert into database do { if ($data[0]) { mysql_query("INSERT INTO requisition (department, contact_last, contact_email) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."' ) "); } } while ($data = fgetcsv($handle,1000,",","'")); // //redirect header('Location: import.php?success=1'); die; } ?> <!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>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> ........................................................................................................................................... On page load, it gives some erros Notice: Use of undefined constant csv - assumed 'csv' in C:\wamp\www\orango\upload_data.php on line 7 Notice: Use of undefined constant size - assumed 'size' in C:\wamp\www\orango\upload_data.php on line 7 Notice: Undefined index: csv in C:\wamp\www\orango\upload_data.php on line 7 Notice: Use of undefined constant success - assumed 'success' in C:\wamp\www\orango\upload_data.php on line 43 I try to ignore the errors to see if it would work but it didn't save in the DB. please help me out