Hidden FIelds

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Hidden FIelds

Post by michaelk46 »

I have a PHP script that generates a HTML table in a variable that is then displayed on a search results page and allows the user to select which search fields and records that are exported into a CSV file. When I hit the submit button from there, it loses the variables that generate the page and I want to redisplay them with a mesasge to say whether or not the page exported successfully.
I am thinking of using a hidden field to pass those variables back for redisplay. I am just a little unsure how to use them.

If the name of the variable I am trying to pass back is $pagetable would this work when the page is submitted?

Code: Select all

 
<input type="hidden" name="Language" value="<?php $pagetable ?>">
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Hidden FIelds

Post by AbraCadaver »

Yes :-)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: Hidden FIelds

Post by michaelk46 »

It still doesn't show up... I tried to post variables I want to pass back to the same variable names using the name field, but no go.

Here's the form code I am working with:

Code: Select all

 
 
<form action="?" method="POST">
    <div> 
        <label for="searchid">Page ID Number:</label>
        <div></div>
        <input type="text" name="searchid" id="searchid" value="<?php 
                    if(!empty($_POST['searchid'])) echo htmlspecialchars($searchid, ENT_QUOTES, 'utf-8');?>" size="30"/>
    </div> 
    <p></p>
    <div> 
        <label for="pagename">Page Name:</label>
        <div></div>
        <input type="text" name="pagename" id="pagename" value="<?php 
                    if(!empty($_POST['pagename'])) echo htmlspecialchars($pagename, ENT_QUOTES, 'utf-8');?>" size="30"/>
    </div> 
    <p></p>
    <div>
        <input type="hidden" name="sql" value="<?php $sql ?>">
        <input type="hidden" name="pagetable" value="<?php $pagetable ?>">
        <input type="submit" name="search" value="Generate"/>
    </div>
<p></p>
 
<?php 
if(empty($sql)) include 'error.html.php';
else echo ($pagetable);
?>
</form>
and the part of the PHP code I am working with:

Code: Select all

 
$check = $_POST['check'];
$fields = $_POST['fields'];
$number = count($check);
$fnumber = count($fields);
$a=0;
$fp = fopen('C:/wamp/www/Files/csv/export/' . ' ' . date('Y-m-d') . '.csv', 'w'); //opens CSV file for record export
fputcsv($fp, $fields);
while ($a < $number) //generates search string for export into CSV file 
    {
        $sql1 ='SELECT ';
        $b=0;
        while ($b < $fnumber) //adds which fields are to be exported based on the search box selections that were checked  
           {
                if ($fields[$b] == 'id')
                    $sql1 .= 'pages.id';                    
                if ($fields[$b] == 'category')
                    $sql1 .= 'category.cat';
                if ($fields[$b] == 'manufacturer')
                    $sql1 .= 'manufacturer.manu';
                if ($fields[$b] == 'pagename')
                    $sql1 .= 'pages.pagename';                  
                if ($fields[$b] == 'retailprice')
                    $sql1 .= 'pages.retailprice';
                if ($fields[$b] == 'salesprice')
                    $sql1 .= 'pages.salesprice';
                if ($fields[$b] == 'upc')
                    $sql1 .= 'pages.upc';
                if ($fields[$b] == 'sku')
                    $sql1 .= 'pages.sku';
                if ($fields[$b] == 'caption')
                    $sql1 .= 'pages.caption';
                if ($fields[$b] == 'image')
                    $sql1 .= 'image.name';
                if ($b < $fnumber - 1)
                    $sql1 .= ', ';  
                else
                    $sql1 .= ' ';   
                ++$b;
             }
$sql1 .= 'FROM pages 
         INNER JOIN category ON pages.categoryid = category.id 
         INNER JOIN image ON pages.imageid = image.id
         INNER JOIN manufacturer ON pages.manufactureid = manufacturer.id WHERE pages.id = "'. $check[$a] .'"';
$result = mysqli_query($link, $sql1);
$row1 = mysqli_fetch_row($result);
fputcsv($fp, $row1); //adds selected info to CSV File
++$a; 
            }
fclose($fp);
$sql = $_POST['sql'];
$pagetable = $_POST['pagetable'];
include 'searchres.html.php';   //calls search results page
 
 
Can anyone give me a nudge in the direction I need to go on this?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Hidden FIelds

Post by pickle »

What is actually posted? Does the proper value show up in the source code before you re-submit? Does $pagetable have any double quotes in it?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: Hidden FIelds

Post by michaelk46 »

Nothing gets posted and nothing is in the variables I am trying to re submit.

The only error it shows is 'No Pages Found' and that comes up because $sql doesn't contain anything.

There are double quotes in $pagetable... But that's because they are inside single quotes.
Post Reply