0

Good Day Everone

Just wanna ask for a suggestion if it is possible to Save data in DB and at the same time Print the form when the submit button is clicked? and if possible how can i obtain it?

Here's what ive tried

form.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<style type="text/css">
<!--
.style1 {
    font-size: 18px;
    font-weight: bold;
}
-->
</style>
</head>

<body>
<span class="style1">Sample RA</span><br><br>
<form action="save.php" method="post">
I <input name="Name" type="text"  placeholder="State your Name"/> certified that the info on this form is true and legitimate<br><br><br>
<input name="" type="submit"  value="Print/Save"/>


</form>
</body>
</html>

and this part is the Save file

<?php

    require_once('config.php');



    $errmsg_arr = array();


    $errflag = false;


    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }


    $db = mysql_select_db(DB_NAME);
    if(!$db) {
        die("Unable to select database");
    }


    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }


    //Sanitize the POST values

    $name = clean($_POST['Name']);


    $sql="INSERT INTO data(name) VALUES('$name')";

if (!mysql_query($sql,$link))
  {
  //ERROR MESSAGE
 echo "<script type='text/javascript'>alert('There was an error processing your request, Please Try Again'); window.location.href = 'index.php';</script>";
  }

  //SUCCESS WILL REDIRECT TO PRINT.php ///////////////////////////
header("location:print.php");




mysql_close($conn)

?>

and the print file

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<style type="text/css">
<!--
.style1 {
    font-size: 18px;
    font-weight: bold;
}
-->
</style>
</head>

<body onload="window.print()">

<span class="style1">Sample RA</span><br><br>
<?php 
$name = $_POST['Name'];

?>

I <?php echo"$name"; ?> certified that the info on this form is true and legitimate



</body>
</html>

but its not capturing the name in the print part it will just show *Sample RA

I certified that the info on this form is true and legitimate *

is there anyway to achieve this in a simpler manner?

Thanks

Edited by ehpratah: edit

4
Contributors
6
Replies
52
Views
4 Years
Discussion Span
Last Post by happygeek
1

okay i think that's becuz the $_POST['Name'] is not set in print.php.
actually u are redirecting to the page print.php and not submitting the input values ... In other words u may use the post in the save.php cuz the form action is pointing to save.php but not in print.php.
To fix this u can use the $_GET['name'] in print.php. Like this:

save.php
header('location:print.php?name='.$_POST['name']);

and in the print.php use:
I <?php echo $_GET['name'] ?> certified ....

Edited by cmps

0

Hey thanks for the help..getting it now. although my problem is already answered just wondering am i doing it correctly or theres is an alternative solution for this?

0

There are lot of solution for doing anything, one can use any solution as long as it's correct and effecient. So your code is fine ...

-3

Excellent and exceptional blog found and read from your web address on the net. Retain write your blog on the net like this and make enjoyable through your blog on the net. Thanks you very much for posting the blog on the net.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.