PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old November 3rd, 2009, 07:56 AM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
Quote:
Originally Posted by woger
Am I right in thinking from an end users point of view, I should be able to get PHP to look at the 0, and if there's a 0, put in a NO, else a Yes?


That's correct, please do that.

Don't forget in the form.php to avoid the id fields to be modified. You should display them as regular text and also have it's value in a hidden input field.

Let me know when we are done here, I will point you to some other stuff.
__________________
Best Regards!

- Dehumanizer

Reply With Quote
  #17  
Old November 3rd, 2009, 04:50 PM
achardrys's Avatar
achardrys achardrys is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 192 achardrys Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 14 h 1 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by woger
Always happy to take advice - just never sure how far to push one's welcome.
And with a couple hundred posts, I guess you're pretty busy too. Mine have mostly been questions - and I know that takes time. You guys who answer (and who are patient) deserve a medal.
I'll change the code now - just fixed the sql injection.
Works well - much easier to input.

Am I right in thinking from an end users point of view, I should be able to get PHP to look at the 0, and if there's a 0, put in a NO, else a Yes?


A reputation point would help
But another thing that would help is if the user is going to be inputting text, comma's might look funny. When you use commas either MySql or PHP changes ' to \' . Use stripslashes() around the input you add to the database and take out, otherwise it'll look funny.
PHP Code:
 $example stripslashes($example); 
Comments on this post
woger disagrees: Your advice on security has been very helpful. Are the stripslashes all that criticial in this
scenario? Only 1 user/operator!

Reply With Quote
  #18  
Old November 4th, 2009, 05:02 AM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
Quote:
Originally Posted by Dehumanizer
That's correct, please do that.

Don't forget in the form.php to avoid the id fields to be modified. You should display them as regular text and also have it's value in a hidden input field.

Let me know when we are done here, I will point you to some other stuff.

I searched the web, and found bool - so I assume if I get bool(limit), it will read the 1 0r 0 and return yes or no. That's how I thought I read it.
In my display_plants.php, how do I access those 2 fields from the sql query and the loop?
PHP Code:
for ($i 0$i mysql_num_fields($result); $i++)
// {
// echo ("<td bgcolor='#FFCC00'>". mysql_field_name($result, $i) ."</td>");
// }
 
//echo ("\n</tr>");
 
while ($row mysql_fetch_array($result))
 {
 echo (
"<tr>\n");
 for (
$i 0$i mysql_num_fields($result); $i++)
  {
  echo(
"<td bgcolor='#FFccff'>" $row[$i] . "</td>");
  }
 echo (
"\n</tr>");    
 }
 echo (
"\n</table>\n");
 print 
"There are " mysql_num_rows($result) . " rows in the $database database\n";
?> 

I also changed the value of id in the form to hidden. I don't want it edited, but do want it displayed. How do i display it as "plain text"?

Reply With Quote
  #19  
Old November 4th, 2009, 07:46 AM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
Please try this code:

PHP Code:
for ($i 0$i mysql_num_fields($result); $i++)
// {
// echo ("<td bgcolor='#FFCC00'>". mysql_field_name($result, $i) ."</td>");
// }
 
//echo ("\n</tr>");
 
while ($row mysql_fetch_array($result))
 {
 echo (
"<tr>\n");
 for (
$i 0$i mysql_num_fields($result); $i++)
  {
if(
$row[$i] == 1; ) { $value "Yes"; } elseif ($row[$i] == 0) { $value "No"; }  else { $value $row[$i]; }
  echo(
"<td bgcolor='#FFccff'>" $value "</td>");
  }
 echo (
"\n</tr>");    
 }
 echo (
"\n</table>\n");
 print 
"There are " mysql_num_rows($result) . " rows in the $database database\n";
?> 

Reply With Quote
  #20  
Old November 4th, 2009, 03:22 PM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
I can make sense of what you've done there, but it now shows botanical name and common name as "yes or no".
The display.php can be viewed here
These are the changes I made

PHP Code:
for ($i 0$i mysql_num_fields($result); $i++)
// {
// echo ("<td bgcolor='#FFCC00'>". mysql_field_name($result, $i) ."</td>");
// }
 
//echo ("\n</tr>");
 
while ($row mysql_fetch_array($result))
 {
 echo (
"<tr>\n");
 for (
$i 0$i mysql_num_fields($result); $i++)
  {
  if(
$row[$i] == ) { 
  
$value "Yes"
  } 
  elseif (
$row[$i] == 0) { 
  
$value "No"
  }  
  else { 
  
$value $row[$i]; 
  }
  echo(
"<td bgcolor='#FFccff'>" $value "</td>");
  }
 echo (
"\n</tr>");    
 }
 echo (
"\n</table>\n"); 

Reply With Quote
  #21  
Old November 5th, 2009, 01:23 AM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
Ok, lets change the below code:

PHP Code:
if($row[$i] == ) { 
  
$value "Yes"
  } 
  elseif (
$row[$i] == 0) { 
  
$value "No"
  }  
  else { 
  
$value $row[$i]; 
  } 


To the following code:

PHP Code:
if($row[$i] == ) { 
  
$value "Yes"
  } 
  if (
$row[$i] == 0) { 
  
$value "No"
  }  
  if (!
is_numeric($row[$i])) { 
  
$value $row[$i]; 
  } 

Reply With Quote
  #22  
Old November 5th, 2009, 05:58 AM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
I implemented that change. ID is the only column to display using that.
View here

Reply With Quote
  #23  
Old November 5th, 2009, 06:48 AM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
Yes, my mistake.

Please show me your entire display_plants1.php code.

Reply With Quote
  #24  
Old November 5th, 2009, 03:55 PM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
Quote:
Originally Posted by Dehumanizer
Yes, my mistake.

Please show me your entire display_plants1.php code.

This the orginal display_plants1.php code:
PHP Code:
<?php
require ("dbcnx.php");

//Display Table
$result mysql_query("SELECT * FROM $table ORDER BY id ASC");
 
if (!
$result)
 {
 die(
'<p>Error performing query: ' mysql_error() . '</p>');
 }

echo 
"<table border='1' width='80%'cellpadding='3' cellspacing='0'>";
echo 
"<tr>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>ID</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Botanical Name</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Common Name</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Size</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Readily Avail</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Limit Avail</strong></td>";

echo 
"</tr>";




for (
$i 0$i mysql_num_fields($result); $i++)
// {
// echo ("<td bgcolor='#FFCC00'>". mysql_field_name($result, $i) ."</td>");
// }
 
//echo ("\n</tr>");
 
while ($row mysql_fetch_array($result))
 {
 echo (
"<tr>\n");
 for (
$i 0$i mysql_num_fields($result); $i++)
  {
  if(
$row[$i] == ) { 
  
$value "Yes"
  } 
 if (
$row[$i] == 0) { 
  
$value "No"
  }  
  if (!
is_numeric($row[$i])) { 
  
$value $row[$i]; 
  }  
  }
  echo(
"<td bgcolor='#FFccff'>" $value "</td>");
  }
 echo (
"\n</tr>");    

 echo (
"\n</table>\n");
 print 
"There are " mysql_num_rows($result) . " rows in the $database database\n";
?>

Thanks

Reply With Quote
  #25  
Old November 5th, 2009, 06:43 PM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
Hello, it is tested:

PHP Code:
<?php

require ("dbcnx.php"); 

//Display Table
$result mysql_query("SELECT * FROM plant_name ORDER BY id ASC");
 
if (!
$result)
 {
 die(
'<p>Error performing query: ' mysql_error() . '</p>');
 }

echo 
"<table border='1' width='80%'cellpadding='3' cellspacing='0'>";

echo 
"<tr>";

echo 
"<td align='center' bgcolor='#FF3399'><strong>ID</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Botanical Name</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Common Name</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Size</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Readily Avail</strong></td>";
echo 
"<td align='center' bgcolor='#FF3399'><strong>Limit Avail</strong></td>";

echo 
"</tr>";

while (
$row mysql_fetch_array($result)) {

echo 
"<tr>";

if(
$row["readily_avail"] == 1) { $readilyAvail "Yes"; } else { $readilyAvail "No"; }
if(
$row["limit_avail"] == 1) { $limitAvail "Yes"; } else { $limitAvail "No"; }

echo 
"<td align='center'><strong>"$row["id"] ."</strong></td>";
echo 
"<td align='center'><strong>"$row["botanical_name"] ."</strong></td>";
echo 
"<td align='center'><strong>"$row["common_name"] ."</strong></td>";
echo 
"<td align='center'><strong>"$row["size"] ."</strong></td>";
echo 
"<td align='center'><strong>"$readilyAvail ."</strong></td>";
echo 
"<td align='center'><strong>"$limitAvail ."</strong></td>";

echo 
"</tr>";

}    

 echo (
"\n</table>\n");
 print 
"There are " mysql_num_rows($result) . " rows in the $database database\n";
?>


However I don't know the name of your botanical name and size db fields. Please change accordingly.

Reply With Quote
  #26  
Old November 7th, 2009, 04:22 PM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
Finally got access to my site (still don't know what was wrong).

That's perfect now, thanks!!!

Reply With Quote
  #27  
Old November 7th, 2009, 08:11 PM
Dehumanizer Dehumanizer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 225 Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level)Dehumanizer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 14 h 31 sec
Reputation Power: 6
In your form.php you are not showing your id. You can go two ways. If you want to display the id you can change the below code:

PHP Code:
<input name="id<? echo $i; ?>" type="hidden" value="<? echo $row["id"]; ?>" /> 


To the following:

PHP Code:
<?php echo $row["id"]; ?>
<input name="id<? echo $i?>" type="hidden" value="<? echo $row["id"]; ?>" />


You can also opt to not have the id column at all and place the hidden value together with the common name:

PHP Code:
<input name="id<? echo $i; ?>" type="hidden" value="<? echo $row["id"]; ?>" />
<
input name="common<? $i; ?>" type="text" value="<? echo $row["common_name"]; ?>" /> 

Reply With Quote
  #28  
Old November 7th, 2009, 10:41 PM
woger woger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 228 woger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 45 m 54 sec
Reputation Power: 5
Thanks
I opted for the ID, because, unless I include all the fields in the form, whoever updates it may need to differentiate between different plants with the same common name.

Thanks heaps

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Help to create a modify form in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek