# Limiting user inputting records



## VividProfessional (Apr 29, 2009)

Hi all
I am in need of help. Again.

What I have is a plane logging system. Part of it, the non paid for area should limit the about of "spots" a user inputs into the system. These demo users are in a group called "GROUP 1". each user has a username in a variable called "$username" is it possible to check the database table in this case "spottings" to see how many records a user has . 

So that if "freddie" inputted 200 records it would be OK and allow him to input the record 
If he tried to input another record, aka his 201st record the website would redirect him to a page called suprem.php asking Freddie to contribute to the site to enable him to input more?

Thanks


----------



## brent.charlebois (May 8, 2007)

Hi Dave,

First, I would implement a form to collect the info you want to store in the database for each user and have the action in the form code set to your php file.

Then, use PHP/MySQL to INSERT the info collected to the database. Then SELECT from the database all rows it contains. Then implement PHP/MySQL to return the number of rows it has. Using PHP now, if the number of rows is 201, then "echo" the HTML to implement a way for your users to donate. I suggest you use Paypal which will collect donations in a secure manner. With Paypal the user can donate via direct withdrawal from their bank account or with credit card.

If you want the PHP/MySQL code to do all this I can provide it.


----------



## VividProfessional (Apr 29, 2009)

BrentC said:


> If you want the PHP/MySQL code to do all this I can provide it.


that would be extremely helpful thank you :smile:


----------



## brent.charlebois (May 8, 2007)

First of all, do you know how to connect to a MySQL database which you have created?


----------



## brent.charlebois (May 8, 2007)

Hi, 

Here is the first page:


```
<!DOCTYPE html>

<html>

<body>


<form action="dave.php" method="POST">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  Last name: <input type="text" name="limit"><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>
```


Now the second page in PHP:


```
<?php


$host="localhost";
$username="username";
$password="*******";
$db_name="databasename";

$con=mysqli_connect($host, $username, $password, $db_name);

// Check connection
if (mysqli_connect_errno())
  {
  die ("Failed to connect to MySQL: " . mysqli_connect_error());
  }

  $sql="SELECT * FROM $username";

$result = mysqli_query($con, $sql);
if (!$result) {
	mysqli_close($con);
	die('Error with SELECT From username: ' . mysqli_error());
	}

		$num_rows = mysqli_num_rows($result);
		$row = mysqli_fetch_array($result);
	if(($num_rows == 200) && !$row['limit']) {
	
			$sql = "INSERT INTO $username (firstname, lastname, limit)
			VALUES ('John', 'Doe','true')";
		$result = mysqli_query($con, $sql);
	
	echo '<div style="position:absolute; top:200px; left:47%; text-align:center; font-family:Arial, sans serif; font-size:24px;">
	We request that you make a donation as you are at 200 records saved.<br><br>
	<form  name="myform" action="dave2.html"  style="position:absolute; top:300px; left:47%;" />
		<input class="buttons" style="background-color:#3366FF; color:#ffffff;" type="submit" value="Payment" />
	</form></div>';
	} else {
		
		$sql = "INSERT INTO $username (firstname, lastname, limit)
		VALUES ('John', 'Doe','true')";
	$result = mysqli_query($con, $sql);
	if (!$result) {
		mysqli_close($con);
		die('Error INSERTing ' . mysqli_error());
		}
	}


mysqli_close($con);
?>
```

And a third:


```
<!DOCTYPE html>

<html>

<body>


<form style='margin-left:31%' action='https://www.paypal.com/cgi-bin/webscr' method='post' target='_top'>
<input type='hidden' name='cmd' value='_s-xclick'>
<input type='hidden' name='hosted_button_id' value='PAZ5G388TXWFL'>
<input type='image' src='https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif' width='31%' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>
<img alt='' border='0' src='https://www.paypalobjects.com/en_US/i/scr/pixel.gif' width='1' height='1'>
</form>

<br><br><br>

<form action="dave.html" method="get">
  <input type="submit" value="Homepage">
</form>

</body>
</html>
```

What you have to do is create a database with these:

$host="localhost";
$username="username";
$password="*******";
$db_name="databasename";

Fill in the value of $username, $db_name and password. You must create a table for each user with the same name as each user. There will only be one name for the database.

Adjust the form on the first page to input the info you want to save in the database for each user. You also create a password for each user.

You do all of this with PHPMyAdmin which is included with your Hosting Service.

I haven't tested this so good luck. Come back for further help.


----------

