PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
# connect to the database
mysql_connect(*****);
mysql_select_db('*****');
$id = (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id'])) ? $_GET['id'] : 0;
$sql = "SELECT * FROM `proof`,`users` WHERE users.id = $id and proof.userproof_id = $id UPDATE users set user_money = user_money + perperson WHERE users.id = $id" or die( mysql_error() );
?>
This obviously doesnt work as i cant join the tables proof/users correctly. Ive tried a few ways now and im getting no where
the perperson is the intergers to add to the overall money but perperson is in table proof. Hence why im trying to join them. Then the WHERE part just secures the money goes to the right user as both should = $id.
I feel ive got the right idea but just can not execute it. Any advice would be great.
As far as I'm aware, you can't do a SELECT and an UPDATE in the same SQL statement. You'd need to use two separate statements: one for the UPDATE and a second for the SELECT.
Hmm maybe im coding this wrong in the query as when i try withdraw data from one of the tables just to see if information is being selected it displays nothing. Aswell as no calculations are done. I need to break up the two queries but i still think im writing the actual queries wrong.
You can test the queries in isolation with something like phpMyAdmin. Also consider testing the return value from mysql_query(), it should be a resource, not false. A call to mysql_error() will return a string explaining what went wrong last.
Ok ill log on to phpmyadmin now and give it a go the select query worked ... Aha in the update query this goes wrong
#1054 - Unknown column 'perperson' in 'field list' i also tried
#1054 - Unknown column 'proof.perperson' in 'field list'
why doesnt the update understand where perperson is when the table proof is selected :S
The code starts as UPDATE users so maybe it just gets all the information from users and not proof table to so it doesnt understand perperson field. So the question is how can i make the update query understand another table kinda thing
You're making queries but you're not doing anything with the resource returned. Walk through the steps on a basic tutorial for querying and showing results from a query, in PHP using MySQL.