|  | |  |
07-23-2008, 07:22 AM
|
#1 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| HTML Form with PHP preview, print, submit HTML Form with preview button.
Upon clicking preview a new page will load with the data displayed and 2 buttons (print and submit).
I am having trouble previewing the data. The print (java) and submit to DB (php to mysql) should be easy.
Suggestions on how to display the data from the form onto the new page? |
| |
07-23-2008, 07:30 AM
|
#2 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| it's difficult to give you a practical example without seeing your form, but here's a sample:
form_page.php HTML Code: <form method="POST" action="processing_page.php"> <input type="text" name="field1" /> <input type="submit" value="Process this page" /> </form> processing_page.php PHP Code:
Below is the data you submitted <hr />
Field1: <?php echo $_POST['field1']; ?>
__________________ Mike |
| |
07-23-2008, 09:19 AM
|
#3 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| thanks sde, that worked perfect. So now I am able to display the data, but having problems getting it from there to my db. This worked when I used it directly from the initial form, but not from the preview...
Here is my code for process.php: PHP Code: $field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3];
$dbh = new PDO('mysql:host=host;dbname=DB', 'DB', pass') or die(PDO::errorInfo());
$sth = $dbh->prepare("
INSERT INTO db (field1, field2, field3)
VALUES (?, ?, ?)
");
$sth->execute(array($field1, $field2, $field3)) or die(array_pop($sth->errorInfo()));
$dbh = null;
// confirmation redirect page
echo header("Location: thankyou.html");
?>
|
| |
07-23-2008, 09:31 AM
|
#4 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| is error reporting turned on so you see errors if they occur? are you seeing any errors or is it just directing to thankyou.html?
i know it's probably psuedo code, but you're missing a single quote for the array element of field3. $field3 = $_POST['field3'];
__________________ Mike |
| |
07-23-2008, 09:57 AM
|
#5 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| yeah its just fake code...
error reporting is telling me this:
Column 'field1' cannot be null
It isn't redirecting me either... (nothing in the db as well) |
| |
07-23-2008, 10:26 AM
|
#6 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| ok, so PDO must be replacing empty values with NULL, and your db is set so it won't be null.
are you sure you're sending values in field1 of the form? if field1 is allowed to be empty, then maybe something like this will do the trick: PHP Code: $field1 = $_POST['field1'] ? $_POST['field1'] : '';
it's just a guess, but maybe PDO is checking if $field1 is even set, .. if not, then it uses NULL, .. and my theory is if we set it to a blank string, it will enter a blank string.
but this should only be an issue if you are sending an empty field1 from the form in the first place. if you are populating field1 in the form and it is not submitting the data to the next page, then you have another issue.
__________________ Mike |
| |
07-23-2008, 10:51 AM
|
#7 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| yes it is the later issue, the field is not blank .
I'm assuming that its not properly getting the data |
| |
07-23-2008, 01:22 PM
|
#8 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| a good debugging tool is print_r.
at the top of your processing script, put this code. make sure there's no white space or anything printed to the screen above this since we're setting header information: PHP Code: <?php header('content-type: text/plain'); print_r($_POST); exit; that will dump the $_POST array so you can see exactly what your form is sending.
__________________ Mike |
| |
07-29-2008, 05:37 AM
|
#9 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| still not working... this is what is displayed:
Array
(
[Submit] => Submit
) |
| |
07-29-2008, 04:00 PM
|
#10 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| if you post your html form, i'll test it and post if it works for me or not.
__________________ Mike |
| |
07-30-2008, 07:44 AM
|
#11 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| here is my html form - if you 'd like to see my actual files, send me an email. thanks! HTML Code: <form name="form1" method="post" action="../preview.php" onSubmit=""> <p>Field1
<input name="field1" type="text" id="field1"> </p> <p>Field 2
<input name="field2" type="text" id="field2"> </p> <p>Field 3
<input name="field3" type="text" id="field3"> </p> <p> <input type="preview" name="Preview" value="preview"> </p> </form> |
| |
07-30-2008, 07:59 AM
|
#12 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| Your preview button should be type="submit"
Try running test.php (the script below) on your server and let me know if it works.
test.php PHP Code: <?php if ($_POST) { header('content-type: text/plain'); print_r($_POST); exit; } ?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="">
<p>Field1 <input name="field1" type="text" id="field1"> </p> <p>Field 2 <input name="field2" type="text" id="field2"> </p> <p>Field 3 <input name="field3" type="text" id="field3"> </p> <p> <input type="submit" name="Preview" value="preview"> </p> </form> Your output should look like this: Code: Array
(
[field1] => a
[field2] => b
[field3] => c
[Preview] => preview
)
__________________ Mike |
| |
07-30-2008, 08:09 AM
|
#13 (permalink)
| | Recruit
Join Date: Jul 2008
Posts: 7
| that worked fine |
| |
07-30-2008, 11:57 AM
|
#14 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,706
| so then based off that, can you get your other script to work?
__________________ Mike |
| | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -8. The time now is 05:37 AM. |
Copyright © 2000-2008, Milano Interactive Web Hosting provided by Portal 360 Web Hosting |  | |