Jump to content


Photo

Update Code Now Has 'form_Id' Error


  • Please log in to reply
28 replies to this topic

#21 justlukeyou

justlukeyou

    Advanced Member

  • Members
  • PipPipPip
  • 966 posts

Posted 27 November 2012 - 09:47 AM

Or should it be this?

	 <form>
	    <input type="text" name="firstname" value="<?php if($_POST['firstname']) echo $_POST['firstname']; ?>"/>
</form>


#22 justlukeyou

justlukeyou

    Advanced Member

  • Members
  • PipPipPip
  • 966 posts

Posted 27 November 2012 - 09:49 AM

Nope that doesn't work.

#23 mrMarcus

mrMarcus

    I'm a beleafer.

  • Members
  • PipPipPip
  • 1,903 posts
  • LocationCanada

Posted 27 November 2012 - 09:56 AM

Your form is a mess. You're querying the database many times to simply get a name or whatever for each table row.

Query the database one time:

<?php
$query = "SELECT * FROM users WHERE id = " . intval($_SESSION['userID']) . " LIMIT 1";
if ($result = mysql_query($query)) {
    if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        ?>
        <div class="updateinputcell">
            <li class="li_1" >
                <div class="forminputleft">
                    About Your Company:  <?php echo $row['category']; ?>
                </div>
            <div class="forminputright">
                <textarea class="element_2" name="aboutcompany" class="element textarea medium" value="<?php echo (!empty($row['aboutcompany'])) ? $row['aboutcompany'] : ''; ?>"><textarea>
            </div> 
            </li>
        </div>

        <!-- CONTINUE WITH REST OF FORM -->

        <?php
    }
}

This simply pre-populates the form based on the user data from the db.  However, depending on whether an application has proper error-handling, and let's assume it does, you will want to check if any $_POST data exists which will trump the user table data.  Imagine editing numerous parts of a form only to have all your changes reset back to how it was when you started all because you accidentally put an integer in a string-only field.  In a case like that, you would want to check if $_POST data is available to retain the user's current form state.  However, that's another thread altogether, I'm sure.

Edited by mrMarcus, 27 November 2012 - 10:03 AM.


#24 MDCode

MDCode

    Advanced Member

  • Members
  • PipPipPip
  • 645 posts

Posted 27 November 2012 - 10:04 AM

I not something that stops it from being updated.


<?php
if(empty($postcode)) {
do not update;
}
?>


<?php
// You can keep adding if you want but this a very basic way
if(empty($one_variable) || empty($second_variable) || empty($keep_going)) {
echo "You left some blank";
} else {
// update the database
}
?>


#25 justlukeyou

justlukeyou

    Advanced Member

  • Members
  • PipPipPip
  • 966 posts

Posted 27 November 2012 - 10:10 AM

Your right, I should tidy that up.

When I try this it echoes the HTML following this part

$row['aboutcompany'] : ''; ?>">

So this whats being displayed

<textarea>
</div>
</li>
</div>





<!-- CONTINUE TO REST OF FORM -->




"><textarea>
</div>
</li>
</div>

</div>
</div>
</div>


<div class="registerinfobenefitsright">
</div>
</div>
<div class="aside">

</div>









</body>
</html>

#26 justlukeyou

justlukeyou

    Advanced Member

  • Members
  • PipPipPip
  • 966 posts

Posted 28 November 2012 - 04:55 AM

Hi,

Huge thanks for you help with this mrMarcus. I just change the text area to input and it worked fine.

Many thanks.

  <input class="element_2"


#27 mrMarcus

mrMarcus

    I'm a beleafer.

  • Members
  • PipPipPip
  • 1,903 posts
  • LocationCanada

Posted 28 November 2012 - 09:07 AM

Hi,

Huge thanks for you help with this mrMarcus. I just change the text area to input and it worked fine.

Many thanks.

<input class="element_2"


Shoot, my bad. Didn't even realize I posted a <textarea> in my example.

For <textarea>, it works a little different. So, you can keep your textarea, just use the following code:

<textarea class="element_2" name="aboutcompany" class="element textarea medium"><?php echo (!empty($row['aboutcompany'])) ? $row['aboutcompany'] : ''; ?><textarea>


#28 justlukeyou

justlukeyou

    Advanced Member

  • Members
  • PipPipPip
  • 966 posts

Posted 28 November 2012 - 04:01 PM

Hi,

Whats the difference betweent the two?

This code has helped massively. Ive also sorted out my header. I was previously echoing the first name the user submitted. So if someone did change their name the site would continiously show there old name.

Is it possible to do this with drop down menus. I have 2 drop down menus that I need to change to this method.

#29 mrMarcus

mrMarcus

    I'm a beleafer.

  • Members
  • PipPipPip
  • 1,903 posts
  • LocationCanada

Posted 28 November 2012 - 04:04 PM

Hi,

Whats the difference betweent the two?

This code has helped massively. Ive also sorted out my header. I was previously echoing the first name the user submitted. So if someone did change their name the site would continiously show there old name.

Is it possible to do this with drop down menus. I have 2 drop down menus that I need to change to this method.


Are you asking the difference between a <textarea> box and an <input> field? If so, see here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com