How to determine if a specified row is specified in a specific MySQL column? (as well as perhaps a training site?)

This is a pretty simple question. Basically, I have a program that sends a HardWare ID to my PHP script as GET data. I need to check the PHP script to make sure that the HardWare identifier is in a specific MySQL column, and if so, {continue the script,} else {exit (); }

The problem is that I'm not very good at MySQL and have no idea how to do this. However, I feel that I should know this so far, so if someone could also link me to a good training site for MySQL, this type keeps it β€œhumanized” if you know what I have in mind. One who is "dumb." I'm not stupid or something like that, I’m just easily distracted, and if all his actions show me the code and do not explain it, I won’t take it. If you do not have training sites from the top of my head, I agree to help with the first question and try to track the textbook later.

EDIT: It has been noted that this can help find out how my database is set up. I have a table called "hwids" This table has 3 columns: "id", "hwid" and "paypal"

(They buy from me a program, I add their HWID to the database so that they can use the program. If they return money and try to cheat, I can easily check which HWID is assigned to PayPal, which made the refund, and delete it from the system using the control page)

+4
source share
2 answers

When I started learning PHP / MySQL, I really liked the books that O'Reilly publishes on this subject. You can check Learning PHP, MySql and Javascript . The official sites for PHP and MySql provide a lot of good links and information, as well as documentation. Tizag has a useful tutorial.

To answer your question a bit, you can make a select query that checks if the number of rows found is greater than zero. i.e:.

$query = "SELECT * FROM hwids WHERE hwid = 'hardware_id'"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num > 0) { // continue script } else { // exit/inform user } 
+2
source

There are a number of steps that must be completed in order to achieve your goal, breaking them down, and studying each will help with your attention (without disrespect, I have the same problem)

The steps necessary to achieve your goal

  • Connect to MySql database - see mysql_connect and mysql_select_db documentation
  • Confirm your entry (make sure you have a valid hardware identifier)
  • Prepare the query - I would suggest something like $ Sql ​​= sprintf ("Select [columnName] from [tableName], where [columnName] =% s", mysql_escape_string ($ hardwareID));
  • return a recordset using mysql_query ($ sql) - see php.net documentation
    5.Check if it is empty mysql_num_rows (), if it exits the script

I hope that the resource that I would point you to will be http://tuxradar.com/practicalphp in particular, chapter 9

Everything, as others put it above, in fact, I typed a little slowly :)

+2
source

Source: https://habr.com/ru/post/1307692/


All Articles