How to insert hidden variables in MySQL

Discussion in 'PHP' started by Sarao, Jan 22, 2011.

  1. #1
    Hi,

    This following is the preview page of my page and I want to insert the data from this page to MySQL. How can that be done?

    I mean what would be the syntax to insert data into MySQL table ? I know no PHP and the below code is also made with the help of Internet so please be a bit more detailed.


    <style type="text/css">
    <!--
    .K {
    	font-size: 14px;
    	font-weight: normal;
    	font-family: Tahoma, Geneva, sans-serif;
    }
    .bar {
    	font:"Free 3 of 9 Extended";
    	font-size:14px;
    }
    
    .K2 {
    	font-size: 14px;
    	font-family: tahoma, Geneva, sans-serif;
    }
    .ff {
    	font-family: "Courier New", Courier, monospace;
    }
    -->
    </style>
    
    <table align="left">
      <tr>
        <td>
          <table width="97%" align="center" background="ss.jpg">
            <tr>
              <td>&nbsp;</td>
              <td class="ff">CONTENTS: <span class="K2"><?php echo " :" .$_POST["item"]. " "; ?></span></td>
            </tr>
          </table>
    
          <table>
            <tr>
              <td>&nbsp;</td>
            </tr>
          </table>
          <table width="800" align="center">
            <tr>
            <td class="K"><strong><U>SEND TO :</U></strong></td>
            <td class="K2">&nbsp;</td>
            <td class="K" align="right"><strong>FROM :</strong></td>
            <td class="K2">&nbsp;</td>
          </tr>
          <tr>
            <td width="12%" height="131" class="K">&nbsp;</td>
            <td align="justify" width="34%" class="K2"><table width="250">
                <tr>
                  <td class="K2" style="text-transform:uppercase"><strong> <?php
    
    
    echo nl2br(" " .$_POST["to"]. " ");
    ?></strong></td>
                  </tr>
              </table>         </td>
            <td width="14%" class="K" align="center"><p>::</p>
              <p>::</p>
              <p>::</p>
              <p>::</p></td>
            <td align="justify" width="40%" class="K2">&nbsp;</td>
          </tr>
          <tr>
            <td height="16" class="K">------------------</td>
            <td class="K2">--------------------------------------------------</td>
            <td class="K">---------------------</td>
            <td class="K">--------------------------------------------------------</td>
          </tr>
        </table>
          <table width="72%" align="center">
            <tr>
              <td align="center"><span style="font:Verdana, Geneva, sans-serif; font-size: 10px;"> :: Package Information :: </span></td>
            </tr>
          </table>
          <table  width="72%" align="center" >
            <tr align="left">
              <td width="11%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" height="20">*Content:</td>
              <td width="28%"  class="K2"><?php echo " " .$_POST["cat"]. " "; ?></td>
              <td width="8%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;">*Weight:</td>
              <td width="31%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K2"><?php echo " ".$_POST["wgt"]." "; ?> grams</td>
              <td width="9%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K"><p>*Price:</td>
              <td width="13%" style="font:Verdana, Geneva, sans-serif; font-size: 10px;" class="K2"><?php echo " ".$_POST["usd"]." "; ?> USD</td>
            </tr>
          </table>
        <hr color="#CCCCCC" />
        <table width="100%">
          <tr>
            <td width="57%" height="67"><p>Item ID:</p>
              <font face="IDAutomationHC39M" color="#000000" size="+2"> <?php echo " " .$_POST["contents"]. " "; ?> </font> </td>
            <td width="43%"><p>Tracking Code:</p>
              <p>&nbsp;</p></td>
          </tr>
        </table>    <?php
    echo "<input type='hidden' name='to' value='".$_POST["to"]."' />";
    echo "<input type='hidden' name='from' value='".$_POST["from"]."' />";
    echo "<input type='hidden' name='content' value='".$_POST["cat"]."' />";
    echo "<input type='hidden' name='wgt' value='".$_POST["wgt"]."' />";
    echo "<input type='hidden' name='usd' value='".$_POST["usd"]."' />";
    echo "<input type='hidden' name='usd' value='".$_POST["contents"]."' />";
    ?></td>
      </tr>
    </table>
    PHP:
     
    Sarao, Jan 22, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2

    It's not currently with exactly names with columns in your table and you have to edit it, but it should be like this. In this case, `to` and `from` should have these `` beacuse it can be part of MYSQL statement
     
    G3n3s!s, Jan 22, 2011 IP
  3. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you give me complete syntax like where to add the above line after connecting to DB?

    
    <?php
    
    // contact to database
    
    $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");
    
    mysql_select_db("sarao");
    
    
    PHP:
     
    Sarao, Jan 22, 2011 IP
  4. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #4
    first you have to put <form> start before input hidden fields and then place button. IF you click it, it does action written in <form>

    <form> looks like this

    <form method="post" action="doit.php">
    <input type="hidden" name="id" value="0" />
    <input type="submit" name="submit" value="submit" / >
    </form>

    in this case it calls doit.php which is proccessing form.
     
    G3n3s!s, Jan 23, 2011 IP
  5. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok I figured it out. Thank you. One thing I need again is to retrieve the data from the said tables and display them on the page with the way I want. I mean on the preview page, I displayed the information in the tables using the snipped

    
    <?php echo " :" .$_POST["item"]. " "; ?>
    
    PHP:
    CAn you please tell, how can I use the anippet like above to retrieve the data from MySQL so I can customize the look?
     
    Sarao, Jan 23, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    $rows = mysql_query("SELECT * FROM  tablename");
    
    while ($row = mysql_fetch_assoc($rows))
    {
     echo "to => ".$row['to'].", from => ".$row['from']." etc....";
    }
    PHP:
     
    G3n3s!s, Jan 23, 2011 IP
  7. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Its gives me an error

    <?php
    
    // contact to database
    
    $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");
    
    $rows = mysql_query("SELECT * FROM  info");
    
    while ($row = mysql_fetch_assoc($rows))
    
    {
    	echo "to => ".$row['to'].", "from => ".$row['from'].";
    }
    ?>
    
    PHP:
    
    Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\display.php on line 12
    
    Code (markup):
     
    Sarao, Jan 23, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #8
    this one
    <?php
    
    // contact to database
    
    $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");
    
    $rows = mysql_query("SELECT * FROM  info");
    
    while ($row = mysql_fetch_assoc($rows))
    {
        echo "to => ".$row['to'].", from => ".$row['from']."....";
    }
    ?>
    PHP:
     
    Last edited: Jan 23, 2011
    G3n3s!s, Jan 23, 2011 IP
  9. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php
    
    // contact to database
    
    $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");$rows = mysql_query("SELECT * FROM  info");while ($row = mysql_fetch_assoc($rows))
    {  
    echo "to => ".$row['to'].", from => ".$row['from'].";
    }
    
    ?>
    
    PHP:
    
    Parse error: parse error in C:\wamp\www\display.php on line 10
    
    Code (markup):
    :(
     
    Sarao, Jan 23, 2011 IP
  10. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    okay this

    <?php
    
    // contact to database
    
    $connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");
    
    $rows = mysql_query("SELECT * FROM  info");
    
    while ($row = mysql_fetch_assoc($rows))
    {
        echo "to => ".$row['to'].", from => ".$row['from']."....";
    }
    ?>
    PHP:
     
    G3n3s!s, Jan 23, 2011 IP
  11. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    ITs still giving me an error at last line.
     
    Sarao, Jan 23, 2011 IP
  12. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #12
    try to delete
    ?>
     
    G3n3s!s, Jan 23, 2011 IP
  13. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Then it says:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\display.php on line 7
    Code (markup):
     
    Sarao, Jan 23, 2011 IP
  14. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #14
    try this


    ;)
     
    G3n3s!s, Jan 23, 2011 IP
  15. Sarao

    Sarao Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Isnt it all the same code or am I missing anything?
     
    Sarao, Jan 23, 2011 IP
  16. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #16
    just try it.
    added
     
    G3n3s!s, Jan 23, 2011 IP