Page 1 of 1
Sending data from a list to a database!
Posted: Wed Feb 02, 2011 1:45 pm
by paddy.brophy
Hi all,
This is my first post on the devnetwork.
I have a pretty descent grasp of the ins and outs of PHP code.
However, I am having a bit of a problem right now. At the moment, I have a PHP-SQL query which returns a list of files uploaded by others in the form of a HTML table. That's grand. Within the table I have a column for each criteria from the database with a radio button at the start of each row in the first column. This is grand too. The problem that I am having is the next step, selecting one of the files via the radio button and submitting the data from that row to another table in the database.
Is there anyone who knows how I could do this?
If anyone can help me out, I would be most grateful!!!!!!!!
Re: Sending data from a list to a database!
Posted: Wed Feb 02, 2011 2:58 pm
by Jade
Can you post your code?
Re: Sending data from a list to a database!
Posted: Wed Feb 02, 2011 3:09 pm
by paddy.brophy
I will indeed. Here it is:
Code: Select all
<?php
require("connect.php");
$query = mysql_query("Select * FROM fileSystem Where Status='Pending'") or die(mysql_error("Unable to find any data!"));
while($row = mysql_fetch_array($query))
{
$criteria1 =$row['criteria1'];
$criteria2 = $row['criteria2'];
$fileUploaded = $row['fileUploaded'];
$updatedFile = $row['updatedFile'];
$someText = $row['someText'];
$someText2 = $row['someText2'];
$Status = $row['Status'];
echo "<h2>$title</h2><br><br>";
echo "<table border='1'";
echo "<tr>
<td>Criteria 1</td>
<td>Criteria 2</td>
<td>File Uploaded</td>
<td>File Updated</td>
<td>Some Text 1</td>
<td>Some Text 2</td>
<td>Status</td>
</tr>";
echo "<tr>
<td><input type=radio name='$criteria1' VALUE='$criteria1'></td>
<td>$criteria2</td>
<td>$fileUploaded</td>
<td>$updatedFile</td>
<td>$someText</td>
<td>$someText2</td>
<td>$Status</td>
</tr>";
echo "</table>";
}
?>
Re: Sending data from a list to a database!
Posted: Wed Feb 02, 2011 3:15 pm
by Jade
You have to wrap them in a form tag with a submit button and put the values of the table into hidden inputs.
Code: Select all
<?php
require("connect.php");
if ($_POST['submit'])
echo "Your form values are: " . var_dump($_POST);
echo "<form action=# method=post>";
$query = mysql_query("Select * FROM fileSystem Where Status='Pending'") or die(mysql_error("Unable to find any data!"));
while($row = mysql_fetch_array($query))
{
$criteria1 =$row['criteria1'];
$criteria2 = $row['criteria2'];
$fileUploaded = $row['fileUploaded'];
$updatedFile = $row['updatedFile'];
$someText = $row['someText'];
$someText2 = $row['someText2'];
$Status = $row['Status'];
echo "<h2>$title</h2><br><br>";
echo "<table border='1'";
echo "<tr>
<td>Select</td>
<td>Student Names</td>
<td>Uploaded Exam Scripts</td>
<td>Corrected Exam Scripts</td>
<td>someTexts</td>
<td>Feedback Card</td>
<td>Status</td>
</tr>";
echo "<tr>
<td><input type=radio name='$criteria1' VALUE='$criteria1'></td>
<td>$criteria2 <input type=hidden name=criteria value='$critera2'></td>
<td>$fileUploaded <input type=hidden name=criteria value='$fileUploaded'></td>
<td>$updatedFile <input type=hidden name=criteria value='$updatedFile'></td>
<td>$someText <input type=hidden name=criteria value='$someText'></td>
<td>$someText2 <input type=hidden name=criteria value='$someText2'></td>
<td>$Status <input type=hidden name=criteria value='$Status'></td>
</tr>
";
echo "</table>";
}
echo "<br/><br/>
<center><input type=submit name=submit value='See Selected Row Data'></center>
</form>";
?>