Since this is only one customer, how can I carry this $total from the submit button to the next page for INSERT into database

punches page

<p>Is this the correct total of punches?</P>
<form action="run_punches.php" method="post" >

<?php
$small = $_REQUEST['smallamount'];
$medium = $_REQUEST['mediumamount'];
$large = $_REQUEST['largeamount'];
$total = $small + $medium + $large



?>
<input name="submit" type="submit" Value="Punchcard <?php echo $total; ?> times"/>
</form>
<form action="punchcard.php" method="post">
<input type="submit" value="No, take me back">
</form>

Example: Submit shows " Punchcard 2 times "
I want to click
then add to database

<?php
$small = $_REQUEST['smallamount'];
$medium = $_REQUEST['mediumamount'];
$large = $_REQUEST['largeamount'];
$total = $small + $medium + $large




$con = mysql_connect("localhost","user","password");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database_name", $con);

mysql_query("UPDATE punchcards SET smoothies = '$_REQUEST['$total']'
WHERE punchcard = 'punchcard' AND LastName = 'Griffin'");

echo "punches added";

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database_name", $con);;

$result = mysql_query("SELECT $punchcard FROM table_name");


while($row = mysql_fetch_array($result))
  { 
  echo "<td>" . $row['punches_recorded'] . "</td>";
  }
;

mysql_close($con);

Recommended Answers

All 13 Replies

You can use session variable or HTML HIDDEN ELEMENT

I'm logged into a user session can I start a punchcard session separately or on top of?
User session
Punchcard session
Then
End punchcard session
Start new punchcard session

At least being able to hold all the vars through every page and form, for every card.

would the Hidden HTML be better than the SESSION, since I am dealing with maybe 150 "sessions" of punchcards?

Member Avatar for diafol

Bit of a weird setup.

Use $_POST instead of $_REQUEST

Redirecting with a submit button seems a bit extreme - why not use a link or a button?
A submit button assumes that you are sending data.

Have you thought about using a js confirm box from the first page form (not shown)?
You seem to be duplicating.

commented: always helpful with new and useful advise +1

Use session.

I'm not able to carry the var

<?PHP
require_once("./include/file.php");

if(!$site->CheckLogin())
{
    $site->RedirectToURL("login.php");
    exit;
}

$punchcard = $_SESSION['punchcard'];
$oldpunches = $_SESSION['drinks'];
$punches = $_POST['punchesamount'];
$total = $punches + $oldpunches;
echo "Punching card'.$punches.'time/s";


$con = mysql_connect("localhost","user","pass");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

mysql_query("UPDATE punchcards SET drinks = '$total'
WHERE punchcard = '$punchcard'");

echo "</br>";


$result = mysql_query("SELECT $punchcard FROM punchcards");


while($row = mysql_fetch_array($result))
  { 
  echo "<td>" . $row['drinks'] . "</td>";
  }
;

mysql_close($con);


echo "You are now at'.$total.'";





?>

this doesn't add SESSION to new drink total = new total.

what am I missing?

how do you pull the session var to the next page, if i am doing it right how do I know I have it and then add it to a SELECT cell?

Bit of a weird setup.

Use $_POST instead of $_REQUEST

Redirecting with a submit button seems a bit extreme - why not use a link or a button?
A submit button assumes that you are sending data.

Have you thought about using a js confirm box from the first page form (not shown)?
You seem to be duplicating.

I changed the REQUEST's to POST's, I am guessing for privacy reasons?

next I need it to be simple as possible so submitting a punchcard#

then

to select how many drinks

then

add to how many drinks they had...

seems to be as simple as I can get it. I only want 1-2 options per page. KISS (Keep It Simple Stupid)

I don't want the "tap tap tap....wobbly" of ajax

in addition thanks for all your help!

Member Avatar for diafol

POST to stop url parameters or cookies being used in REQUEST.
I vaguely remember you posting something about this in a previous thread - the drinks thing.

You may find ajax useful for a 'at-the-end-submission' for an order.

What is wrong with this?

says there is white space in this array echo

echo "<input type=\"radio\" name=\"employee\" value=\"$row\[\'employee\'\]\"> . $row2['employee']";

POST to stop url parameters or cookies being used in REQUEST.
I vaguely remember you posting something about this in a previous thread - the drinks thing.

You may find ajax useful for a 'at-the-end-submission' for an order.

hey thanks, yeah drinks, and I will have to look up how to arrange the ajax for a grand finale.

I guess you are saying I could add all the results from the session vars in to the ajax?

would that be possible?

or am I lost in the sea?

Member Avatar for diafol

or am I lost in the sea?

ho ho

I don't think you're way off, just that the code looks a little too complicated for what you need:

You seem to have a two stage entry for drinks orders - perhaps you could combine that into one.

e.g.

PAGE ORDERS.PHP

<script>
js code to hijack the form submission with a confirm popup - if yes, proceed with ajax call, otherwise do nothing

you could include you ajax js code here if you wanted - the return value could be true or false - so you could provide an alert with a suitable message or have an updatable tag in/near the form to hold the message
</script>

<form>
here are your order buttons
along with submit button
</form>

PAGE UPDATE.PHP

get data from js ajax script usu. via POST
manipulate DB
echo "true" or "false" depending on success/failure

---------

Will guests punch in their own data or will a 3rd party (eg. barman) do that?

echo "<input type=\"radio\" name=\"employee\" value=\"$row\[\'employee\'\]\"> . $row2['employee']";

don't escape the single quotes and you must enclose array variables within {}:

echo "<input type=\"radio\" name=\"employee\" value=\"{$row['employee']}\" />" . $row2['employee'];
commented: more detail answers than any others at this point. Most appreciated! +1

ho ho

I don't think you're way off, just that the code looks a little too complicated for what you need:

You seem to have a two stage entry for drinks orders - perhaps you could combine that into one.

js code to hijack the form submission with a confirm popup - if yes, proceed with ajax call, otherwise do nothing

you could include you ajax js code here if you wanted - the return value could be true or false - so you could provide an alert with a suitable message or have an updatable tag in/near the form to hold the message

As I am learning php, I love the way ajax and js can help in the near furture. I think one page is the best way to go! Getting JScript to hande a change per text entry. Thanks again for the help and the syntax answer. As of right now I just trying to figure out every step page by page. Then I want to combine them.

$sql="INSERT INTO tablename (account, drinks, when, employee)
VALUES
('$account','$drinks', NOW(),'$employee')";

sql snytax error. I feel I have the same exact setup when adding a employee. Here I just want to add a record of the drinks that were added to "this" account and "this" employee NOW.

got it!

mysql_query("INSERT INTO `tablename`(`account`, `drink`, `when`, `employee`) 
VALUES ('$account','$drinks',NOW(),'$employee')");

So moving to jS I think!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.