Matt Ridge Posted November 16, 2011 Share Posted November 16, 2011 When creating a PHP document we use echo ''; to wrap HTML into PHP, so why does it seem to me that people always say to create a form using PHP you must break it up by using HTML to show the form itself? Is there a way to create the form, and do all that is required using PHP and wrapping PHP around HTML to make it work? I can't imagine its impossible. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/ Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 Regardless of what you do, html markup has to be sent to the browser. Whether you echo it from within php, or exit php to send it makes no difference in how the browser handles and interprets it. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288698 Share on other sites More sharing options...
QuickOldCar Posted November 16, 2011 Share Posted November 16, 2011 Agree with Pikachu2000. You can display it however you would like, but even echoed it would still be html code...just wrapped in quotes and within php.. Can use html with breaking in and out of php easier. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288700 Share on other sites More sharing options...
maccy93 Posted November 16, 2011 Share Posted November 16, 2011 or heredocs even easier still echo <<<_END heeeelllllooooo world! _END; Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288709 Share on other sites More sharing options...
Matt Ridge Posted November 16, 2011 Author Share Posted November 16, 2011 Regardless of what you do, html markup has to be sent to the browser. Whether you echo it from within php, or exit php to send it makes no difference in how the browser handles and interprets it. So basically you can take a code that normally was exited out of PHP to do as normal HTML echo it in PHP and get the same results? Of course cleaning it up to use PHP more efficiently is always a bonus, but the generic question still stands. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288715 Share on other sites More sharing options...
kicken Posted November 16, 2011 Share Posted November 16, 2011 You can do the whole thing in one file. I prefer to actually. You do not have to wrap all the html in PHP echo statements though. If you have big chunks of html the easiest thing to do is just exit php mode and put the html. Re-enter php mode as necessary. Put all your main processing code at the top of the page: <?php if (count($_POST) > 0){ //process the form here } ?> <html> <head></head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p>Name: <input type="text" name="name" value="<?php echo isset($_POST['name'])?$_POST['name']:''; ?>"></p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288721 Share on other sites More sharing options...
Matt Ridge Posted November 16, 2011 Author Share Posted November 16, 2011 You can do the whole thing in one file. I prefer to actually. You do not have to wrap all the html in PHP echo statements though. If you have big chunks of html the easiest thing to do is just exit php mode and put the html. Re-enter php mode as necessary. Put all your main processing code at the top of the page: <?php if (count($_POST) > 0){ //process the form here } ?> <html> <head></head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p>Name: <input type="text" name="name" value="<?php echo isset($_POST['name'])?$_POST['name']:''; ?>"></p> </form> </body> </html> This is a small form, two lines of input. The problem I see with your post is that there is no way to submit... Here is why I am asking: I have a php form I've worked on for a while, it is technically working a form in a form, so I am running into an issue where even if I use the HTML break like normal, I'm not sure how to make this work... Basically I have the majority of the form pushing data out, where in one section you are entering data into the same database. Do you set up the interaction between input and output to be the same? The reason I'm asking is because I want to do this entirely in PHP instead of going in and out of PHP if that makes sense... and I am finding that where most books that I've been reading show me how to do one or the other, it never shows how to do both at the same time...almost 100% of them say to go out of php to html and then back again. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288731 Share on other sites More sharing options...
litebearer Posted November 16, 2011 Share Posted November 16, 2011 Matt... Perhaps if you presented us with what you have attempted this far, and defined where in your coding you are having difficulties, we (the collective) could better assist. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288736 Share on other sites More sharing options...
Matt Ridge Posted November 16, 2011 Author Share Posted November 16, 2011 Matt... Perhaps if you presented us with what you have attempted this far, and defined where in your coding you are having difficulties, we (the collective) could better assist. I've tried, no dice. Here is what I have, and what I need. This is a form that takes data sent to it, an ID to be specific, and says show me information from ID 1" and it works... What I need to do is simple I think to most people here but above my skill set right now. Once the ID was received, push the data to the form from the database. There are two fields that are empty, on purpose, $ncmrsr and $ncmrsc. What I have this doing is if they are empty show a field which will allow a person to submit a comment. Once the data has been submitted the page reloads and shows the data that was just entered. If they are full initially show the comments. The reason I was asking the original question was because someone said it can't be done in PHP, and I can't believe that to be true. This is with the form: http://kaboomlabs.com/PDI/1.php?id=2 This is with the data already entered: http://kaboomlabs.com/PDI/1.php?id=1 Here is the code, I've cut a lot out, to make it simple to understand, but you should get the gyst of it: Thanks for the help... it's appreciated. BTW I do know about the tr and td inside the form, I will get rid of it later, but for now I need to work on the rest... <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all">'; echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id="ab"><tr><td><span class="b">Added By: </span></td><td>' . $row['Added_By'] . '</td></tr></div>';} if (!empty($row['Added_By_Date'])) { echo '<div id="abd"><tr><td><span class="b">On: </span></td><td>' . $row['Added_By_Date'] . '</td></tr></div>';} echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part'])) { echo '<div id="np"><tr><td><span class="b">Nexx Part: </span></td><td>' . $row['Nexx_Part'] . '</td></tr></div>';} if (!empty($row['Nexx_Rev'])) { echo '<div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td>' . $row['Nexx_Rev'] . '</td></tr></div>';} if (!empty($row['Nexx_Part_Description'])) { echo '<div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td>' . $row['Nexx_Part_Description'] . '</td></tr></div>';} if (!empty($row['NCMR_Qty'])) { echo '<div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td>' . $row['NCMR_Qty'] . '</td></tr></div>';} echo '<div id ="JSI">'; if (!empty($row['JO'])) { echo '<div id="JO"><tr><td><span class="b">JO: </span></td><td><br />' . $row['JO'] . '</td></tr></div>';} if (!empty($row['SN'])) { echo '<div id="SN"><tr><td><span class="b">SN: </span></td><td><br />' . $row['SN'] . '</td></tr></div>';} if (!empty($row['INV'])) { echo '<div id="INV"><tr><td><span class="b">INV: </span></td><td><br />' . $row['INV'] . '</td></tr></div>';} echo '</div>'; echo '</div>'; echo '<div id="box4">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // code to add comment would go here. echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; } else { // echo the two fields if (!empty($row['ncmrsr'])) { echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response: </span></td><td>' . $row['ncmrsr'] . '</td></tr></div>';} if (!empty($row['ncmrsc'])) { echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment: </span></td><td>' . $row['ncmrsc'] . '</td></tr></div>';} echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288743 Share on other sites More sharing options...
kicken Posted November 16, 2011 Share Posted November 16, 2011 I don't really know what your asking. Your code seems ok. You have a lot of if's since seem to not want to show any field that is blank. Not much of any better way to do that though, just have to deal with it if you want that level of appearance control. You could just have the field be empty but still shown, which would remove a lot of the if's and clean up the code a bit. You can still get rid of the number of echo's by just going in and out of php mode, depends on which style you like best I guess when it comes down to it. Neither is really any better or worse than the other. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); if (!$row){ echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } else { $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); ?> <h3 id="NCMR2">Non-Conforming Materials Report (NCMR: <?php echo $row['NCMR_ID']?>)</h3> <form id="all"> <fieldset> <?php if (!empty($row['Added_By'])) { ?><div id="ab"><tr><td><span class="b">Added By: </span></td><td><?php echo $row['Added_By']?></td></tr></div> <?php } ?> <?php if (!empty($row['Added_By_Date'])) { ?><div id="abd"><tr><td><span class="b">On: </span></td><td><?php echo $row['Added_By_Date']?></td></tr></div> <?php } ?> <div id="box"> <div id="box1"> <?php if (!empty($row['Nexx_Part'])) { ?><div id="np"><tr><td><span class="b">Nexx Part: </span></td><td><?php echo $row['Nexx_Part'];?></td></tr></div><?php } ?> <?php if (!empty($row['Nexx_Rev'])) { ?><div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td><?php echo $row['Nexx_Rev'];?></td></tr></div><?php } ?> <?php if (!empty($row['Nexx_Part_Description'])) { ?><div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td><?php echo $row['Nexx_Part_Description'];?></td></tr></div><?php } ?> <?php if (!empty($row['NCMR_Qty'])) { ?><div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td><?php echo $row['NCMR_Qty'];?></td></tr></div><?php } ?> <div id ="JSI"> <?php if (!empty($row['JO'])) { ?><div id="JO"><tr><td><span class="b">JO: </span></td><td><br /><?php echo $row['JO'];?></td></tr></div><?php } ?> <?php if (!empty($row['SN'])) { ?><div id="SN"><tr><td><span class="b">SN: </span></td><td><br /><?php echo $row['SN'];?></td></tr></div><?php } ?> <?php if (!empty($row['INV'])) { ?><div id="INV"><tr><td><span class="b">INV: </span></td><td><br /><?php echo $row['INV'];?></td></tr></div><?php } ?> </div> </div> <div id="box4"> <?php if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { ?> <div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br /> <div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br /> <?php } else { ?> <?php if (!empty($row['ncmrsr'])) { ?><div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response: </span></td><td><?php echo $row['ncmrsr']; ?></td></tr></div><?php } ?> <?php if (!empty($row['ncmrsc'])) { ?><div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment: </span></td><td><?php echo $row['ncmrsc']; ?></td></tr></div><?php } ?> <?php } ?> </div> </div> </div> </fieldset> </form> <?php } //!$row ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288792 Share on other sites More sharing options...
Matt Ridge Posted November 16, 2011 Author Share Posted November 16, 2011 I don't really know what your asking. Your code seems ok. You have a lot of if's since seem to not want to show any field that is blank. Not much of any better way to do that though, just have to deal with it if you want that level of appearance control. You could just have the field be empty but still shown, which would remove a lot of the if's and clean up the code a bit. You can still get rid of the number of echo's by just going in and out of php mode, depends on which style you like best I guess when it comes down to it. Neither is really any better or worse than the other. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); if (!$row){ echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } else { $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); ?> <h3 id="NCMR2">Non-Conforming Materials Report (NCMR: <?php echo $row['NCMR_ID']?>)</h3> <form id="all"> <fieldset> <?php if (!empty($row['Added_By'])) { ?><div id="ab"><tr><td><span class="b">Added By: </span></td><td><?php echo $row['Added_By']?></td></tr></div> <?php } ?> <?php if (!empty($row['Added_By_Date'])) { ?><div id="abd"><tr><td><span class="b">On: </span></td><td><?php echo $row['Added_By_Date']?></td></tr></div> <?php } ?> <div id="box"> <div id="box1"> <?php if (!empty($row['Nexx_Part'])) { ?><div id="np"><tr><td><span class="b">Nexx Part: </span></td><td><?php echo $row['Nexx_Part'];?></td></tr></div><?php } ?> <?php if (!empty($row['Nexx_Rev'])) { ?><div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td><?php echo $row['Nexx_Rev'];?></td></tr></div><?php } ?> <?php if (!empty($row['Nexx_Part_Description'])) { ?><div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td><?php echo $row['Nexx_Part_Description'];?></td></tr></div><?php } ?> <?php if (!empty($row['NCMR_Qty'])) { ?><div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td><?php echo $row['NCMR_Qty'];?></td></tr></div><?php } ?> <div id ="JSI"> <?php if (!empty($row['JO'])) { ?><div id="JO"><tr><td><span class="b">JO: </span></td><td><br /><?php echo $row['JO'];?></td></tr></div><?php } ?> <?php if (!empty($row['SN'])) { ?><div id="SN"><tr><td><span class="b">SN: </span></td><td><br /><?php echo $row['SN'];?></td></tr></div><?php } ?> <?php if (!empty($row['INV'])) { ?><div id="INV"><tr><td><span class="b">INV: </span></td><td><br /><?php echo $row['INV'];?></td></tr></div><?php } ?> </div> </div> <div id="box4"> <?php if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { ?> <div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br /> <div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br /> <?php } else { ?> <?php if (!empty($row['ncmrsr'])) { ?><div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response: </span></td><td><?php echo $row['ncmrsr']; ?></td></tr></div><?php } ?> <?php if (!empty($row['ncmrsc'])) { ?><div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment: </span></td><td><?php echo $row['ncmrsc']; ?></td></tr></div><?php } ?> <?php } ?> </div> </div> </div> </fieldset> </form> <?php } //!$row ?> </body> </html> The ifs are there for a reason, but I agree about cleaning it up a bit. What I want to do is to be able to submit the form if the form shows up... and then reload the page after. Then in its place show the inputed data... As it stands now I can't send the data to the database if I input it into the two fields in #2... I hope that is a little bit clearer.... Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288812 Share on other sites More sharing options...
Matt Ridge Posted November 17, 2011 Author Share Posted November 17, 2011 Ok, here is the deal with the entire script. This is where the form above is getting it's data: http://kaboomlabs.com/PDI/list.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PDI NCMR Admin Panel</title> <link rel="stylesheet" type="text/css" href="CSS/admin.css" /> </head> <body> </body> </html> <?php $NCMR_ID = $_POST['NCMR_ID']; $Nexx_Part_Description = $_POST['Nexx_Part_Description']; $Added_By_Date = $_POST['Added_By_Date']; // Connect to the database require_once('connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL Server'); echo '<h2 id="LNCMR">Latest NCMRs </h2>'; // Retrieve the score data from MySQL $query = "SELECT * FROM ncmr"; $result = mysqli_query($dbc, $query) or die('Error quering database'); while ($row = mysqli_fetch_array($result)) { $NCMR_ID = $row['NCMR_ID']; $Nexx_Part_Description = $row['Nexx_Part_Description']; $Added_By_Date = $row['Added_By_Date']; $id = $row['id']; echo '<table>'; // Display the score data echo '<tr><td class="ncmrdata">'; echo '<strong id="listh2">NCMR ID:<a href="1.php?id=' . $row['id'] . '">' . $row['NCMR_ID'] . '</a></strong><br />'; echo '<strong id="listh2">Name:</strong>' . $row['Nexx_Part_Description'] . '<br />'; echo '<strong id="listh2">Date Entered:</strong>' . $row['Added_By_Date'] . '<br/ >'; echo '</table>'; } mysqli_close($dbc); ?> This is where the output goes: http://kaboomlabs.com/PDI/1.php?id=2 <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { // Grab the profile data from the POST $ncmrsr = mysqli_real_escape_string($dbc, trim($_POST['ncmrsr'])); $ncmrsc = mysqli_real_escape_string($dbc, trim($_POST['ncmrsc'])); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (!empty($ncmrsr) && !empty($ncmrsc)) { $query = "UPDATE ncmr SET ncmrsr = '$ncmrsr', ncmrsc = '$ncmrsc' WHERE id = '" . $_GET['id'] . "'"; mysqli_query($dbc, $query) or die ('Data not inserted.'); echo 'Customer added.'; } if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all">'; echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id="ab"><tr><td><span class="b">Added By: </span></td><td>' . $row['Added_By'] . '</td></tr></div>';} if (!empty($row['Added_By_Date'])) { echo '<div id="abd"><tr><td><span class="b">On: </span></td><td>' . $row['Added_By_Date'] . '</td></tr></div>';} echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part'])) { echo '<div id="np"><tr><td><span class="b">Nexx Part: </span></td><td>' . $row['Nexx_Part'] . '</td></tr></div>';} if (!empty($row['Nexx_Rev'])) { echo '<div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td>' . $row['Nexx_Rev'] . '</td></tr></div>';} if (!empty($row['Nexx_Part_Description'])) { echo '<div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td>' . $row['Nexx_Part_Description'] . '</td></tr></div>';} if (!empty($row['NCMR_Qty'])) { echo '<div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td>' . $row['NCMR_Qty'] . '</td></tr></div>';} echo '<div id ="JSI">'; if (!empty($row['JO'])) { echo '<div id="JO"><tr><td><span class="b">JO: </span></td><td><br />' . $row['JO'] . '</td></tr></div>';} if (!empty($row['SN'])) { echo '<div id="SN"><tr><td><span class="b">SN: </span></td><td><br />' . $row['SN'] . '</td></tr></div>';} if (!empty($row['INV'])) { echo '<div id="INV"><tr><td><span class="b">INV: </span></td><td><br />' . $row['INV'] . '</td></tr></div>';} echo '</div>'; echo '</div>'; echo '<div id="box4-1">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // code to add comment would go here. echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; echo '<input type="submit" name="submit" value="Submit" />'; } } else { // echo the two fields if (!empty($row['ncmrsr'])) { echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response: </span></td><td><br />' . $row['ncmrsr'] . '</td></tr></div>';} if (!empty($row['ncmrsc'])) { echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment: </span></td><td><br />' . $row['ncmrsc'] . '</td></tr></div>';} echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> The problem I am running into is that it is telling me that there is an error, please contact the admin. This is literary the last line in the script, I can't figure out what is wrong except that its not inputting the data into the server correctly. Can someone help? Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1288916 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 Ok, I figured out what I need to do: The problem is I don't know how to do it. After entering in the data and pressing submit, I need to have the data post, now I can do this, but I am running into an issue I think. To post data normally I need to have this at the beginning of the page is the posting query, and server requests, but with an ID check and validation already there I don't know how to make both work at the same time... does anyone have a clue? Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289157 Share on other sites More sharing options...
MadTechie Posted November 18, 2011 Share Posted November 18, 2011 You need to update your form attributes echo '<form id="all">'; Needs a method and Action Other than that you can handle it like any other form Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289163 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 You need to update your form attributes echo '<form id="all">'; Needs a method and Action Other than that you can handle it like any other form How do I make both actions work though? Both require access to the database, how do I make the php script differentiate between the two actions? In English, one asks for data from the database, and in the same form another posts data to the database... you see what I mean? How do I differentiate between the two actions and still keep the script workable? Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289166 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 Is a way to make this work to show a form in a form? Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289265 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 http://kaboomlabs.com/PDI/1.php?id=2 Ok, To make this work for posting I need this line in there. <form id="all" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Now if I have this in php, it should look like this: echo '<form id="all" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">'; I get an error though: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/pawz/public_html/kaboomlabs.com/PDI/1.php on line 33 Which is the line above. I don't know why it it showing an error... Here is the code: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">'; echo '<fieldset>'; if (!empty($row['Added_By']) && empty($row['Added_By_Date'])) { echo '<div id="ab"><tr><td><span class="b">Added By: </span></td><td>' . $row['Added_By'] . '</td></tr></div>'; echo '<div id="abd"><tr><td><span class="b">On: </span></td><td>' . $row['Added_By_Date'] . '</td></tr></div>'; } echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part']) && !empty($row['Nexx_Rev']) && !empty($row['Nexx_Part_Description']) && !empty($row['NCMR_Qty'])) { echo '<div id="np"><tr><td><span class="b">Nexx Part: </span></td><td>' . $row['Nexx_Part'] . '</td></tr></div>'; echo '<div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td>' . $row['Nexx_Rev'] . '</td></tr></div>'; echo '<div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td>' . $row['Nexx_Part_Description'] . '</td></tr></div>'; echo '<div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td>' . $row['NCMR_Qty'] . '</td></tr></div>'; } echo '<div id ="JSI">'; if (!empty($row['JO']) && !empty($row['SN']) && !empty($row['INV'])) { echo '<div id="JO"><tr><td><span class="b">JO: </span></td><td><br />' . $row['JO'] . '</td></tr></div>'; echo '<div id="SN"><tr><td><span class="b">SN: </span></td><td><br />' . $row['SN'] . '</td></tr></div>'; echo '<div id="INV"><tr><td><span class="b">INV: </span></td><td><br />' . $row['INV'] . '</td></tr></div>'; } echo '</div>'; echo '</div>'; echo '<div id="box4">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // code to add comment would go here. echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment:<br /></span></td><textarea name="ncmrsr" rows="6" cols="85" ></textarea></tr></div><br />'; } else { // echo the two fields if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo '<div id="ncmrsr"><tr><td><span class="b">NCMR Supplier Response: </span></td><td>' . $row['ncmrsr'] . '</td></tr></div>'; echo '<div id="ncmrsc"><tr><td><span class="b">NCMR Supplier Comment: </span></td><td>' . $row['ncmrsc'] . '</td></tr></div>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289275 Share on other sites More sharing options...
trq Posted November 18, 2011 Share Posted November 18, 2011 If your already within php you don't need more php tags. echo '<form id="all" method="post" action="{$_SERVER[php_SELF]}">'; Note that: echo '<form id="all" method="post">'; Does exactly the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289277 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 If your already within php you don't need more php tags. echo '<form id="all" method="post" action="{$_SERVER[php_SELF]}">'; Note that: echo '<form id="all" method="post">'; Does exactly the same thing. Thanks a lot. That makes my life a lot easier. This is one of the reasons I hate learning on my own, simple things like this would of been taught in a classroom. Could you answer my other question though? I've been reading books that show code like this to make data input into a database. <?php require_once('connectvars.php'); if (isset($_POST['submit'])) { $ncmrsr = $_POST['ncmrsr']; $ncmrsc = $_POST['ncmrsc']; if (!empty($ncmrsr) && !empty($ncmrsc)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); or die('Error connecting to MySQL server.'); $query = "INSERT INTO ncmr (ncmrsr, ncmrsc) VALUES ('$ncmrsr', '$ncmrsc')"; mysqli_query($dbc, $query) or die ('Data not inserted.'); echo 'Customer added.'; mysqli_close($dbc); } } ?> But I already have this code there in its place. <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { } ?> How do I merge both to work with this script? Thanks in advance if you can figure it out.... I've been stuck on this for over a week and I am running into a deadline. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all" method="post">'; echo '<fieldset>'; if (!empty($row['Added_By']) && empty($row['Added_By_Date'])) { echo '<div id="ab"><span class="b">Added By: </span>' . $row['Added_By'] . '</div>'; echo '<div id="abd"><span class="b">On: </span>' . $row['Added_By_Date'] . '</div>'; } echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part']) && !empty($row['Nexx_Rev']) && !empty($row['Nexx_Part_Description']) && !empty($row['NCMR_Qty'])) { echo '<div id="np"><span class="b">Nexx Part: </span>' . $row['Nexx_Part'] . '</div>'; echo '<div id="nr"><span class="b">Nexx Rev: </span>' . $row['Nexx_Rev'] . '</div>'; echo '<div id="npd"><span class="b">Nexx Part Description: </span>' . $row['Nexx_Part_Description'] . '</div>'; echo '<div id="ncqt"><span class="b">NCMR Qty: </span>' . $row['NCMR_Qty'] . '</div>'; } echo '<div id ="JSI">'; if (!empty($row['JO']) && !empty($row['SN']) && !empty($row['INV'])) { echo '<div id="JO"><span class="b">JO: </span><br />' . $row['JO'] . '</div>'; echo '<div id="SN"><span class="b">SN: </span><br />' . $row['SN'] . '</div>'; echo '<div id="INV"><span class="b">INV: </span><br />' . $row['INV'] . '</div>'; } echo '</div>'; echo '</div>'; echo '<div id="box4-1">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // add comment. echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; } else { // echo the two fields. if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response: </span>' . $row['ncmrsr'] . '</div>'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment: </span>' . $row['ncmrsc'] . '</div>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289282 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 Ok, now I'm just colored confused....I'm not getting an error at all. The problem is the form isn't showing up at all either. Can someone help me here? I'd rather see an error than nothing... at least I'd have an idea of where to start. Here is my updated code and site: http://kaboomlabs.com/PDI/1-1.php?id=2 <?php require_once('connectvars.php'); ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { // Grab the profile data from the POST $ncmrsc = mysqli_real_escape_string($dbc, trim($_POST['ncmrsc'])); $ncmrsr = mysqli_real_escape_string($dbc, trim($_POST['ncmrsr'])); $output_form= true;} // Update the form in the database if (!empty($ncmrsr) && !empty($ncmrsc)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); mysqli_query($dbc, $query); // Confirm success with the user echo 'Customer added.'; mysqli_close($dbc); exit(); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all" method="post">'; echo '<fieldset>'; if (!empty($row['Added_By']) && empty($row['Added_By_Date'])) { echo '<div id="ab"><span class="b">Added By: </span>' . $row['Added_By'] . '</div>'; echo '<div id="abd"><span class="b">On: </span>' . $row['Added_By_Date'] . '</div>'; } echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part']) && !empty($row['Nexx_Rev']) && !empty($row['Nexx_Part_Description']) && !empty($row['NCMR_Qty'])) { echo '<div id="np"><span class="b">Nexx Part: </span>' . $row['Nexx_Part'] . '</div>'; echo '<div id="nr"><span class="b">Nexx Rev: </span>' . $row['Nexx_Rev'] . '</div>'; echo '<div id="npd"><span class="b">Nexx Part Description: </span>' . $row['Nexx_Part_Description'] . '</div>'; echo '<div id="ncqt"><span class="b">NCMR Qty: </span>' . $row['NCMR_Qty'] . '</div>'; } echo '<div id ="JSI">'; if (!empty($row['JO']) && !empty($row['SN']) && !empty($row['INV'])) { echo '<div id="JO"><span class="b">JO: </span><br />' . $row['JO'] . '</div>'; echo '<div id="SN"><span class="b">SN: </span><br />' . $row['SN'] . '</div>'; echo '<div id="INV"><span class="b">INV: </span><br />' . $row['INV'] . '</div>'; } echo '</div>'; echo '</div>'; echo '<div id="box4-1">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // add comment. echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="button"><input type="submit" name="submit" value="Submit" /></div>'; } else { // echo the two fields. if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response: </span>' . $row['ncmrsr'] . '</div>'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment: </span>' . $row['ncmrsc'] . '</div>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289381 Share on other sites More sharing options...
Matt Ridge Posted November 18, 2011 Author Share Posted November 18, 2011 Sorry, forgot a line... <?php require_once('connectvars.php'); ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { // Grab the profile data from the POST $ncmrsc = mysqli_real_escape_string($dbc, trim($_POST['ncmrsc'])); $ncmrsr = mysqli_real_escape_string($dbc, trim($_POST['ncmrsr'])); } // Update the form in the database if (!empty($ncmrsr) && !empty($ncmrsc)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "INSERT INTO ncmr (ncmrsr, ncmrsc) VALUES ('$ncmrsr', '$ncmrsc')"; mysqli_query($dbc, $query); // Confirm success with the user echo 'Customer added.'; // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all" method="post">'; echo '<fieldset>'; if (!empty($row['Added_By']) && empty($row['Added_By_Date'])) { echo '<div id="ab"><span class="b">Added By: </span>' . $row['Added_By'] . '</div>'; echo '<div id="abd"><span class="b">On: </span>' . $row['Added_By_Date'] . '</div>'; } echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part']) && !empty($row['Nexx_Rev']) && !empty($row['Nexx_Part_Description']) && !empty($row['NCMR_Qty'])) { echo '<div id="np"><span class="b">Nexx Part: </span>' . $row['Nexx_Part'] . '</div>'; echo '<div id="nr"><span class="b">Nexx Rev: </span>' . $row['Nexx_Rev'] . '</div>'; echo '<div id="npd"><span class="b">Nexx Part Description: </span>' . $row['Nexx_Part_Description'] . '</div>'; echo '<div id="ncqt"><span class="b">NCMR Qty: </span>' . $row['NCMR_Qty'] . '</div>'; } echo '<div id ="JSI">'; if (!empty($row['JO']) && !empty($row['SN']) && !empty($row['INV'])) { echo '<div id="JO"><span class="b">JO: </span><br />' . $row['JO'] . '</div>'; echo '<div id="SN"><span class="b">SN: </span><br />' . $row['SN'] . '</div>'; echo '<div id="INV"><span class="b">INV: </span><br />' . $row['INV'] . '</div>'; } echo '</div>'; echo '</div>'; echo '<div id="box4-1">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // add comment. echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="button"><input type="submit" name="submit" value="Submit" /></div>'; } else { // echo the two fields. if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response: </span>' . $row['ncmrsr'] . '</div>'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment: </span>' . $row['ncmrsc'] . '</div>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289394 Share on other sites More sharing options...
Matt Ridge Posted November 21, 2011 Author Share Posted November 21, 2011 Solved it: http://kaboomlabs.com/PDI/1.php?id=2 <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="CSS/view.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all" method="post">'; echo '<fieldset>'; if (!empty($row['Added_By']) && empty($row['Added_By_Date'])) { echo '<div id="ab"><span class="b">Added By: </span>' . $row['Added_By'] . '</div>'; echo '<div id="abd"><span class="b">On: </span>' . $row['Added_By_Date'] . '</div>'; } echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part']) && !empty($row['Nexx_Rev']) && !empty($row['Nexx_Part_Description']) && !empty($row['NCMR_Qty'])) { echo '<div id="np"><span class="b">Nexx Part: </span>' . $row['Nexx_Part'] . '</div>'; echo '<div id="nr"><span class="b">Nexx Rev: </span>' . $row['Nexx_Rev'] . '</div>'; echo '<div id="npd"><span class="b">Nexx Part Description: </span>' . $row['Nexx_Part_Description'] . '</div>'; echo '<div id="ncqt"><span class="b">NCMR Qty: </span>' . $row['NCMR_Qty'] . '</div>'; } echo '<div id ="JSI">'; if (!empty($row['JO']) && !empty($row['SN']) && !empty($row['INV'])) { echo '<div id="JO"><span class="b">JO: </span><br />' . $row['JO'] . '</div>'; echo '<div id="SN"><span class="b">SN: </span><br />' . $row['SN'] . '</div>'; echo '<div id="INV"><span class="b">INV: </span><br />' . $row['INV'] . '</div>'; } echo '</div>'; echo '</div>'; echo '<div id="box4-1">'; // We know both $ncmrsr AND $ncmrsc are blank $row['ncmrsr'] = trim($row['ncmrsr']); $row['ncmrsc'] = trim($row['ncmrsc']); if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) { // add comment. echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />'; echo '<div id="button"><input type="submit" name="submit" value="Submit" /></div>'; } else { // echo the two fields. if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response: </span>' . $row['ncmrsr'] . '</div>'; echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment: </span>' . $row['ncmrsc'] . '</div>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251258-is-it-possible-to-create-a-form-using-only-php/#findComment-1289974 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.