943,636 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1770
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jun 13th, 2009
0

Re: customised the locked textboxes and save as new data

Click to Expand / Collapse  Quote originally posted by tulipputih ...
ok..thanks.this is my code
php Syntax (Toggle Plain Text)
  1. <?php
  2. $query= mysql_query(" SELECT * FROM lesson
  3. WHERE lessonID='" . $_GET['lessonID'] . "'");
  4.  
  5. while($entry=mysql_fetch_array($query))
  6. {
  7. echo " Subject: ";
  8. echo '<input name="subject" readonly="readonly" value="', $entry['subject'] , '" /><br />';
  9. echo " Year:";
  10. echo '<input name="year" readonly="readonly" value="', $entry['year'] , '" /><br />';
  11.  
  12.  
  13. }
  14.  
  15. ?>
Your code misses :

1. Form tag
2. Single quote never evaluates/expand variables.
3. No submit buttons.

Get a hint from the given code:

page1.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $flag="disabled=\"disabled\"";
  3. $cmd=$_REQUEST["cmd"];
  4.  
  5. $query= mysql_query(" SELECT * FROM lesson
  6. WHERE lessonID='" . $_GET['lessonID'] . "'");
  7.  
  8. $no="";
  9. $name="";
  10. if($entry=mysql_fetch_array($query)) {
  11. $no=$entry[0]; $name=$entry[1];
  12. }
  13.  
  14. if(isset($cmd)) {
  15. if($cmd=="Edit")
  16. $flag="";
  17. else
  18. if($cmd=="Update") {
  19. ..... Write code to update a record.
  20. }
  21. }
  22. ?>
  23.  
  24. <form method="post" action="page1.php">
  25. No <input type="text"
  26. <?php echo $flag ?>
  27. name="no"
  28. value="<?php echo $no?>"
  29. />
  30. <br/>
  31. Name <input type="text"
  32. <?php echo $flag ?>
  33. name="name"
  34. value="<?php echo $name?>"
  35. />
  36.  
  37. <input type="submit" name="cmd" value="Edit"/>
  38. <input type="submit" name="cmd" value="Cancel"/>
  39. <input type="submit" name="cmd" <?php echo $flag ?> value="Update"/>
  40. </form>
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 15th, 2009
0

Re: customised the locked textboxes and save as new data

Thanks Atli & Adatapost for your responses.

Adatapost,
What I intend to do is to insert a new record after customising the display data ( by click edit button).. so, I need to change "update" to "insert"..am I?

& how can the id be increased based on the highest id in the table?

thanks
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jun 15th, 2009
0

Re: customised the locked textboxes and save as new data

Click to Expand / Collapse  Quote originally posted by tulipputih ...
Thanks Atli & Adatapost for your responses.

Adatapost,
What I intend to do is to insert a new record after customising the display data ( by click edit button).. so, I need to change "update" to "insert"..am I?

& how can the id be increased based on the highest id in the table?

thanks
Add another submit button with value="Insert" and name="cmd". Compare value of $cmd and if it is "Insert" then write code to insert a record.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 17th, 2009
0

Re: customised the locked textboxes and save as new data

hello all,
thanks for your input
Quote ...
& how can the id be increased based on the highest id in the table?
what I mean here is to enable an ID auto increment whenever we insert a new record to the table.
Do I have to query the maximum number in that table,
then ID++.
Is it correct? any proper syntax?
thanks
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jun 17th, 2009
0

Re: customised the locked textboxes and save as new data

You can simply add the AUTO_INREMENT option to the column that is supposed to incremented, and leave it out of the INSERT query.
sql Syntax (Toggle Plain Text)
  1. CREATE TABLE test (
  2. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `value` VARCHAR(255) NOT NULL,
  4. PRIMARY KEY(`id`);
  5. );
  6.  
  7. INSERT INTO test(`value`)
  8. VALUES ('First'), ('Second'), ('Third');
  9.  
  10. SELECT * FROM test;
  11. +----+--------+
  12. | id | value |
  13. +----+--------+
  14. | 1 | First |
  15. | 2 | SECOND |
  16. | 3 | Third |
  17. +----+--------+
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Jun 18th, 2009
0

Re: customised the locked textboxes and save as new data

owh..thanks
I did used AUTO incerement.
tq.
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jul 3rd, 2009
0

Re: customised the locked textboxes and save as new data

HI adatapost,
I am sorry for coming to this thread again
several questions to ask:

Quote ...
$flag="disabled=\"disabled\"";
to enable the textboxes after click edit, can we code like this ?
php Syntax (Toggle Plain Text)
  1. $unflag="enabled=\"enabled\"";
I have tried this but it doesn't work.

when click the EDIT button, the value in textbox
remains..& can be editted.
currently the value is set to empty = $flag="";

thank you
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jul 3rd, 2009
0

Re: customised the locked textboxes and save as new data

php Syntax (Toggle Plain Text)
  1. $flag="";
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 4th, 2009
0

Re: customised the locked textboxes and save as new data

There is no enabled attribute. There is no need for it.
If the tag isn't specifically marked as disabled, it will be enabled.
So to enable it, simply remove the disabled attribute, as adatapost demonstrated.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Jul 4th, 2009
0

Re: customised the locked textboxes and save as new data

Quote ...
If the tag isn't specifically marked as disabled, it will be enabled.
So to enable it, simply remove the disabled attribute, as adatapost demonstrated
ic, ok..thanks
but I would like to retain the value that is currently displayed.
by using this
php Syntax (Toggle Plain Text)
  1. $flag="";
the textbox is enable..it's correct..but the value inside is emptied.

thank you
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Warning: session_start() [function.session-start]: Cannot send session cache limiter
Next Thread in PHP Forum Timeline: auction script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC