Gilly79 Posted March 29, 2010 Share Posted March 29, 2010 Hello Im re-wording the previous post i did! Im doing a Select on mysql database - Im displaying this in a table however i also want the value to be in a hidden form which passes variables to another page I do not know how to display .$row["Report_Message"]. in a form that i have specified at the foot of my page.. Currently i have <input name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" ></input><br /> yet this is not working - any ideas please its doing my sweede in!! Many thanks page attatched.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/ Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 Hidden form field <input type="hidden" name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" /> Or <form action="whatever.php"> <div style="display:none;"> <input type="text" name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" /> </div> <input type="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/#findComment-1033780 Share on other sites More sharing options...
Gilly79 Posted March 29, 2010 Author Share Posted March 29, 2010 Hi - I have the form part covered but the solution you gave regarding the <input type="text" name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" /> dosn't work...? could it be something else im doing? Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/#findComment-1033784 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 You are wanting this input hidden correct? <input type="hidden" name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" /> <!-- OR --> <input style="display:none;" type="text" name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/#findComment-1033801 Share on other sites More sharing options...
Gilly79 Posted March 30, 2010 Author Share Posted March 30, 2010 Hi - this is still not working - Is it something im doing on the page elsewhere preventing it working?? Ive even not hidden the form so I can tell if it is being populated or not the fields subject and report message are not being populated in the form - The only fields being populated in the form are the vars being passed from the previous calling page I cant seem to reference anything from my select statement... below is the code <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'View Selcted Student Report Report'; require_once('header.php'); // ========== SCOTT ============== //Include the connection details, open $connection and select database //include ("connection.php"); require_once('connectvars.php'); //vars $user_id = $_SESSION['user_id']; $Report_ID = $_GET['Report_id'] ; $user_idp = $_GET['user_idp'] ; $sfirst_name = $_GET['sfirst_name'] ; $ssurname = $_GET['ssurname'] ; $Overall_Grade = $_GET['Overall_Grade'] ; $Date = $_GET['Date'] ; echo $user_id; echo $Report_ID; echo $user_idp; echo $sfirst_name; echo $Overall_Grade; echo $Date; echo $ssurname; ?> <?php //Prepare query $query = "SELECT Student_Reports.Report_ID, Student_Reports.Subject, Student_Reports.Overall_Grade, Student_Reports.Report_Message, parent_student.parent_id, parent_student.student_id, student.first_name, student.surname, student.student_id, parent.parent_id, parent.first_name, parent.surname FROM Student_Reports, parent_student, student, parent WHERE Student_Reports.Report_ID = '$Report_ID' AND student.user_id = '$user_idp' AND parent.user_id = '$user_id' AND parent_student.parent_id = '$user_id' "; // execute query $result = mysqli_query($dbc,$query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysqli_num_rows($result)>0) { echo "<table border=1>\n<tr>" . "<th>Reportid</th>" . "<th>Overall_Grade</th>" . "<th>first_name</th>" . "<th>Surname</th>" ; // "<th>Message</th>". // "<th>Delete</th>". // "<th>View</th>". // "<th>Reply</th>". while ($row = @ mysqli_fetch_array($result)) { //while($row = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>".$row["Report_ID"]."</td>"; echo "<td>".$row["Overall_Grade"]."</td>"; echo "<td>".$row["first_name"]."</td>"; echo "<td>".$row["surname"]."</td>"; echo "<tr><th colspan='4'>Date Report Written:</th></tr>" ; echo "<tr><td colspan='4'>$Date</td>"; echo "<tr><th colspan='4'>Student Name</th></tr>" ; echo "<tr><td colspan='2'>$sfirst_name</td>"; echo "<td colspan='2'>$ssurname</tr></td>"; echo "<tr><th colspan='4'>Subject</th></tr>" ; echo "<tr><td colspan='4'>".$row["Subject"]."</td></tr>"; echo "<tr><th colspan='4'>Report_Message</th></tr>" ; echo "<tr><td colspan='4'>".$row["Report_Message"]."</td></tr>"; // echo "<td>".$row["username"]."</td>"; // echo "<td>".$row["MessageTo"]."</td>"; // echo "<td>".$row["Subject"]."</td>"; // echo "<td>".$row["Message"]."</td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message print "No Reports To View"; } ?> <p><form enctype="multipart/form-data" method="post" action="test2.php"> <input name="Subject" id="Subject" value="<?php echo $row['Subject']; ?>" /> <input name="Report_Message" id="Report_Message" value="<?php echo $row['Report_Message']; ?>" ></input><br /> <input name="Date" id="Date" value="<?php echo $Date; ?> "></input><br /> <input name="Overall_Grade" id="Overall_Grade" value="<?php echo $Overall_Grade; ?> "></input><br /> <input name="sfirst_name" id="sfirst_name" value="<?php echo $sfirst_name; ?> "></input><br /> <input name="ssurname" id="ssurname" value="<?php echo $ssurname; ?> "></input><br /> <input name="user_idp" id="user_idp" value="<?php echo $user_idp; ?> "></input><br /> <p> <label>View Report as PDF <input type="submit" name="submit" id="button" value="submit" /> </label></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/#findComment-1034239 Share on other sites More sharing options...
jcbones Posted April 2, 2010 Share Posted April 2, 2010 Few things. 1. You need a "type" for your input fields. type="submit", type="text", type="hidden", type="password", etc. 2. You need to pass your database values to a variable. After the last row in the database, the pointer increments to fail the while statement, allowing the script to continue. So, there is no longer a $row[$database_column] to pull from. 3. You are trying to access database information, even if the database returns 0 rows of data. Not a good idea, as you will consistently have inputs with empty value's. Quote Link to comment https://forums.phpfreaks.com/topic/196912-returned-data-from-mysql-database-into-a-form/#findComment-1035941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.