CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Update History

Print topic Send  topic

Author Message
AndreSch

Posts: 27
Posted: 07/26/2008, 3:43 AM

U am using Mysql, PHP.
I am trying to update a hitory table for a simple auction system. the 2 tables of relevance are:
Items: Offers (the history table):
item_no (PK) offers_id (PK)
Descript item_no (FK)
Buyer buyer
Bid bid
Phone phone
Reminder remind_me

In my bid_maint screen where I add (update) these bid information I added custom code for
AfterExecuteUpdate
//Custom Code @89-2A29BDB7
// -------------------------
$db = new clsDBradioton();
$SQL = "INSERT INTO offers (item_no, buyer, phone, bid, remind_me) ".
"VALUES (". $db->ToSQL(CCGetFromGet("item_no",0),ccsInteger) .",". $db->ToSQL(CCGetFormGet("buyer",0),ccsText) .",".
$db->ToSQL(CCGetFromGet("phone",0),ccsText) .",". $db->ToSQL(CCGetFromGet("bid",0),ccsDecimal) .",".
$db->ToSQL(CCGetFromGet("remind_me",0),ccsInteger) .")";

$db->query($SQL);
$db->close();
// -------------------------
//End Custom Code

2 things: I get an error for the Values and (b) it does not update my table

Please help
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/26/2008, 4:06 AM

(use the "code" button or tags to enclose coding examples)

At first glance,
you have inteerchanged bid and phone
  
Items:                                     Offers (the history table):  
item_no (PK)                        offers_id (PK)   
Descript                                 item_no (FK)  
Buyer                                      buyer  
Bid                                          bid  
Phone                                    phone  
Reminder                              remind_me  

your code you should change to
  
$SQL = "INSERT INTO offers (item_no, buyer, bid, phone, remind_me) VALUES (".   
   $db->ToSQL(CCGetFromGet("item_no",0),ccsInteger) .",".   
   $db->ToSQL(CCGetFormGet("buyer",0),ccsText) .",".   
   $db->ToSQL(CCGetFromGet("bid",0),ccsDecimal) .",".   
   $db->ToSQL(CCGetFromGet("phone",0),ccsText) .",".   
   $db->ToSQL(CCGetFromGet("remind_me",0),ccsInteger) .  
")";   

The table is not updated because the SQL is faulty.

At second glance,
1: You did do the SQL right as I just seen that in the part before the VALUES you also intechanged phone and bid, so that is no real problem.
what do you use the CCGetFromGet for????, study the CCGetParam() command.
I doubt that all that data is on the URL, CCGetParam() will look at the GET parameters and if not present check the POST parameters.
Please explain, for now I supsect that your SQL is garbled, meaning the values are not what you expect..
You could add a print( $SQL): just before the $db->query($SQL);
That will show you the resulting SQL, which you can feed to your DB through f.i. PhPMyAdmin to see what it does.
(or set Debug = True in db_mysql.php or db_mysqli.php)

Walter



_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
datadoit
Posted: 07/26/2008, 6:37 AM

Wouldn't you want CCGetFromPost()?

Debug advice: Drop in an 'echo $SQL; exit;' before doing the query.
Take that SQL statement to your favorite db manager software (such as
PHPMyAdmin or MySQL Manager) and run it to see what happens.

Finally, to avoid having to match up column names and their orders with
the values to insert, try using the format:

INSERT INTO offers SET field1=value, field2=value, etc.

Should make things easier to track.
AndreSch

Posts: 27
Posted: 07/26/2008, 9:29 AM

Thanks Guys!!
Well to be honest, I am no programmer and am only learning.

The insert into make sense and lets see if I understand this correct?

// -------------------------
$db = new clsDBradioton();
$SQL = "INSERT INTO offers (item_no={item_no}, buyer={buyer}, phone={phone}, bid={bid}, remind_me={remind})";

$db->query($SQL);
$db->close();
// -------------------------

But nothing happens:
Should I add offer_id (my auto increment PK) also to the update string? I believe the $db->query($SQL); should not be query but honestly, have no idea hoe this should look.
View profile  Send private message
datadoit
Posted: 07/26/2008, 10:35 AM

AndreSch wrote:
> U am using Mysql, PHP.
> I am trying to update a hitory table for a simple auction system. the 2 tables
> of relevance are:
> Items: Offers (the history table):
> item_no (PK) offers_id (PK)
> Descript item_no (FK)
> Buyer buyer
> Bid bid
> Phone phone
> Reminder remind_me
>
> In my bid_maint screen where I add (update) these bid information I added
> custom code for
> AfterExecuteUpdate
> //Custom Code @89-2A29BDB7
> // -------------------------
> $db = new clsDBradioton();
> $SQL = "INSERT INTO offers (item_no, buyer, phone, bid, remind_me) ".
> "VALUES (". $db->ToSQL(CCGetFromGet("item_no",0),ccsInteger) .",".
> $db->ToSQL(CCGetFormGet("buyer",0),ccsText) .",".
> $db->ToSQL(CCGetFromGet("phone",0),ccsText) .",".
> $db->ToSQL(CCGetFromGet("bid",0),ccsDecimal) .",".
> $db->ToSQL(CCGetFromGet("remind_me",0),ccsInteger) .")";
>
> $db->query($SQL);
> $db->close();
> // -------------------------
> //End Custom Code
>
> 2 things: I get an error for the Values and (b) it does not update my table
>
> Please help
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
Here you go:

$db = new clsDBradioton();

$SQL = "INSERT INTO offers SET "
.. "item_no=" . $db->ToSQL(CCGetFromPost("item_no",0), ccsInteger) . ", "
.. "buyer=" . $db->ToSQL(CCGetFromPost("buyer",""), ccsText) . ", "
.. "bid=" . $db->ToSQL(CCGetFromPost("bid",0), ccsDecimal) . ", "
.. "phone=" . $db->ToSQL(CCGetFromPost("phone",""), ccsText) . ", "
.. "remind_me=" . $db->ToSQL(CCGetFromPost("remind_me",0), ccsInteger);

$db->query($SQL);
$db->close();
AndreSch

Posts: 27
Posted: 07/26/2008, 3:06 PM

Thanks a Lot!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.