Im having an issue with fetch_array. I keep getting the return of record not found. With every thing that I have looked at it seems to me that this code should work. Sorry im new to php web development.
$JobNumber = NULL;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$JobID = $_POST['jobid'];
include('pmconnect.php');
$sql="SELECT * FROM tblJobMaster WHERE JobNumber=" . $JobID;
$result=$conn->query($sql);
if ($result->num_rows==0)
{
echo "Record not found.<br>";
die(0);
}
$row=$result->fetch_array();
echo '<table style="text-align: left; width: 100%;" border="1" cellpadding="2" cellspacing="2">';
echo "<tbody>";
echo "<tr>";
echo '<td style="vertical-align: top; text-align: right;">Job Number:<br>';
echo "</td>";
echo '<td style="vertical-align: top;">' .$row[0] . '<br>';
echo "</td>";
echo '<td style="vertical-align: top; text-align: right;">Engineer:<br>';
echo '</td>';
echo '<td style="vertical-align: top;">' . $row[3] .'<br>';
echo '</td>';
echo "</tr>";
echo "<form action=pmAssignEngineer2.php method=post id=usrform>";
echo "<input type=hidden name=JobID value=" . $JobID . ">";
echo "<input type=submit value=\"Update\" name=lookup>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</tbody>";
}
else
{
echo "<form action=pmAssignEngineer.php method=post>";
echo "<table border=2>";
echo "<tr>";
echo "<td>Job Number:</td>";
echo "<td><input type=text name=JobID></td>";
echo "</tr>";
echo "</table>";
echo "<input type=submit value=\"Lookup\" name=lookupQ><br>";
echo "</form>";
}
HTML elements are posted to $_POST if form method is post.
The element name is key and value is array value.
And the keys are case-sensitive.
In your case, your element has name JobID and you are referring jobid.
Obviously, the keys of $_POST do not match as jobid and JobID are different.
<input type=text name=JobID>
So, update the following line:
$JobID = $_POST['jobid'];
To
$JobID = $_POST['JobID'];
Related
I need to get the data of the database to an HTML table.
There were similar questions asked before but none of them were similar to my requirement.
I need to get the first row of the database to the first row of the table.
So I did this.
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] . Number:".$row["status"] . "</td>";
echo "</tr> </form>";
}//End of While
echo "</tbody></table>";
There is a syntax error in line 55 as mentioned above in the code.
Check this code:
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
echo "<td> Board Code:".$row["board_code"]. "</td>";
echo "<td>Number:".$row["status"]. "</td>";
echo "</tr> </form>";
}
echo "</tbody></table>";
"<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
edit your code like if it does not work please share your whole code will help you for sure
Check with this code
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
echo "</tr> </form>";
Hi I'm creating a questionnaire. The questions and their answers are stored in a table like so:
Now, I want to display the questions and their answers in a table where I get the questions and their possible answers on different rows. Like so:
In my php file, I echo the table and the rows but I cannot figure out how to put the questions and answer in different rows. here is how it looks like:
and here is my php code:
<?php
session_start();
$status=$_GET["status"];
include 'dbh.inc.php';
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
text-align: left;
padding: 8px;
}
#td_box{
text-align: center;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #006689;
color: white;
}
</style>
</head>
<body>
<?php
if ($status=="disp") {
$sql="SELECT * FROM questions";
$result = mysqli_query($conn,$sql);
echo "<table>";
while ($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"; echo $row["question"]; echo "</td>";
echo "<td>"; echo $row["optionA"];echo $row["optionB"];echo $row["optionC"];
echo $row["optionD"];echo $row["optionE"];echo "</td>";
}
}
echo "</table>";
?>
</body>
</html>
Try:
<?php
if ($status=="disp") {
$sql="SELECT * FROM questions";
$result = mysqli_query($conn,$sql);
echo "<table>";
while ($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"; echo $row["optionA"];echo $row["optionB"];echo $row["optionC"];
echo $row["optionD"];echo $row["optionE"];echo "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
What I did:
I added a </tr> after your question echo and opend a new one directly after. Then I closed that <tr> after your last <td> as you forgot to do that.
1st : Put all option radio buttons in another tr .
2nd : Maintain proper name attribute for radio button .name="question[$row['question_id']]"
3rd : And use colspan="4" for question td
while ($row=mysqli_fetch_array($result)) {
echo "<tr >";
echo "<td colspan='4'>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionA']\" >".$row['optionA'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionB']\" >".$row['optionB'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionC']\" >".$row['optionC'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionD']\" >".$row['optionD'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionE']\" >".$row['optionE'];
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan='4'>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"; echo $row["optionA"];echo "</td>";
echo "<td>"; echo $row["optionB"];echo "</td>";
echo "<td>"; echo $row["optionC"];echo "</td>";
echo "<td>"; echo $row["optionD"];echo "</td>";
echo "</tr>";
this way you will have proper answers in tabular format in aligned manner
I have a table of values that I am trying to update only the date of. I have a checkbox that I want only the select rows to updated when its checked and user clicks the submit button. The issue I am having is let's say I have 4 records and I only want record 1,2 and 4 updated. What is happening is records 1,2 and 3 are being updated. I know it has something to do with the array in the foreach loop. Side note I know the sql code allows for injection I am trying to get this to work first before worrying about that. Thank you for any and all help and time.
Table Code
$sql = "SELECT * FROM tblUnitMaster WHERE JobNumber = '" . $JobNumber . "' AND `EngReleaseDate` IS NULL OR `EngReleaseDate` = '' ORDER BY UnitID";
$result=$conn->query($sql);
echo "<style>";
echo "th {";
echo "background-color: #6EB4FF;";
echo "color: white;";
echo "}";
echo "</style>";
echo "<form action=pmReleaseEngineering3.php method=post>";
echo "<input type=hidden name=JobNumber value=$JobNumber />";
echo "<table border=2 cellpadding=4 cellspacing=10>";
echo "<tr>";
echo "<th><b><font size=4></font></b></th>";
echo "<th><b><font size=4>"."Job"."</font></b></th>";
echo "<th><b><font size=4>"."Code"."</font></b></th>";
echo "<th><b><font size=4>"."Model Number"."</font><?b></th>";
echo "<th><b><font size=4>"."Serial Number"."</font><?b></th>";
echo "<th><b><font size=4>"."Scope"."</font></b></th>";
echo "<th><b><font size=4>"."Date"."</font></b></th>";
echo "</tr>";
while ($row=$result->fetch_array())
{
echo "<tr>";
//echo "<td><font color=silver size=4>".$row[0]."</font></td>"; // Unit Number
echo "<td><input type=checkbox name=check[] value=".$row[0]." checked></td>";
echo "<td><input name=UnitID type=text font color=silver size=3 value=".$row[0]." readonly/></td>"; // Unit Number
echo "<td><font color=silver size=4>".$row[5]."</font></td>"; // Job Code
echo "<td><font color=silver size=4>".$row[2]."</font></td>"; // Model Number
echo "<td><font color=silver size=4>".$row[3]."</font></td>"; // Serial Number
echo "<td><font color=silver size=4>".$row[4]."</font></td>"; // Scope
echo "<td><input name=EngReleaseDate size=6 type=datetime value=" . date('Y-m-d'). " /></td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<button class=button style=vertical-align:middle><span>Submit</span></button>";
echo "</form>";
echo "<br>";
PHP SQL Update TBL Code
include('pmconnect.php');
$JobNumber=$_REQUEST['JobNumber']; //array
$UnitID=$_POST['UnitID']; // array
$EngReleaseDate=$_POST['EngReleaseDate']; // array
if(isset($_POST['check'])){
//if(!empty($_POST['check'])) {
foreach($_POST['check'] as $a => $B){
$sql = "UPDATE tblUnitMaster SET " .
"EngReleaseDate='" . $EngReleaseDate . "'" .
"WHERE UnitID='" . $UnitID . "'";
//$result=$conn->query($sql);
if ($conn->multi_query($sql) === TRUE)
echo "<table border=1 cellpadding=4 cellspacing=10>";
echo "<tbody>";
echo "<tr>";
echo "<td><b><font size=4>Unit ID</font></b></td>";
echo "<td><b><font size=4>Eng. Release</font></b></td>";
echo "</tr>";
echo "<tr>";
echo "<td><font size=4> $UnitID </font></td>";
echo "<td><font size=4> $EngReleaseDate </font></td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo"<br>";
}
}
I've posted my code below. I can able to fetch the text values from database. But, i'm unable to fetch the image. i don't know where i made mistake?
try
{
$stmt = $conn->prepare("SELECT * FROM ebusers");
$conn->errorInfo();
$stmt->execute();
while($userrow = $stmt->fetch())
{
echo "<table class=glowing width=800 border=0 align=center cellpadding=0 cellspacing=0>";
echo "<tr>";
echo "<td height=40 colspan=3 class=user_id >User ID : " . $userrow['UserID'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=wheat colspan=3> </td>";
echo "</tr>";
echo "<tr>";
echo '<td width=334 rowspan=9 bgcolor=wheat align=center >';
if( $userrow['UserProfilePicture'] >= '[BLOB - 0B]' )
{
echo '<img class=shadow_img width=160 height=180 src="data:image/png;base64,' . base64_encode($userrow['UserProfilePicture']) . '"/>';
}
else
{
echo '<img src=\'images/nophoto.gif\' class=shadow_img width=160 height=180 />';
}
echo "<tr>";
echo "<td bgcolor=wheat style=\"border-bottom-right-radius:5px; border-bottom-left-radius:5px;\" colspan=3> </td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<br>";
}
}
catch(PDOException $e)
{
'Error : ' .$e->getMessage();
}
I've posted my code below. I can able to fetch the text values from database. But, i'm unable to fetch the image. i don't know where i made mistake?
try
{
$stmt = $conn->prepare("SELECT * FROM ebusers");
$conn->errorInfo();
$stmt->execute();
while($userrow = $stmt->fetch())
{
echo "<table class=glowing width=800 border=0 align=center cellpadding=0 cellspacing=0>";
echo "<tr>";
echo "<td height=40 colspan=3 class=user_id >User ID : " . $userrow['UserID'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=wheat colspan=3> </td>";
echo "</tr>";
echo "<tr>";
echo '<td width=334 rowspan=9 bgcolor=wheat align=center >';
if( $userrow['UserProfilePicture'] >= '[BLOB - 0B]' )
{
echo '<img class=shadow_img width=160 height=180 src="data:image/png;base64,' . base64_encode($userrow['UserProfilePicture']) . '"/>';
}
else
{
echo '<img src=\'images/nophoto.gif\' class=shadow_img width=160 height=180 />';
}
echo "<tr>";
echo "<td bgcolor=wheat style=\"border-bottom-right-radius:5px; border-bottom-left-radius:5px;\" colspan=3> </td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<br>";
}
}
catch(PDOException $e)
{
'Error : ' .$e->getMessage();
}