button to pull from database

General discussions related to php

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 6
Joined: Wed Mar 07, 2012 9:49 pm

button to pull from database

Postby fgatlin » Fri Jun 29, 2012 5:13 am

I am in the process of creating a new points system on the company website.

Generally speaking, the customer will receive 1 point for every dollar spent.

I have a table setup with different products with different points needed to get the item.

I need to figure out how to have the button pull the points from the database (subtract it from the total in the database) and send me a message of the item wanted, and who sent it.

customer: John Doe
Item from button click (maybe use the button ID or button name?)
Sent to email.

Points subtracted from database leaving the remaining points there.

Any suggestions?

New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: button to pull from database

Postby kyle04 » Mon Jul 09, 2012 4:47 pm

You would need a form set up to post the variables to the script , very generally, assuming the customer has to input their data in some form (email address would be the most reliable) :

<form name="button20" method=POST action="this_script.php">
<input type=hidden name="points_value" value="20">
Enter Email : <input type=text name="customer_email" size=15>
<input type=submit name="submit_points" value="Submit">



foreach($_POST as $name=>$value) {
${$name} = $value;
// echo $name." - ".$value."<br>"; // for testing, commented out here


if(isset($_POST['submit_points'])) {

$result = mysql_query("SELECT FROM YOUR_TABLE_NAME WHERE FIELD_EMAIL = '$customer_email'");
$row = mysql_fetch_array($result);

if(!$result) {
echo "No records for ".$customer_email." found";
// error proceedure here

$stored_points = $row['FIELD_STORED_POINTS'];

if($points_value>$stored_points) { // not enough stored points for item
echo "The item points value exceeds your current points total";
echo "You currently have ".$stored_points." available";

exit; // or other options here


else { // update the table
$new_points_value = $stored_points-$points_value;

$update = mysql_query("UPDATE YOUR_TABLE_NAME SET FIELD_STORED_POINTS = '$new_points_value' WHERE FIELD_EMAIL = '$customer_email'");

// then do the email script here





Return to “PHP General”

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 1 guest