Jump to content

Game Help


Go to solution Solved by Luke_Watson,

Recommended Posts

Hi guys I am working on a small project for my site, the site of mine sells digital codes so I thought it would be fun to have a section where my customers can go and gamble for the chance to win a code..

 

So I have the main bulk of the application, currently the game works like the slots, you click play and 3 numbers are generated, each number = a prize you can win match 3 prizes and win a ... prize!

 

So the codes will be stored in a database and be shown on screen, and probably emailed to the winner, obviously I cant have the code sent out twice so I have a row called active, the code starts at 1 which is active and when it is sent out it is set to 0 inactive.

 

The codes are showing up fine but I need help setting the code to inactive, this is my first php project and I have little programming experience so I apologize if this seems quite a simple question 

 

So anyway here is my code for retrieving the code from the database

 

$results = $conn -> query('SELECT code FROM orders WHERE active = 1 LIMIT 1 SET active = 0');

 

so as you can see if takes a code from orders if the code is set as active, but the last lin SET active = 0 gives me the error

 

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET active = 0' at line 1' in C:\xampp\htdocs\Learning\0Casino\win.php:9 Stack trace: #0 C:\xampp\htdocs\Learning\0Casino\win.php(9): PDO->query('SELECT code FRO...') #1 {main} thrown inC:\xampp\htdocs\Learning\0Casino\win.php on line 9

 

 

Which I understand is due to poor syntax, can anyone tell me how to properly use the SET/ACTIVE properties?

 

Should I be doing this in another line or is it okay to have the code retrieved and deactivated on the same line?

 

Thanks in advance 

 

Luke

Link to comment
https://forums.phpfreaks.com/topic/275607-game-help/
Share on other sites

  • Solution

Hi guys I have fixed the problem, I made a new line under the above which is as follows

 

$conn -> query('UPDATE codes SET Available = 0 WHERE ItemID = ' . $conn->quote($id));

 

This UPDATES the codes table and SETS Available to 0 where the ItemID is equal to that of the product ID

 

I'm just working on a way to test if a code is Available or not 

Edited by Luke_Watson
Link to comment
https://forums.phpfreaks.com/topic/275607-game-help/#findComment-1418433
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.