Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
If blank then dont Update
Old 11-04-2009, 07:43 PM If blank then dont Update
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
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 update only when a form updates it?
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-04-2009, 07:58 PM Re: If blank then dont Update
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
side question... how come your sig says php and web design professionally done... pm for html, php help when you're asking a lot of basic information

don't take it offensively I'm just curious

PHP Code:
<?php

<?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;  

if (
$firstname=='' || $lastname=='' || $middlename=='') {
    
$sql mysql_query ("
       UPDATE `testing` SET 
          `FirstName` = '"
.$firstname."', 
          `LastName` = '"
.$lastname."',
          `MiddleName` = '"
.$middlename."' 
       WHERE `id` = '"
.$id."'
    "
)
    OR die (
mysql_error());
}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 08:00 PM Re: If blank then dont Update
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Code:
if($_POST['submit_button_name'] != "" ) {
    do 
update
} else {
    do 
not update;

__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-04-2009, 08:04 PM Re: If blank then dont Update
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
Thanks I used something a little more simple now I have another question...

I am trying to do it so the value in the text box is the current value that is in the database so I do not have to retype, and instead edit it or add on to it.

PHP Code:
<html>
<body>
<?php
if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
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());
echo 
"hello";
}
//form hasent been submitted
{

?>


<form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br>
Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br>
middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br>
<input type="submit" id="submit" name="submit" value="Submit!">
</form>
<?php
}
?>


</body>
</html>
Basicly the value isnt showing up.
PHP Code:
<input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" />
How do I fix that?
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 08:33 PM Re: If blank then dont Update
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
you didn't even call $row yet

PHP Code:
$row mysql_fetch_array(mysql_query("SELECT * FROM 'testing' WHERE id='$id'")); 
and btw your method, somebody can still set text fields to null and empty out your columns
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 08:54 PM Re: If blank then dont Update
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
Thanks here is my final code:

PHP Code:
<html>
<body>
<?php
if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
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());
echo 
"hello";
}

require_once (
'inc/config.php');
$query "SELECT * FROM testing";
$result mysql_query($query) or die(mysql_error());
while (
$row mysql_fetch_array ($result))
{
?>



<form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br>
Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br>
middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br>
<input type="submit" id="submit" name="submit" value="Submit!">
</form>
<?php
}
?>

</body>
</html>
Now I have a new problem:

I want to echo what is currently in the database but it wont show up
PHP Code:
<?php
// show errors if any
error_reporting(E_ALL);
ini_set('display_errors''1');

// require a file
require_once ('inc/config.php');

// select row from table
$query "SELECT * FROM testing";

// check if is valid if it is then show results if not then die
$result mysql_query($query) or die(mysql_error()); 
while (
$row mysql_fetch_array ($result)) 
{
?>
First Name:
<?php $row['FirstName']; ?>
<br>Last Name:
<?php $row['LastName']; ?>
<br>Middle Name:
<?php $row['MiddleName']; ?>
<?
}
?>
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 02:49 AM Re: If blank then dont Update
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You forgot to actually print it.
PHP Code:
<?php $row['Firstname']; ?>
should be
PHP Code:
<?php echo $row['Firstname']; ?>
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-05-2009, 01:00 PM Re: If blank then dont Update
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
Shorthand:
PHP Code:
<?= $row[0?>
Note: "<?=" != "<?php"
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 04:08 PM Re: If blank then dont Update
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
depends on how the server is set up.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-05-2009, 05:57 PM Re: If blank then dont Update
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
Sorry, should've mentioned... In order to use the shorthand method you must have the "short_open_tag" option enabled in your php.ini file. Also, the use of shorthand is highly discouraged given the decreased portability.

That doesn't mean you can't still love it. As a pure text-only coder it just "feels" cleaner to me.
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to If blank then dont Update
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52888 seconds with 12 queries