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
Updating a table HELP!!
Old 05-26-2009, 10:55 AM Updating a table HELP!!
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all I am passing varabiles from one page to another. I know this is working as I have echo the result what are coreect, but it just dont want to update the database. And I can not see why any help be amazing thanks.

Code:
<?php
$price_code=$_REQUEST['price_code'];
$price=$_REQUEST['price'];
$description=$_REQUEST['description'];
echo "$price_code";
echo"$price";
echo"$description";
##################################################
#Open database                                   # 
##################################################
include("connect.php");
##################################################
#Run Query                                       # 
##################################################
$query = "UPDATE price
				SET
				price_code = '$price_code',
				Price = '$price',
				Description = '$description'
				WHERE price_code = '$price_code'";
$result = mysql_query($query,$db)
		or die("Couldn't execute update query.");		

$query = "select * from price"; 
$result = mysql_query($query,$db)
		or die("Couldn't execute list query.");; 
$nrows = mysql_num_rows($result); 
?>
<table width="48%" border="1" align="center" bordercolor="#000000" bgcolor="#CCCCCC">
  <tr> 
    <td><div align="center"><b>Price Code</b></div></td>
    <td><div align="center"><b>Description</b></div></td>
    <td><div align="center"><b>Price</b></div></td>
  </tr>
<?php  
##################################################
#Extract and place data in table                 # 
##################################################
$row=0; 
while($row < $nrows) 
{  $price_code = mysql_result($result,$row,"price_code"); 
   $description     = mysql_result($result,$row,"description"); 
   $price = mysql_result($result,$row,"price"); 
   
   echo "
  <tr> 
    <td>$price_code</td>
    <td>$description</td>
    <td>$price</td>
  </tr>
   "; 
   $row++; 
} 
?>
</table>
thanks in advance
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 05-26-2009, 11:40 AM Re: Updating a table HELP!!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
ok, first thing, "print" the query sent to the db, and try to execute it directly in the db.
If there is an error, mysql will tell you exactly what is wrong (which php simply don't do).

You can go a bit further in your db error management to show you the error message returned by mysql and the query sent, with something like this:
PHP Code:
<?php
$price_code
=$_REQUEST['price_code'];
$price=$_REQUEST['price'];
$description=$_REQUEST['description'];
echo 
"$price_code";
echo
"$price";
echo
"$description";
##################################################
#Open database                                   # 
##################################################
include("connect.php");
##################################################
#Run Query                                       # 
##################################################
$query "UPDATE price
                SET
                price_code = '
$price_code',
                Price = '
$price',
                Description = '
$description'
                WHERE price_code = '
$price_code'";
$result mysql_query($query,$db);
if(
$result===FALSE){
    print 
"<pre>$query<br/>".mysql_error()."</pre>";
    die();
}

$query "select * from price"
$result mysql_query($query,$db);
if(
$result===FALSE){
    print 
"<pre>$query<br/>".mysql_error()."</pre>";
    die();
}
$nrows mysql_num_rows($result); 
?>
<table width="48%" border="1" align="center" bordercolor="#000000" bgcolor="#CCCCCC">
  <tr> 
    <td><div align="center"><b>Price Code</b></div></td>
    <td><div align="center"><b>Description</b></div></td>
    <td><div align="center"><b>Price</b></div></td>
  </tr>
<?php  
##################################################
#Extract and place data in table                 # 
##################################################
$row=0
while(
$row $nrows
{  
$price_code mysql_result($result,$row,"price_code"); 
   
$description     mysql_result($result,$row,"description"); 
   
$price mysql_result($result,$row,"price"); 
   
   echo 
"
  <tr> 
    <td>
$price_code</td>
    <td>
$description</td>
    <td>
$price</td>
  </tr>
   "

   
$row++; 

?>
By the way, your update is a bit strange, as you seem to update the value of price_code with the same value than the one that was already there...
Are you sure it's what you want ? Or is it just an copy/paste mistake ?
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 05-26-2009 at 11:48 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-26-2009, 11:50 AM Re: Updating a table HELP!!
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
sorted it out guys/girls it was not passing a hidden value over
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 05-26-2009, 12:17 PM Re: Updating a table HELP!!
Novice Talker

Posts: 5
Trades: 0
Quote:
Originally Posted by millwalll View Post
sorted it out guys/girls it was not passing a hidden value over
thanks buddy, it's solve my problem too
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
han55 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Updating a table HELP!!
 

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.32000 seconds with 12 queries