Author

Topic: $40 in BTC for some php/mysql coding help, quick problem (Read 1231 times)

newbie
Activity: 19
Merit: 0
Thanks, glad it worked for you.
sr. member
Activity: 472
Merit: 250
Never spend your money before you have it.
Assuming the primary key for db1 is 'ID':
Code:
$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 
'Processed.
';
$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.
sr. member
Activity: 434
Merit: 250
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.
hero member
Activity: 576
Merit: 514
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!
newbie
Activity: 19
Merit: 0
Assuming the primary key for db1 is 'ID':
Code:
$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 
'Processed.
';
$db->commit();
?>
newbie
Activity: 41
Merit: 0
$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 '
Processed.
';

$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 '
Processed.
';

$db->commit()


161bSBKWMRzpBANV3yHqsePCBtT143xJEE

sr. member
Activity: 472
Merit: 250
Never spend your money before you have it.
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 '
Processed.
';
$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!
Jump to: