Data from table to edit doesnt work mysqli and GET/POST - php

Im not a PHP pro i started php 3 weeks ago my knowledge is low.
My Problem:
In my outdex.php there is table with content read out of my database.
if i click the icon to edit a column i get to edit.php
But it doesnt shown my editable column.
My Code:
outdex.php
<?php
require('config/config.inc.php');
$sql = "SELECT id, name, Status, Strasse, Telefon, ProblemBeschreibung, Datum FROM probleme WHERE id = 1 OR id > 1";
$result = mysqli_query($db, $sql);
if(mysqli_num_rows($result) > 0) {
// Ausgabe der Daten in einer row
echo '<table class="bordered"><thead>';
echo '<tr>';
echo '<th style="display: none;">ID</th>';
echo '<th>Name</th>';
echo '<th>Status</th>';
echo '<th>Straße</th>';
echo '<th>Telefon</th>';
echo '<th>Problembeschreibung</th>';
echo '<th>Eintragsdatum</th>';
echo '<th width="36"></th>';
echo '</tr></thead>';
echo '<tbody>';
while($adr = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>" . $adr['name'] . "</td>
<td>" . $adr['Status'] . "</td>
<td>" . $adr['Strasse'] . "</td>
<td>" . $adr['Telefon'] . "</td>
<td>" . $adr['ProblemBeschreibung'] . "</td>
<td>" . $adr['Datum'] . "</td>
<td>
<div id=\"test\">
<div id=\"div1\"><form action='edit.php' method='GET'>
<input type='hidden' name='id' value='" .htmlspecialchars($adr['id'], ENT_COMPAT, 'UTF-8') . "'/>
<input type='hidden' name='name' value='".htmlspecialchars($adr['name'], ENT_COMPAT, 'UTF-8')."'/>
<input type='hidden' name='Status' value='".htmlspecialchars($adr['Status'], ENT_COMPAT, 'UTF-8')."'/>
<input type='hidden' name='Strasse' value='".htmlspecialchars($adr['Strasse'], ENT_COMPAT, 'UTF-8')."'/>
<input type='hidden' name='Telefon' value='".htmlspecialchars($adr['Telefon'], ENT_COMPAT, 'UTF-8')."'/>
<input type='hidden' name='ProblemBeschreibung' value='".htmlspecialchars($adr['ProblemBeschreibung'], ENT_COMPAT, 'UTF-8')."'/>
<input type='hidden' name='Datum' value='".htmlspecialchars($adr['Datum'], ENT_COMPAT, 'UTF-8')."'/>
<input type='image' src='edit.png' height='16' width='16' name='edit' value='Bearbeiten' onClick=\"self.location.href='edit.php?=\">
</form></div>
<div id=\"div2\">
<form action='delete.php' method='POST'>
<input type='hidden' name='id' value='" . htmlspecialchars($adr['id'], ENT_COMPAT, 'UTF-8') . "'/>
<input type='image' src='delete.png' height='16' width='16' name='delete' value='Löschen' onClick=\"self.location.href='delete.php?\">
</form></div>
</div>
</td>
</tr>\n";
}
echo "</tbody></table>";
} else {
echo "0 Einträge gefunden<br>Es konnten keine Einträge in der Datenbank gefunden werden.";
}
mysqli_close($db);
?>
My edit.php
<table class="bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
<th>Strasse</th>
<th>Telefon</th>
<th>Problembeschreibung</th>
<th>Eintragsdatum</th>
</tr>
</thead>
<?php
include('config.inc.php');
if(isset($_GET['id'])){
$id = $_GET['id'];
} else {
die('Bitte eine ?id übergeben');
}
$statement = $pdo->prepare("SELECT * FROM probleme WHERE id = ?");
$statement->execute(array($id));
while($row = $statement->fetch()){
echo "<tr>
<form method='post' action='edit1.php'>
<td><input name='id' type='text' value='".$id."'</input></td>
<td><input name='name' type='text' value='" .$row['name']."'</input></td>
<td>
<select name='Status'>
<option>".$row['Status']."</option>
<option>FINISHED</option>
</select>
</td>
<td><input name='Strasse' type='text' value='".$row['Strasse']."'</input></td>
<td><input name='Telefon' type='number' value='".$row['Telefon']."'</input></td>
<td><input name='ProblemBeschreibung' type='text' value='".$row['ProblemBeschreibung']."'</input></td>
<td>".$row['Datum']."</td>
</tr>
</table>";
echo "
<input type='submit' value='Absenden' />
</form>";
}
?>
If I change GET to POST it doesnt work too.
hope you can help me.

Related

passing of multiple arrays in <form> object html/php

I have a HTML/PHP(MySql) related question
I just have troubles finding out how to pass more than one array to the same row in a database
Code: (- at the start of the page)
<?php
if ( isset($_POST['logActivity']) ) {
$date = trim($_POST['date']);
$date = strip_tags($date);
$date = htmlspecialchars($date); //Aquiring a date() function variable
foreach ($_POST['activity'] as $activity => $value){
$query="INSERT INTO monitorlog(dateofentry,activity)
VALUES ('$date','$value')";
mysqli_query($conn,$query);
}} ?>
(In the < body> section)
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
<table>
<tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr><td>
<button type='submit' class='mybuttons' name='button'>Log to database</button>
</td></tr>
</table>
</form>
The code above successfully inputs the data of $activity in the database but it also limits the value of the input to $activity's value on that particular row in the database, whereas I need to pass both activity and activity2 to the same row.
Feels like I've tried everything by now to no effect. Hope you guys can help me
Best regards.

insert multiple rows of data by single submit button using php

How do I retrieve data from a SQL table, modify the data and store it in another database table with multiple rows & columns and with single submit button I want insert every rows at a time I don't know how to get that hidden value and work properly with that
<?php
include"connect_database.php";
if(isset($_POST['submit'])) {
$amt = $_POST['total'];
if($amt > 0) {
$qry = "INSERT INTO attendance(rollno, name, year, attendance, reason) VALUES "; // Split the mysql_query
for($i=1; $i<=$amt; $i++) {
$qry .= "('".$_POST["rollno$i"]."', '".$_POST["name$i"]."', '".$_POST["year$i"]."', '".$_POST["attendance$i"]."', '".$_POST["reason$i"]."' ),"; // loop the mysql_query values to avoid more server loding time
}
$qry = substr($qry, 0, strlen($qry)-2);
$insert = mysqli_query($dbcon, $qry); // Execute the mysql_query
}
// Redirect for each cases
if($insert) {
$msg = '<script type="text/javascript">alert("added");</script>';
}
else {
$msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
}
};
if (isset($_POST['select']))
{
$sql = "SELECT * FROM data WHERE year='" . $_POST['yr'] . "'";
$myData = mysqli_query($dbcon, $sql);
$num = mysqli_num_rows($myData);
echo "<table border=1>
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Year</th>
<th>Attendance</th>
<th>reason</th>
</tr>";
for ($i=0; $i <$num; $i++)
{
$record = mysqli_fetch_array($myData);
echo "<form action=smanage.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=rollno$i value=" . $record['rollno'] . " </td>";
echo "<td>" . "<input type=text name=name$i value=" . $record['name'] . " </td>";
echo "<td>" . "<input type=text name=year$i value=" . $record['year'] . " </td>";
echo "<td> "."<select name=attendance$i >
<option value=Present >present</option>
<option value=Absent >Absent</option>
</select>"."</td>";
echo "<td>". "<textarea cols=15 rows=2 name=reason$i placeholder=Enter reason ...></textarea>" . "</td>" ;
echo "<td>" . "<input type=hidden name=total value=" . $i-1 . "</td>";
echo "</tr>";
}
echo"</table>";
echo "<input type=submit name=submit value=save class=Button3>";
echo "</form>";
};
mysqli_close($dbcon);
?>
you are opening multiple forms, for each row in your table on.
This causes your html to be invalid, just start the form before displaying the table.
You could use this html
<table>
<?php
for ($i = 0; $i < $num; $i++) {
$record = mysqli_fetch_array($myData);
?>
<tr>
<td><input type="text" name="rollno[<?= $record['rollno'] ?>]" value="<?= $record['rollno'] ?>" </td>
<td><input type="text" name="name[<?= $record['rollno'] ?>]" value="<?= $record['name']?>" </td>
<td><input type="text" name="year[<?= $record['rollno'] ?>]" value="<?= $record['year'] ?>" </td>
<td><select name="attendance[<?= $record['rollno'] ?>]" >
<option value="Present" >present</option>
<option value="Absent" >Absent</option>
</select></td>
<td><textarea cols="15" rows="2" name="reason[<?= $record['rollno'] ?>]" placeholder="Enter reason ..."></textarea></td>
</tr>
<?php
}
?>
</table>
with this your values will every row will be put into the $_POST-Array, you can access the values via the indexes (I am guessing rollno represents the ID of the dataset).
When you really only want to insert all the values into a table, you can leave the index out. Meaning you could write
<td><input type="text" name="rollno[]" value="<?= $record['rollno'] ?>" </td>
Instead of
<td><input type="text" name="rollno[<?= $record['rollno'] ?>]" value="<?= $record['rollno'] ?>" </td>
You don't need the hidden field, you can just count the items in the array.
$total = count($_POST['rollno']);
<?php
include"connect_database.php";
if(isset($_POST['submit'])) {
$amt = $_POST['total'];
$rollnos= $_POST['rollno'];
if($amt > 0) {
$qry = "INSERT INTO attendance(rollno, name, year, attendance, reason) VALUES "; // Split the mysql_query
$i=0;
foreach($rollnos as $rollno) {
$qry .= "('".$rollno."', '".$_POST["name"][$i]."', '".$_POST["year"][$i]."', '".$_POST["attendance"][$i]."', '".$_POST["reason"][$i]."' ),"; // loop the mysql_query values to avoid more server loding time
$i=$i+1;
}
$qry = substr($qry, 0, strlen($qry)-2);
$insert = mysqli_query($dbcon, $qry); // Execute the mysql_query
}
// Redirect for each cases
if($insert) {
$msg = '<script type="text/javascript">alert("added");</script>';
}
else {
$msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
}
};
if (isset($_POST['select']))
{
$sql = "SELECT * FROM data WHERE year='" . $_POST['yr'] . "'";
$myData = mysqli_query($dbcon, $sql);
$num = mysqli_num_rows($myData);
echo "<table border=1>
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Year</th>
<th>Attendance</th>
<th>reason</th>
</tr>";
for ($i=0; $i <$num; $i++)
{
$record = mysqli_fetch_array($myData);
echo "<form action=smanage.php method=post>";
echo "<tr>";
echo "<td>" . "<input type='text' name='rollno[]' value='" . $record['rollno'] . "'> </td>";
echo "<td>" . "<input type='text' name='name[]' value='" . $record['name'] . "'> </td>";
echo "<td>" . "<input type='text' name='year[]' value='" . $record['year'] . "'> </td>";
echo "<td> "."<select name='attendance[]' >
<option value='Present' >present</option>
<option value='Absent' >Absent</option>
</select>"."</td>";
echo "<td>". "<textarea cols='15' rows='2' name='reason[]' placeholder='Enter reason ...'></textarea>" . "</td>" ;
echo "<td></td>";
echo "</tr>";
}
echo "<input type='hidden' name='total' value='" . $i-1 . "'>";
echo"</table>";
echo "<input type='submit' name='submit' value='save' class='Button3'>";
echo "</form>";
};
mysqli_close($dbcon);
?>

not understanding mysqli_fetch_array

So i guess i don't understand this i am a very newbie to coding in general. I have searched and can't find a good enogh explanation to get it to work in my situatation. I need to fill a table from a fetch command then update each result with an input of information into a new column. Here is the code i have:
This fills the table:
echo "<table border='1'>
<tr>
<th>Envelope</th>
<th>Budget</th>
<th>Amount</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['envelopename'] . "</td>";
echo "<td>" . $row['envelopebudget'] . "</td>";
?><td><input type="text" name="budgetamount"></td><?php;
echo "</tr>";
}
echo "</table>";
?>
<input type="submit">
And this writes the input for budgetname into the column budgetname:
$paycheckname = mysqli_real_escape_string($con, $_POST['paycheckname']);
$budgetamount = mysqli_real_escape_string($con, $_POST['budgetamount']);
$envelopename = mysqli_real_escape_string($con, $_POST['envelopename']);
}
$sql="UPDATE envelopes SET $paycheckname='$budgetamount' WHERE envelopename ='$envelopename'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
Right now it just doesn't write anything. I have used echo var_dump($envelopename)."<br>"; and echo var_dump($budgetamount)."<br>"; to try and see what it is doing but $envelopename is always blank. Thanks for any help you can provide.
only <input> , <textarea>, <select> and <button> are submitted to the server in a form
If you want to re-submit some static values create some hidden inputs
while($row = mysqli_fetch_array($result)) {
echo "<input type='hidden' value='$row[envelopename]' name='envelopename'/>";
echo "<input type='hidden' value='$row[envelopebudget]' name='envelopebudget'/>";
echo "<tr>";
echo "<td>" . $row['envelopename'] . "</td>";
echo "<td>" . $row['envelopebudget'] . "</td>";
?><td><input type="text" name="budgetamount"></td><?php;
echo "</tr>";
}
echo "</table>";
But your next issue will be that you're creating the elements in a loop so you'll have multiple inputs with the same name
<tr>
<input type='hidden' value='envName1' name='envelopename'/>
<input type='hidden' value='envBudget1' name='envelopename'/>
<td>envName1</td>
<td>envBudget1</td>
<td><input type="text" name="budgetamount"></td>
</tr>
<tr>
<input type='hidden' value='envName2' name='envelopename'/>
<input type='hidden' value='envBudget2' name='envelopename'/>
<td>envName2</td>
<td>envBudget2</td>
<td><input type="text" name="budgetamount"></td>
</tr>
so you must submit as an array
while($row = mysqli_fetch_array($result)) {
echo "<input type='hidden' value='$row[envelopename]' name='envelopename[]'/>";
echo "<input type='hidden' value='$row[envelopebudget]' name='envelopebudget[]'/>";
echo "<tr>";
echo "<td>" . $row['envelopename'] . "</td>";
echo "<td>" . $row['envelopebudget'] . "</td>";
?><td><input type="text" name="budgetamount[]"></td><?php;
echo "</tr>";
}
echo "</table>";
and at the server end process as an array
foreach ($_POST['budgetamount'] as $budgetamount){
echo $budgetamount. '<br>';
}
suppose the form rendered looks like this:
<tr>
<input type='hidden' value='envName1' name='envelopename[]'/>
<input type='hidden' value='envBudget1' name='envelopebudget[]'/>
<td>envName1</td>
<td>envBudget1</td>
<td><input type="text" name="budgetamount[]"></td>
</tr>
<tr>
<input type='hidden' value='envName2' name='envelopename[]'/>
<input type='hidden' value='envBudget2' name='envelopebudget[]'/>
<td>envName2</td>
<td>envBudget2</td>
<td><input type="text" name="budgetamount[]"></td>
</tr>
<tr>
<input type='hidden' value='envName3' name='envelopename[]'/>
<input type='hidden' value='envBudget3' name='envelopebudget[]'/>
<td>envName3</td>
<td>envBudget3</td>
<td><input type="text" name="budgetamount[]"></td>
</tr>
when the user hits submit the $_POST that arrives at newpaycheck.php will look like:
$_POST
['envelopename']{
[0]=>'envName1',
[1]=>'envName2',
[2]=>'envName3'
},['envelopebudget']{
[0]=>'envBudget1',
[1]=>'envBudget2',
[2]=>'envBudget3'
},['budgetamount']{
[0]=>'someValueEnteredByUser',
[1]=>'anotherValueEnteredByUser',
[2]=>'yetAnotherValueEnteredByUser'
}
so you can do something like this:
foreach ($_POST['envelopename'] as $envelopename){
$arrayIndex = array_search($envelopename,$_POST['envelopename']);
$envelopebudget = $_POST['envelopebudget'][$arrayIndex];
$budgetamount= $_POST['budgetamount'][$arrayIndex];
$paycheckname = mysqli_real_escape_string($con, $envelopebudget);
$budgetamount = mysqli_real_escape_string($con,$budgetamount);
$envelopename = mysqli_real_escape_string($con,$envelopename);
$sql="UPDATE envelopes SET $paycheckname='$budgetamount' WHERE envelopename ='$envelopename'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
}

Values not Posted in the Database

I want to take attendance of a particular class and store the values in database.
I have used INNER JOIN to get the data from two tables and used those tables values in a form name attendance.
Now once i take attendance using the form i want to store that values in my database so i created another file name insertattendance.php.
The problem is it shows undefined index variables. ex.undefined index classid ..etc
so i tried using it in *if(isset($_POST['submit'])* There is no erros but the values are not posted.
My doubt is since iam using the values of my old tables is it showing error?.
Tell me how can i do this?
attendance.php
<html>
<head>
<title>grade1</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
<tr>
<th>classid</th>
<th>studentid</th>
<th>teacherid</th>
<th>locid</th>
<th>date</th>
<th>flag</th>
<th>comments</th>
</tr>
<?php
include 'conn.php';
$query = "(SELECT a.classid, a.fname, b.teacherid, c.locid
FROM class_master c JOIN student_master a
ON c.classid = a.classid JOIN teacher_link b
ON c.classid = b.classid
WHERE c.classid = 'grade1' )";
$result = mysql_query($query);
$i=1;
while( $row = mysql_fetch_array($result))
{
echo "<form action=insertattend.php method=POST>";
echo "<tr>";
echo "<td>" . "<input name=classid[$i] type=text value=" .$row['classid']." </td>";
echo "<td>" . "<input name=fname[$i] type=text value=" .$row['fname']." </td>";
echo "<td>" . "<input name=teacherid[$i] type=number value="
.$row['teacherid']." </td>";
echo "<td>" . "<input type=number name=locid[$i] value=" .$row['locid']." </td>";
echo "<td>" . "<input name=date[$i] type=date value='date'></td>";
echo "<td>" . "<input type=radio id=attend name=attend[$i] value='present'>";?>P
<?php echo "<input type=radio id=attend name=attend[$i] value='absent'>";?>A
<?php
echo"</td>";
echo "<td><input name=comment type=comment[$i] row=3 column=5></td>";
echo "</tr>";
$i++;
}
?>
</table>
<input type="submit" value="submit">
</form>
</body>
</html>
Here is my Insertattendance.php code
<?php
if (isset($_POST['submit'])){
include 'conn.php';
$clnm = mysql_real_escape_string($_POST['classid']);
$stfn = mysql_real_escape_string($_POST['fname']);
$dt = mysql_real_escape_string($_POST['date']);
$fg = mysql_real_escape_string($_POST['attend']);
$tid = mysql_real_escape_string($_POST['teacherid']);
$lid = mysql_real_escape_string($_POST['locid']);
$cmt = mysql_real_escape_string($_POST['comment']);
$inquery =("INSERT INTO attendance(classid, studentid, dateid, flag, teacherid,
locid, comments) VALUES('$clnm', '$stfn', '$dt', '$fg', '$tid', '$lid', '$cmt')");
mysql_query($inquery, $dbconnection);
echo "<br>";
echo "values inserted successfully!!!!";
mysql_close($dbconnection);
};
?>
Fix your html code:
<html>
<head>
<title>grade1</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
<tr>
<th>classid</th>
<th>studentid</th>
<th>teacherid</th>
<th>locid</th>
<th>date</th>
<th>flag</th>
<th>comments</th>
</tr>
<?php
include 'conn.php';
$query = "(SELECT a.classid, a.fname, b.teacherid, c.locid
FROM class_master c JOIN student_master a
ON c.classid = a.classid JOIN teacher_link b
ON c.classid = b.classid
WHERE c.classid = 'grade1' )";
$result = mysql_query($query);
while( $row = mysql_fetch_array($result))
{
echo "<form action='insertattend.php' method='POST'>";
echo "<tr>";
echo "<td>" . "<input name=classid type=text value=" .$row['classid']." ></td>";
echo "<td>" . "<input name=fname type=text value=" .$row['fname']." ></td>";
echo "<td>" . "<input name=teacherid type=number value=" .$row['teacherid']." ></td>";
echo "<td>" . "<input type=number name=locid value=" .$row['locid']." ></td>";
echo "<td>" . "<input name=date type=date value='date'></td>";
echo "<td>" . "<input type=radio id=attend name=attend value='present'>";?>P
<?php echo "<input type=radio id=attend name=attend value='absent'>";?>A
<?php
echo"</td>";
echo "<td><input name=comment type=comment row=3 column=5></td>";
echo "</tr>";
//echo "</form>";
?>
<input type="submit" name="submit" value="submit">
</form>
<?php } ?>
<!--<form action="insertattend.php">-->
</table>
</body>
</html>
These changes ought to be done on your attendance.php code
First move this echo "<form action=insertattend.php method=POST>"; out of your while
Actually you are closing the <form> tag before the submit button.
echo "</tr>";
echo "</form>"; //<--- Comment or Remove this line
Also, remove this line too (because you already defined above the while loop)
<form action="insertattend.php"> <!-- Remove this line -->
<input type="submit" value="submit">
</form>
Another thing is.. echo "<td><input name=comment type=comment row=3 column=5></td>"; I don't think there is something called type=comment replace that to type=text or use a <textarea>
You missed name="submit" in your attendance.php form.
<input type="submit" name="submit" value="submit">
use form opening and closing tags like this:
<html>
<head>
<title>grade1</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
<tr>
<th>classid</th>
<th>studentid</th>
<th>teacherid</th>
<th>locid</th>
<th>date</th>
<th>flag</th>
<th>comments</th>
</tr>
<?php
include 'conn.php';
$query = "(SELECT a.classid, a.fname, b.teacherid, c.locid
FROM class_master c JOIN student_master a
ON c.classid = a.classid JOIN teacher_link b
ON c.classid = b.classid
WHERE c.classid = 'grade1' )";
$result = mysql_query($query);
?>
<form action=insertattend.php method=POST>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . "<input name='classid[]' type=text value=" . $row['classid'] . " </td>";
echo "<td>" . "<input name='fname[]' type=text value=" . $row['fname'] . " </td>";
echo "<td>" . "<input name='teacherid[]' type=number value=" . $row['teacherid'] . " </td>";
echo "<td>" . "<input type=number name='locid[]' value=" . $row['locid'] . " </td>";
echo "<td>" . "<input name='date[]' type=date value='date'></td>";
echo "<td>" . "<input type=radio id=attend name='attend[]' value='present'>";
?>P
<?php echo "<input type=radio id=attend name='attend[]' value='absent'>"; ?>A
<?php
echo"</td>";
echo "<td><input name='comment[]' type=comment row=3 column=5></td>";
echo "</tr>";
}
?>
</table>
<input type="submit" name= "submit" value="submit">
</form>
</body>
</html>
You have to post the values as array in form fields inside the loop. Then you have to get the array of post values in foreach to insert all the records to the database.
There are two forms.
Input types are in one form and submit button in another one.So avoid that and put together in one form.There is no need for another form with same action value. There are more than one student so write form outside while loop and then array name for input values. Then in php page values in array so use loop to get all values seperately.
<html>
<head>
<title>grade1</title>
</head>
<body>
<form action=insertattend.php method=POST>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
<tr>
<th>classid</th>
<th>studentid</th>
<th>teacherid</th>
<th>locid</th>
<th>date</th>
<th>flag</th>
<th>comments</th>
</tr>
<?php
include 'conn.php';
$query = "(SELECT a.classid, a.fname, b.teacherid, c.locid
FROM class_master c JOIN student_master a
ON c.classid = a.classid JOIN teacher_link b
ON c.classid = b.classid
WHERE c.classid = 'grade1' )";
$result = mysql_query($query);
$i=1;
while( $row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input name=classid[] type=text value=" .$row['classid']." </td>";
echo "<td>" . "<input name=fname[] type=text value=" .$row['fname']." </td>";
echo "<td>" . "<input name=teacherid[] type=number value="
.$row['teacherid']." </td>";
echo "<td>" . "<input type=number name=locid[] value=" .$row['locid']." </td>";
echo "<td>" . "<input name=date[] type=date value='date'></td>";
echo "<td>" . "<input type=radio id=attend name=attend[] value='present'>";?>P
<?php echo "<input type=radio id=attend name=attend[] value='absent'>";?>A
<?php
echo"</td>";
echo "<td><input name=comment[] type=text row=3 column=5></td>";
echo "</tr>";
}
?>
</table>
<input type="submit" value="submit">
</form>
</body>
</html>
And in php page you take size of any of the coming array
For eg:sizeof(classid);using that write for loop to accept values

MySQL data not fully being shown in html table. Data gets cut off and leaves half the field not the full

Here's the Code.
$result = mysql_query("SELECT * FROM situations");
echo "<table border='1'>
<tr>
<th>Case#</th>
<th>Cop(s)</th>
<th>Code</th>
<th>Vehicle/Person</th>
<th>Location</th>
<th>Division(s)</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<form action=situations.php method=post>";
echo "<tr>";
echo "<td>" . $row['Case#'] . " </td>";
echo "<td>" . "<input type=text name=cop value=" . $row['Cops']. " </td>";
echo "<td>" . "<input type=text name=sector value=". $row['Code'] . " </td>";
echo "<td>" . "<input type=text name=vehicle value=" . $row['Vehicle'] ." </td>";
echo "<td>" . "<input type=text name=location value=" .$row['Location']. " </td>";
echo "<td>" . "<input type=text name=division value=" .$row['Division']. " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" .$row['Case #'] . " </td>";
echo "<td>" . "<input type=submit name=update_situations value=Update" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
I have it so I can update it but my data is not fully shown. EX: I would have "Dukes Blvd" in Location and it would only show "Dukes" Please Help! and I am newb to PHP, MySQL.
You're missing quotes;
while($row = mysql_fetch_array($result))
{
?>
<form action="situations.php" method="post">
<tr>
<td><?php echo $row['Case#']; ?></td>
<td><input type="text" name="cop" value="<?php echo htmlentities($row['Cops'], ENT_QUOTES, 'UTF-8') ; ?>"></td>
<td><input type="text" name="sector" value="<?php echo htmlentities($row['Code'], ENT_QUOTES, 'UTF-8'); ?>"></td>
<td><input type="text" name="vehicle" value="<?php echo htmlentities($row['Vehicle'], ENT_QUOTES, 'UTF-8'); ?>"></td>
<td><input type="text" name="location" value="<?php echo htmlentities($row['Location'], ENT_QUOTES, 'UTF-8'); ?>"></td>
<td><input type="text" name="division" value="<?php echo htmlentities($row['Division'], ENT_QUOTES, 'UTF-8'); ?>"></td>
<td><input type="hidden" name="hidden" value="<?php echo htmlentities($row['Case #'], ENT_QUOTES, 'UTF-8'); ?>"></td>
<td><input type="submit" name="update_situations" value="Update"></td>
</tr>
</form>
<?php
}
?>
</table>
I don't disagree with ntgCleaner about ending PHP although some times its extra work. If you always use the same rules for quotes its not to big a problem plus after a while you recognize the syntax error right off or it is usually the first thing I look for when I get one. I always start with a single quote followed by a double quote inside the html portions.
echo 'some code "quoted code" more code'.$variable;
You can also use a backslash to id the quote \' to separate it from an error state.

Categories