Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2009, 11:42 PM   PM User | #1
bucket
Regular Coder

 
Join Date: Sep 2008
Posts: 688
Thanks: 8
Thanked 17 Times in 16 Posts
bucket is infamous around these parts
If blank then dont Update

How do I do it so when this page gets run by itself it doesn't update the table, since if it does it will just make all the fields blank.

PHP Code:
<?php
require_once ('inc/config.php');
$firstname mysql_real_escape_string ($_POST['firstname']);
$lastname mysql_real_escape_string ($_POST['lastname']);
$middlenamemysql_real_escape_string ($_POST['middlename']);
$id 2;  
$sql mysql_query ("
   UPDATE `testing` SET 
      `FirstName` = '"
.$firstname."', 
      `LastName` = '"
.$lastname."',
      `MiddleName` = '"
.$middlename."' 
   WHERE `id` = '"
.$id."'
"
)
OR die (
mysql_error());
?>
Instead make it update the table only when the form updates it?
bucket is offline   Reply With Quote
Old 11-05-2009, 12:34 AM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Check to see if $_POST is set, or is an array, and additionally, a popular method is to check the SUBMIT button's $_POST index to see if it's set and even if the value of it equals the submit button value on the html form.
__________________
Fumigator is offline   Reply With Quote
Old 11-05-2009, 12:40 AM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yes, check a particular value. I always go for the submission button. You can also check for the request method, though that does not guarentee that the values will be set.
_POST is however always available regardless of if it is a posted form, and will always be an array, so you cannot check for isset on post, or if is_array, though you can check for !empty. I'm fairly certain about this, I remember a previous CLI run on phpinfo(INFO_VARIABLES); pulled up an empty array from post. Everything actually, except for sessions.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 11-05-2009, 04:30 PM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Quote:
_POST is however always available regardless of if it is a posted form, and will always be an array, so you cannot check for isset on post, or if is_array
Crap you're absolutely right...
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:39 PM.


Advertisement
Log in to turn off these ads.