Jump to content

PHP/MySQL problem (simple for those who know stuff)


Deusdies

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
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.