Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 07-23-2008, 07:22 AM   #1 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
Smile 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?
btumpak is offline   Reply With Quote
Old 07-23-2008, 07:30 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 07-23-2008, 09:19 AM   #3 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
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");

?> 
btumpak is offline   Reply With Quote
Old 07-23-2008, 09:31 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 07-23-2008, 09:57 AM   #5 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
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)
btumpak is offline   Reply With Quote
Old 07-23-2008, 10:26 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 07-23-2008, 10:51 AM   #7 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
yes it is the later issue, the field is not blank .

I'm assuming that its not properly getting the data
btumpak is offline   Reply With Quote
Old 07-23-2008, 01:22 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 07-29-2008, 05:37 AM   #9 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
still not working... this is what is displayed:

Array
(
[Submit] => Submit
)
btumpak is offline   Reply With Quote
Old 07-29-2008, 04:00 PM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
if you post your html form, i'll test it and post if it works for me or not.
__________________
Mike
sde is offline   Reply With Quote
Old 07-30-2008, 07:44 AM   #11 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
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>
btumpak is offline   Reply With Quote
Old 07-30-2008, 07:59 AM   #12 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 07-30-2008, 08:09 AM   #13 (permalink)
btumpak
Recruit
 
Join Date: Jul 2008
Posts: 7
btumpak is on a distinguished road
that worked fine
btumpak is offline   Reply With Quote
Old 07-30-2008, 11:57 AM   #14 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
so then based off that, can you get your other script to work?
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Tags
html form preview submit

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML form preview then INSERT using PHP & MySQL SteveSoler PHP 16 09-21-2008 11:59 PM
Javascript Submit Form Options? Redline HTML, XML, Javascript, AJAX 5 05-19-2006 07:59 AM
How to insert HTML form data into mysql database ? plomon PHP 5 02-06-2005 08:23 AM


All times are GMT -8. The time now is 05:37 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting