Go Down

Topic: Get var from database , change it , and update it (Read 529 times) previous topic - next topic

theexit300

Mar 26, 2018, 03:43 pm Last Edit: Mar 26, 2018, 04:03 pm by theexit300
hello ,i am sorry for my English.

I have a project for school , where we have to create an autonomous bakery.

I use arduino and i'm stuck with few php code

I fact i have a database like this with WAMP

Name : stock

ID | Total
1   | 16
7  | 14
11 | 128
13 | 29


What i would like to do is to take the Var in the collum Total where the ID is , for example 7
So it would give me : 14
Then i have an another var to this one from the link , and update it where he is
/!\ The collum ID is not the default ID given by wamp server , it's a hand made collum /!\

link : localhost/add.php?total=6&user=11


So when my php file is used i SHOULD have now but in fact , nothing happen.

11 | 139

Here is my current code with the places where i have some troubleshoots



Code: [Select]

<?php 


try
{
$bdd = new PDO('mysql:host=localhost;dbname=epicerie','root','');
}
catch(
Exception $e)
{
die(
'Erreur : '.$e->getMessage());
}

$user $_GET["user"];



$argentpresent $bdd->query('SELECT Total FROM client WHERE ID = "$user"'); // don't work
print_r($argentpresent); // PDOStatement Object ( [queryString] => SELECT Total FROM client WHERE (ID) = "$user" ) 
// it gives me PDOStatement Object ( [queryString] => SELECT Total FROM client WHERE ID = "$user" ) instead of my value 
// and it's empty if i fetch it and look with echo.

$ttl $argentpresent+('.$_GET["total"]'); // Notice: Object of class PDOStatement could not be converted to int in C:\wamp\www\add.php on line 22

$bdd->exec('UPDATE client SET Total=$argent WHERE ID = "$user"'); // don't work too ! Help !
?>





Why i use arduino forum ?

Because my arduino calls the php file :-)
Hope i could get some help.

robtillaart

hello ,i am sorry for my English.

....

Why i use arduino forum ?

Because my arduino calls the php file :-)
Hope i could get some help.
your english is pretty good, no apology needed,
however your logic to choose the arduino forum ......  I must say it made me smile

First thing to do with databases is to get your SQL right in a (mysql) command line tool.
If that works you can wrap them within PHP and go beyond.

https://www.tutorialspoint.com/mysql/index.htm

(I assumed you use mysql)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Quote
Because my arduino calls the php file :-)
How? That is what we would want to know.
The art of getting good answers lies in asking good questions.

Go Up