Bitcoin Forum
June 03, 2024, 12:42:39 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: $40 in BTC for some php/mysql coding help, quick problem  (Read 1211 times)
MoneypakTrader.com (OP)
Sr. Member
****
Offline Offline

Activity: 472
Merit: 250


Never spend your money before you have it.


View Profile
June 01, 2013, 06:20:57 AM
 #1

I have another problem, need to update a db entry with new data overwriting old data rather than creating a new entry

Current Code creates new entry:
$db->beginTransaction();
$Process = $db->prepare("INSERT INTO db1(num, usd, btc, date) VALUES(?, ?, ?, ?, ?)");
$Process->execute(array($_GET['op'], $_POST['usd'], $_POST['btc'], date('Y-m-d H:i:s')));
echo '<div class="alert alert-success">Processed.</div>';
$db->commit();

Please post the correct code to instead update db which has ID entry = $r['id']
It will only be a single entry for the ID.
It should be pretty simple, but I don't know much.
Value for partial or non-functional code: 0BTC
Value for a completely working code substitution: $40 (in BTC).

Just post the code here with your btc address. If it works, you get coin, if not, no coin.

Thanks in advance!

Panchitoboy
Newbie
*
Offline Offline

Activity: 41
Merit: 0


View Profile
June 01, 2013, 06:31:45 AM
 #2

$db->beginTransaction();

$Process = $db->prepare("UPDATE db1 SET (num, usd, btc, date) VALUES(?, ?, ?, ?, ?) WHERE ID entry = $r['id']");

$Process->execute(array($_GET['op'], $_POST['usd'], $_POST['btc'], date('Y-m-d H:i:s')));

echo '<div class="alert alert-success">Processed.</div>';

$db->commit()



or you can use:


$db->beginTransaction();

$Process = $db->prepare("UPDATE db1 SET (num, usd, btc, date) VALUES(?, ?, ?, ?, ?) WHERE ID entry = ? ");

$Process->execute(array($_GET['op'], $_POST['usd'], $_POST['btc'], date('Y-m-d H:i:s'),$r['id']"));

echo '<div class="alert alert-success">Processed.</div>';

$db->commit()


161bSBKWMRzpBANV3yHqsePCBtT143xJEE

nzbmaster
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
June 01, 2013, 06:35:23 AM
 #3

Assuming the primary key for db1 is 'ID':
Code:
<?php
$db
->beginTransaction();
$Process $db->prepare("UPDATE db1 SET num = ?, usd = ?, btc = ?, date = ? WHERE ID = ?");
$Process->execute(array($_GET['op'], $_POST['usd'], $_POST['btc'], date('Y-m-d H:i:s'), $r['id']));
echo 
'<div class="alert alert-success">Processed.</div>';
$db->commit();
?>
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
June 01, 2013, 08:55:36 AM
 #4

Or you could do both: insert the data and, if a key exists, update it
Code:
INSERT INTO db1(num, usd, btc, date) VALUES(?, ?, ?, ?) ON DUPLICATE KEY UPDATE usd=VALUES(usd), btc=VALUES(btc), date=VALUES(date)
Also, validate your input and don't just insert $_GET/$_POST data without checking it first!

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
rudystyle
Sr. Member
****
Offline Offline

Activity: 434
Merit: 250



View Profile
June 01, 2013, 11:03:32 AM
 #5

You have not mentioned the primary key of your table. I am guessing its called "ID" . If it is nzbmaster code  should work. Also as others have pointed out, it maybe good to sanitize GET/POST values first before inserting into the database. A simple thing to do would be to make sure that numbers are checked using the is_numeric() function.

MoneypakTrader.com (OP)
Sr. Member
****
Offline Offline

Activity: 472
Merit: 250


Never spend your money before you have it.


View Profile
June 01, 2013, 09:21:42 PM
 #6

Assuming the primary key for db1 is 'ID':
Code:
<?php
$db
->beginTransaction();
$Process $db->prepare("UPDATE db1 SET num = ?, usd = ?, btc = ?, date = ? WHERE ID = ?");
$Process->execute(array($_GET['op'], $_POST['usd'], $_POST['btc'], date('Y-m-d H:i:s'), $r['id']));
echo 
'<div class="alert alert-success">Processed.</div>';
$db->commit();
?>
It seems to have worked, coins are on the way. Torchat me if you don't receive to 135ZDfQUQua5fwH9dwrX7n1Rkm9HzszrXy within a few hours.
This Thread can be locked.

nzbmaster
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
June 01, 2013, 11:35:29 PM
 #7

Thanks, glad it worked for you.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!