Value from MySQL inserted into hidden form input.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Value from MySQL inserted into hidden form input.

Post by synical21 »

Hello PHP Gurus,
Im struggleing to insert the value from the database into this hidden input. The query is at the top of the page which is select * from data and the column i need is title. I have tried 3 ways:

(line 59)
<input name="title" type="hidden" value="<? echo $row['title'] ;?>">
<input name="title" type="hidden" value="<? echo $_GET['title'] ;?>">
<input name="title" type="hidden" value="<? echo $_POST['title'] ;?>">

None work. As you will see in the attached code i haev got the title to appear once from the database so why cant it work again but this time be inside a hidden field.

Its been a whole day now and i think im about to lose my hair, any help is apreciated.

Code: Select all

<?php
 
# connect to the database
mysql_connect('l222222');
mysql_select_db('22222');
 
 
session_start(); 
$my_id = trim (' ' . @$_GET['ID']) ;
if ('' < $my_id) { $my_id= (int) $my_id;
                           if ( 0 == $my_id) { $my_id= '';
                                                       } else $my_id = "$my_id"; 
                        }
if ('' == $my_id) {
 
} else {
 
$result = mysql_query("SELECT * FROM `data` WHERE job_id = '$my_id'")   // This will return one result
or die(mysql_error());  
 
 
}
while($row = mysql_fetch_array($result))
{
        echo "<tr>";
   echo "<td><h1>" . $row['title'] . "</h1></td>";
   echo "<p>";
 echo "</tr>";
 
  
  }
?>
 
<form action="proofsend.php" method="post"> 
    <p style="line-height: 150%">
      <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Tahoma; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">
       <table border="0" cellpadding="7" cellspacing="1" width="460" id="AutoNumber55"  bgcolor="#CFCFB3">
        <tr>
          <td bgcolor="#CCFFCC" valign="top">
      If users accept a job but do not complete or submit fake proof to the employer <br/>
      there account will be
      <font color="#DD0000">
        
        <span class="Apple-style-span" style="border-collapse: separate; font-family: Tahoma; font-size: 12px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">
          deleted</span></font><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Tahoma; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">.</span>
    
    </td>
    </tr>
    </table>
    <p style="line-height: 150%"><b>Have you finished this job?</b></p>
    <p style="line-height: 150%">Enter the proof in the box below and 
      press submit.<br>
      
      You must complete the job to the employers standards.</p>
    <p style="line-height: 150%"><b>Enter proof<br>
      <textarea rows="10" name="proof" cols="60">Write here</textarea></b></p>
    <p>
    
    <input name="title" type="hidden" value="<? echo $row['title'] ;?>">      <------ here ----------<
    
    <input name="job_id" type="hidden" value="<? echo $my_id ;?>">
 
    <input name="user_id" type="hidden" value="<? echo $_SESSION['user_id'] ;?>">
        
      
      <input type="submit" value="Submit proof" name="submit"></p>
    </form>
    <?
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Value from MySQL inserted into hidden form input.

Post by AlanG »

Are php short tags enabled in the php.ini file? You seem to be using <? echo $row['title'] ;?> as opposed to <?php echo $row['title'] ;?>
You shouldn't use php short tags as they conflict with xml tags.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Value from MySQL inserted into hidden form input.

Post by synical21 »

Good shout ill try that, For some extra information these two hidden fields work:

Code: Select all

 <input name="job_id" type="hidden" value="<? echo $my_id ;?>">
 
    <input name="user_id" type="hidden" value="<? echo $_SESSION['user_id'] ;?>">
EDIT:: changing the tag to <?php didnt work
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Value from MySQL inserted into hidden form input.

Post by AlanG »

Short tags are enabled then.

Try changing the while loop to this:

Code: Select all

<?php
if(mysql_num_rows($result) == 1) { // Checks only 1 row was returned
    $row = mysql_fetch_array($result);
    echo "<tr>";
    echo "<td><h1>" . $row['title'] . "</h1></td>";
    echo "<p>";
    echo "</tr>";
}
?>
Edit:

Also, include it in the else condition (along with the mysql_query function)

Just cleaned up your code a little, incase your interested.

Code: Select all

<?php
//connect to the database
mysql_connect('l222222');
mysql_select_db('22222');
 
session_start();
$my_id = (isset($_GET['ID']) && !empty($_GET['ID']) && is_numeric($_GET['ID'])) ? trim($_GET['ID']) : 0; // checks that the id is set, not empty and is a numeric string, otherwise it's considered zero
 
    if (!empty($my_id)) {
        $result = mysql_query("SELECT * FROM `data` WHERE job_id = '$my_id'")   // This will return one result
        or die(mysql_error());
 
        if(mysql_num_rows($result) == 1) { // Checks only 1 row was returned
            $row = mysql_fetch_array($result);
            echo "<tr>";
            echo "<td><h1>" . $row['title'] . "</h1></td>";
            echo "<p>";
            echo "</tr>";
        }
}
 
?>
Last edited by AlanG on Thu Aug 27, 2009 7:09 pm, edited 1 time in total.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Value from MySQL inserted into hidden form input.

Post by synical21 »

You did it Alan!!!!! Thank you wooow you actually did it. (Sorry for the over reaction but it was impossible to me)
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Value from MySQL inserted into hidden form input.

Post by AlanG »

No worries. :) :drunk:

I cleaned up your code a little in my previous post. :) and remember... no short tags! :)
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Value from MySQL inserted into hidden form input.

Post by synical21 »

Ignore this post :p Thanks alan
Post Reply