Deusdies Posted October 24, 2010 Share Posted October 24, 2010 Howdy, Sorry for registering simply to ask a question. I know my way around PHP, but I don't know MySQL at all. So I have some affiliate-ready sites ready to go. The websites have a code in them that changes depending on the affiliates' needs. For example, in order for an affiliate to access the website with his code, he will type www.mysite.com/?id=affiliateID . The script will alter the links in the website based on the GET variable from the URL. Simple, yet efficient. However, since this will be a paid access, I would like to prevent abuse (if someone figures out the system, he won't have to pay - he could simply enter his code after ?id= and get the access to the sites other users paid to get). I've come up with the idea that every time a new user registers his affilaite ID is entered into the database. After that, every time someone access www.mysite.com/?id=affilaiteID a script will check if that specific affiliateID exists in the database. If it does, it will allow access to the site. If it doesn't, it will block access. So I'd like answers to two questions please: 1) How do I store a simple string from an input box from PHP to MySQL ? 2) How do I program the script to read the database and check if a string exists (like I mentioned above)? Thank you very much in advance! -Bo Quote Link to comment Share on other sites More sharing options...
optikalefx Posted October 24, 2010 Share Posted October 24, 2010 first, thats the wrong way to do it. example. 5 is stored in the database. I tell my friend mike to go enter 5. He didn't pay but he gets to see 5. You need a user login system, and then send the data with POST from an html form. But to answer you question: (assuming you have the mysql database and table and fields setup) // connect and insert mysql_connect($server,$user,$pass) or die("could not connect"); mysql_select_db($database) or die("could not select db); mysql_query("INSERT INTO aTable SET id = 'your string'"); // will echo true or false if the given id exists mysql_connect($server,$user,$pass) or die("could not connect"); mysql_select_db($database) or die("could not select db); $res = mysql_query("SELECT COUNT(*) as count FROM aTable WHERE id = '{$_GET['id']}'"); echo (bool) mysql_num_rows($res); *note this is not well formed code, and its not tested, its just to give you they syntax. Quote Link to comment Share on other sites More sharing options...
Deusdies Posted October 24, 2010 Author Share Posted October 24, 2010 Don't worry about the system not working. It is difficult to explain. Your friend Mike has no point in entering 5 because 5 belongs to someone else and all the commissions generated from promoting the website with code 5 will go to the account of the one who has affiliate code 5. If that makes any sense. But thanks a bunch for the code! That's exactly what I needed! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.