PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old March 17th, 2013, 02:15 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
HELP - Updating Database through TEXT Boxes



the user will change the price here (text boxes) hit update and it will update all rows (no javascript please - we can just update all rows).

Need help on Process Page code. or ideas on how to go about it.


---- code on current page ----
PHP Code:
 $result2 mysql_query("SELECT * 
                          FROM available
                          JOIN land
                          ON available.building = land.building
                          WHERE land.landlord = '
$landlordselect'
                          ORDER by available.price ASC"
);
                         
echo 
"<table border='1'>
<tr>
<th>Building</th>
<th>Apartment #</th>
<th>Price</th>
<th># of Bedrooms</th>
<th>Move in</th> 
<th>Rented</th>
</tr>"
;
while(
$row mysql_fetch_array($result2))
  {
  echo 
"<tr>";
  echo 
"<td>" $row['building'] . "</td>";
  echo 
"<td>" $row['apt'] . "</td>";
  
?>
  <form action="processpage.php" method="post">
   <td><input name="uprice[]" type="text" size="5" value="<?php echo( htmlspecialchars$row['price'] ) ); ?>" /> </td>
  <?php
  
echo "<td>" $row['bedroom'] . "</td>";
  echo 
"<td>" $row['movein'] . "</td>"?>
  <td><input type="checkbox" name="rent[]" value="yes"></td>
  <?php
  
echo "</tr>";
  }
echo 
"</table>";
?>
   <p><input type="submit" value="Update"><p>
  </form> 

Reply With Quote
  #2  
Old March 17th, 2013, 03:47 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
First enclose your code in [ PHP ] tags. See the sticky at the top of this forum.

Second, DO NOT use the deprecated MySQL extensions. Switch to PDO and prepared statements.

Third, you don't show any code where you try to update the database. I am assuming that is where you are stuck. When processpage.php is invoked, $_POST will contain the form fields. Use that to update your database.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old March 17th, 2013, 04:30 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
First enclose your code in [ PHP ] tags. See the sticky at the top of this forum.

Second, DO NOT use the deprecated MySQL extensions. Switch to PDO and prepared statements.

Third, you don't show any code where you try to update the database. I am assuming that is where you are stuck. When processpage.php is invoked, $_POST will contain the form fields. Use that to update your database.


exactly where i'm stuck.

I'm stuck at the logistical part I want it to go and through and update each price box. to the corresponding apartment.

Reply With Quote
  #4  
Old March 17th, 2013, 04:44 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
You set the arrays from $_POST and process them accordingly:
PHP Code:
 $uprice=$_POST['urpice'];
$rent=$_POST['rent']; 

Then '$uprice' and '$rent' will be arrays containing the data from the form. You can use a 'foreach' or just a 'for' to process them.

Reply With Quote
  #5  
Old March 17th, 2013, 05:31 PM
BarryG BarryG is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: Sydney Australia
Posts: 131 BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 51 m 28 sec
Reputation Power: 83
Quote:
Originally Posted by Loren646
$result2 = mysql_query("SELECT *
FROM available
JOIN land
ON available.building = land.building
WHERE land.landlord = '$landlordselect'
ORDER by available.price ASC");



Your code has no identity for which rows of your database you want to update.
You'll need to pull say a property_id for each row, and put it in the table in say a <hidden> input type. The <hidden> inputs will need to be inside the <form> </form> data so that it will be posted for processing.
Then the processing script can step through the arrays of property_id, and price and update the database as appropriate.

Reply With Quote
  #6  
Old March 17th, 2013, 05:35 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
You set the arrays from $_POST and process them accordingly:
PHP Code:
 $uprice=$_POST['urpice'];
$rent=$_POST['rent']; 

Then '$uprice' and '$rent' will be arrays containing the data from the form. You can use a 'foreach' or just a 'for' to process them.


exactly. i understand that. I just don't understand how i tell the table to update that specific row.

maybe i can a order by price ASC again and then have it loop each one and update each row.

Reply With Quote
  #7  
Old March 17th, 2013, 05:37 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by BarryG
Your code has no identity for which rows of your database you want to update.
You'll need to pull say a property_id for each row, and put it in the table in say a <hidden> input type. The <hidden> inputs will need to be inside the <form> </form> data so that it will be posted for processing.
Then the processing script can step through the arrays of property_id, and price and update the database as appropriate.


hmm interesting... i'll try to wrap my head around this... still a bit confusing...

Reply With Quote
  #8  
Old March 17th, 2013, 05:44 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
What about this...

I have a check box next to each row. The value will be saved as the Primary ID. Then on the update processing page it will search WHERE = PRIMARY ID and update that row?

Reply With Quote
  #9  
Old March 17th, 2013, 05:46 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
How do you identify the rows in your database for each property?

Reply With Quote
  #10  
Old March 17th, 2013, 06:06 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
How do you identify the rows in your database for each property?


auto incrementing primary id? now i have to figure out a way to to associate the new price with the primary id.

maybe a loop?

Reply With Quote
  #11  
Old March 17th, 2013, 09:32 PM
BarryG BarryG is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: Sydney Australia
Posts: 131 BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 51 m 28 sec
Reputation Power: 83
Quote:
Originally Posted by Loren646
now i have to figure out a way to to associate the new price with the primary id.

maybe a loop?


Your lazy SELECT * will be retrieving the auto_increment id of the property. Say for argument's sake, it's building_id.
Write that to the row in the table like this.
PHP Code:
<?php
while ($row mysql_fetch_array($result2)){
echo 
"<form action=\"processpage.php\" method=\"post\">";
echo 
"<tr>";
echo 
"<td><input type=\"hidden\" value=\"{$row['building_id']}\" name=\"building_id[]\">$row['building']</td>";
echo 
"<td>{$row['apt']}</td>";
echo 
"<td><input name=\"uprice[]\" type=\"text\" size=\"5\" value=\""htmlspecialchars($row['price'] ) ."\" /> </td>";
echo 
"<td>{$row['bedroom']}</td>";
echo 
"<td>{$row['movein']}</td>"
echo 
"<td><input type=\"checkbox\" name=\"rent[]\" value=\"yes\"></td>";
echo 
"</tr>";
}
echo 
"</table>";
?>
<p><input type="submit" value="Update"><p>
</form>


In your processing script, you'll get an array of building_id's in $_POST['building_id'] that will be the id of the row you need to update with the data from the corresponding $_POST['uprice'] array.
IOW, the first building_id will use the first uprice, the second building _id will use the second uprice ......

Get it?

You also need to be aware that the "rent" checkbox will only be present if it is checked. If it's not checked, it's not sent.

Last edited by BarryG : March 17th, 2013 at 09:37 PM.

Reply With Quote
  #12  
Old March 18th, 2013, 01:12 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
BarryG. Works perfect! thanks for the help.

What are your thoughts on the check marks? so it might be an array of only 2 items when there are 5 items. I think it'll put the information in the wrong column. I could change the checkboxes to text boxes and just have it say 0 or 1 if i must.


So this is what i have now.

Update page:
PHP Code:
 $countadd=0;
while(
$row mysql_fetch_array($result2))
  {

  echo 
"<tr>";
  echo 
"<td>" $row['building'] . "</td>";
  
?>
  <form action="updateprocess.php" method="post">
   <td><input name="uapt[]" type="text" size="5" value="<?php echo( htmlspecialchars$row['apt'] ) ); ?>" /> </td>
   <td><input name="uprice[]" type="text" size="5" value="<?php echo( htmlspecialchars$row['price'] ) ); ?>" /> </td>
   <td><input name="ubedroom[]" type="text" size="5" value="<?php echo( htmlspecialchars$row['bedroom'] ) ); ?>" /> </td>
   <td><input name="umovein[]" type="text" size="25" value="<?php echo( htmlspecialchars$row['movein'] ) ); ?>" /> </td>
   <td><input type="checkbox" name="urent[]" value="yes"></td>
   <td><input type="checkbox" name="uupdate[]" value="<?php echo $row['prim']; ?>"></td>
   <td><input type="hidden" value="<?php echo $row['prim']; ?>" name="prim_id[]"><?php $row['prim'?></td>
   <td><input type="hidden" value="<?php echo $countadd ?>" name="countadd"><?php $countadd ?></td>
   <?php $countadd++; ?>
   
  <?php
  
echo "</tr>";
  }
echo 
"</table>";
?>
   <p><input type="submit" value="Update"><p>
  </form> 

Process page
PHP Code:
 $rent=$_POST['urent'];
$update=$_POST['uupdate'];
$apt=$_POST['uapt'];
$price=$_POST['uprice'];
$bedroom=$_POST['ubedroom'];
$movein=$_POST['umovein'];
$prim_id=$_POST['prim_id'];
$count=$_POST['countadd'];

  
    if (!
get_magic_quotes_gpc())
  {
    
$apt addslashes($apt);
    
$price doubleval($price);
    
$bedroom addslashes($bedroom);
    
$movein addslashes($movein);
  }


$conn mysql_connect("localhost","user","password");
mysql_select_db("listing");

for (
$i2 0$i2 <= $count$i2++) {
mysql_query("UPDATE available
        SET apt='
$apt[$i2]', price='$price[$i2]', bedroom='$bedroom[$i2]', movein='$movein[$i2]'
        WHERE prim='
$prim_id[$i2]'");


Reply With Quote
  #13  
Old March 18th, 2013, 01:58 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
As requested in the beginning wrap your code in [ PHP ] tags. It is too hard to read unformatted. See the sticky at the top of this forum. Edit your previous post to fix it.

Reply With Quote
  #14  
Old March 18th, 2013, 04:08 PM
Loren646 Loren646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 19 Loren646 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 41 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
As requested in the beginning wrap your code in [ PHP ] tags. It is too hard to read unformatted. See the sticky at the top of this forum. Edit your previous post to fix it.


sorry about that. done.

Reply With Quote
  #15  
Old March 18th, 2013, 06:13 PM
BarryG BarryG is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: Sydney Australia
Posts: 131 BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 51 m 28 sec
Reputation Power: 83
Quote:
Originally Posted by Loren646
BarryG. Works perfect! thanks for the help.

What are your thoughts on the check marks?


You could use the building_id as the index of your array of building_id, price and rent instead of letting php assign them as 0,1,2 ....

Then if the rent checkbox with the building id index exists, then the box was checked.
PHP Code:
<?php
while ($row mysql_fetch_array($result2)){
$b_id $row['building_id'];
echo 
"<form action=\"processpage.php\" method=\"post\">";
echo 
"<tr>";
echo 
"<td><input type=\"hidden\" value=\"$b_id\" name=\"building_id[$b_id]\">$row['building']</td>";
echo 
"<td>{$row['apt']}</td>";
echo 
"<td><input name=\"uprice[$b_id]\" type=\"text\" size=\"5\" value=\""htmlspecialchars($row['price'] ) ."\" /> </td>";
echo 
"<td>{$row['bedroom']}</td>";
echo 
"<td>{$row['movein']}</td>"
echo 
"<td><input type=\"checkbox\" name=\"rent[$b_id]\" value=\"yes\"></td>";
echo 
"</tr>";
}
echo 
"</table>";
?>
<p><input type="submit" value="Update"><p>
</form>


You get the value and key of each element with a
PHP Code:
foreach ($_POST['building_id'] as $building => $b_id) {
   
// $b_id is the index for the $_POST['price'][$b_id] and the rent checkbox
// do stuff with each element


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > HELP - Updating Database through TEXT Boxes

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap