# PHP 7.1 question?



## daubydotson (Mar 18, 2018)

How do I run on my computer, a program I created (I have windows 10)?


----------



## cwwozniak (Nov 29, 2005)

If you wish to test web content that uses PHP, you can install and configure an Apache server with PHP support on your computer usig XAMPP.

https://www.apachefriends.org/index.html


----------



## JiminSA (Dec 15, 2011)

... You would then be able to run programs using a url similar to this:

```
http://localhost/my_project/my_program.php
```
Where my_project is the directory within the xaamp directory htdocs and my_program.php is obviously, the program you wish to run ...


----------



## dvk01 (Dec 14, 2002)

I think this relates to his previous abandoned post https://forums.techguy.org/threads/php-triad-unsupported-16-bit-application-i-have-64.1206934/


----------



## JiminSA (Dec 15, 2011)

Yes, and the OP doesn't appear to have opted for a choice - WAMP, XAAMP or DesktopServer - it's "Make your mind up time!"


----------



## JiminSA (Dec 15, 2011)

Maybe an explanation is in order ...
Because PHP is a server-side language, we need to emulate what a server does in order to run a PHP program. These three options each provide a server environment, to do this ...


----------



## daubydotson (Mar 18, 2018)

whats wrong with my code? here is the html syntax. trying to create a text file. do I have to create the txt file or does it get created automatically. I am new to php. this html file is called "loadrestauranthtml.html"

loadrestauranthtml

*restaurant​*
-----------------------------------------------------------------------------------------------------
this is my php code. I am trying to create a text file called RESTAURANTDATA.TXT.
is there an easier way to do this. this php is called "loadrestaurantphp.php"

loadrestaurantphp

*php load to file*
p
<? php
$fp = ""
$fp = fopen("restaurantdata.txt"; "w");
fclose($fp);
?>

-------------------------------------------------------------------
please help! thank you.
john

*< moderator removed email address >*


----------



## daubydotson (Mar 18, 2018)

thank you JiminSA. Your information was very helpful.
I now know php runs on a server. and also, after you upload your php program you are able to use url to point to the file you created. does that make sense. also, I created a php/html program and upload it to the server. it is suppose to have created a text db. once I create this txt file on the server, how to I read the file/database and view the file.
the program on the server does not run, and I don't know why. if you now PHP, can you help me with this simple (get my feet wet) program. I'm new to programming php.
thanks, John


----------



## JiminSA (Dec 15, 2011)

If you can give us a link to your program online, we can take a look. You might also post the source code, using the "Insert" icon in the "Post Reply" header ...


----------



## dvk01 (Dec 14, 2002)

@daubydotson 
you aren't making it easy to help you. Please make all your replies in this topic, not keep starting new ones all over the place.
I have merged all relevant posts into this one thread.
Now we can see exactly what the problem is, somebody can hopefully offer the correct advice to you.


----------



## JiminSA (Dec 15, 2011)

Okay, the reason why your txt file is not being created is because you are not doing a write - (presumably using data collected from the form).
At the moment you are using 2 separate pages to perform this - it would be more efficient to combine them as one HTML5 .php page. Thus:

```
<?php
if(!isset($_SESSION))
{
    session_start();
}
if(isset($_REQUEST['submit']))
{ 
    $fp = ""
    $fp = fopen("restaurantdata.txt"; "w") or die("Unable to open file!");
    if(isset($_REQUEST['john1']))
    {
        $data = $_REQUEST['john1'] . "\n";
        fwrite($fp, $data);
    }
    else
    {
       die('no post data to process');
    } 
    fclose($fp);
?>
<!DOCTYPE html>

load restaurant page

[B][SIZE=15][U][B]restaurant[/B][/U][/SIZE][/B]

">
```
I have taken out the tag, which is deprecated in HTML5 and put in required for your input field. I have also changed your POST to REQUEST, which also gathers url GET parameters ...​


----------



## colinsp (Sep 5, 2007)

Jim

You should not be using

```
$_SERVER['PHP_SELF']
```
 it is a security risk.

You should be using

```
<form method="post" enctype="multipart/form-data">
```


----------



## JiminSA (Dec 15, 2011)

Thanks for the headsup Colin Not that I doubted you, but I was curious as to how and discover that using it can make script vulnerable to *Cross Site Scripting* injection
So, @daubydotson, please use this revised script - omitting the action= parameter, will make the form default the action page to same page ...

```
<?php
if(!isset($_SESSION))
{
    session_start();
}
if(isset($_REQUEST['submit']))
{
    $fp = ""
    $fp = fopen("restaurantdata.txt"; "w") or die("Unable to open file!");
    if(isset($_REQUEST['john1']))
    {
        $data = $_REQUEST['john1'] . "\n";
        fwrite($fp, $data);
    }
    else
    {
       die('no post data to process');
    }
    fclose($fp);
?>
<!DOCTYPE html>

load restaurant page

[B][SIZE=15][U][B]restaurant[/B][/U][/SIZE][/B]
```
You may want to consider, using the append+ option on the write *(seehere)*


----------



## daubydotson (Mar 18, 2018)

JiminSA-I tried code but still not working. tell me what you need me to supply you with.

*reference this codeline 9)*

$fp = fopen("restaurantdata.txt"; "w") or die("Unable to open file!");

NOTE: restaurantdata.txt was created with notepad.
--------------------------------------------------------------------------
*error message:*
Parse error: syntax error, unexpected '$fp' (T_VARIABLE) in /homepages/21/d728606147/htdocs/
SeniorsNew/database3.php on line 9

*url address:*
seniors-out-and-about.com/database3.php
-or-
seniors-out-and-about.com/database3.htm
----------------------------------------------------------------------------
validation on access to db731443068.

seniors-out-and-about.com/connect.php

----------------------------------------------------------------------------
*questions:*
1) does the php code go inbetween the tags?
2) the database file was created in notepad as '
restaurantdata.txt' and uploaded to the server.(1and1.com)
no records are in it.
3) using the create database in 1and1 control panel, I 
created a database file called: db731443068 but, I don't 
know how to reference it or to save data to it. what 
should I do?
----------------------------------------------------------------------------
please help. thank you
john
[daubydotson]


----------



## dvk01 (Dec 14, 2002)

How many times do we have to tell you
stop making new topics and reply to the original topic.
Moved this one as well!


----------



## colinsp (Sep 5, 2007)

All lines in php must end with a ; and one is missing from this line

```
$fp = ""
```


----------



## daubydotson (Mar 18, 2018)

@dvk01 : I'm sorry about my confusion. I was confused and thought any new question needed a new thread. I will post any more questions I have on this website/database project here. How do I change the title and edit the first post to better reflect the content, since obviously my questions aren't just about PHP? I can't seem to find an edit option. (My daughter helped clear things up for me but she can't find the edit feature either.)


----------



## dvk01 (Dec 14, 2002)

Don't worry about changing the subject, just continue with everything here.


----------



## JiminSA (Dec 15, 2011)

Nice spot Colin
Sorry @daubydotson - my bad this line should read:

```
$fp = "";
```


----------



## daubydotson (Mar 18, 2018)

```
<?php
if(!isset($_SESSION))
{
    session_start();
}
if(isset($_REQUEST['submit']))
{
    $fp = "";
    $fp = fopen("restaurantdata.txt"; "w") or die("Unable to open file!");
    if(isset($_REQUEST['john1']))
    {
        $data = $_REQUEST['john1'] . "\n";
        fwrite($fp, $data);
    }
    else
    {
       die('no post data to process');
    }
    fclose($fp);
?>
<!DOCTYPE html>
<html>
<head>
<title>load restaurant page</title>
</head>
<body>
<h1><u><b>restaurant</b></u></h1>
<br>
<br>
<form method="post" enctype="multipart/form-data">
<input type = "text" name = "john1" value = "" size = "20" required />
<br>
<br>
<input type = "submit" value = "submit">
<input type = "reset" value = "reset">
</form>
</body>
</html>
```
here is my code


----------



## JiminSA (Dec 15, 2011)

The reason for the syntax error is this line:

```
$fp = fopen("restaurantdata.txt"; "w") or die("Unable to open file!");
```
it should read:

```
$fp = fopen("restaurantdata.txt", "w") or die("Unable to open file!");
```
 (Notice the ; has been replaced with a ,)
At this point you seem to be wanting to run before you've learned to walk, by having set up (presumably) an sql database table. Please let me explain that the .txt file you are creating in your code has nothing to do with the sql database you have set up, which requires an entirely different method of coding - _*see here *_- this is the initial connection methodology as explained by w3schools and there following are a number of tutorials, which show you how to manage your data ... this tut also finishes with some Create Database code, which is useful to know, but is irrelevant as you created it via the control panel of your host.


----------



## colinsp (Sep 5, 2007)

That tutorial on W3schools is not the best. Do not use MySQLi (it will be deprecated in the not too distant future) concentrate on learning PDO.


----------



## JiminSA (Dec 15, 2011)

If you look further down on that link, it gives you the PDO code, which as @colinsp has said, is a better alternative


----------



## daubydotson (Mar 18, 2018)

i was successful in creating a database with append attribute and there was also a read in the program. it works fine. however, I am unable to create another program referencing the same database. the program is a read-file. I am not sure if there is a permission to the file problem or is my code the cause. Here's the code, maybe some one can help troubleshoot


----------



## JiminSA (Dec 15, 2011)

How are you running this bit of code - locally or online (hopefully, with a .php extension)?
If the latter, please send us a link.
What response do you get when you run it?
You should be getting a php error on line 10, as $counter is not initialised ...


----------



## colinsp (Sep 5, 2007)

Please post code in code tags not as attachments. The code tags are accessed by clicking the icon to the left of the disk icon in the toolbar.


----------



## daubydotson (Mar 18, 2018)

thanks JiminSA, I initialized it and added a while eof to display all records in file. works great. I have another question. I'm trying to create an online-shop store for the residents of our community. I'm using javascript. for calculating total prices. My calculations are not working.
even my old javascript program with calc is not working.
can't assign values. can't place in fields. and more. others work fine. like alerts, comparisons, variables, etc..
also, can i have html, javascript, and php in one program?
here is the code. hope someone can help. 

```
<html>
<head>
<title>store items</title>
</head>

<script language="JavaScript">
<!--  type="text/javascript"> -->


function calculate(){

var boxx1 = 10.00;
var boxx2 = .20;
var boxx3 = 1.00;
var boxx4 = 2.00;
var boxx5 = 7.00;
var boxx6 = 1.00;

var qty1 = 0;
var qty2 = 0;
var qty3 = 0;
var qty4 = 0;
var qty5 = 0;
var qty6 = 0;

var price1 = 0;
var price2 = 0;
var price3 = 0;
var price4 = 0;
var price5 = 0;
var price6 = 0;

var total = 0;


<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(document.form1.qty1.value > 0){
document.form1.price1.value = (qty1 * boxx1);
}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(qty2 > 0){
    price2 = (qty2 * boxx2);

}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(qty3 > 0){
    price3 = qty3 * boxx3;
}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(qty4 > 0){
    price4 = qty4 * boxx4;
}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(qty5 > 0){
    price5 = qty5 * boxx5;
}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
if(qty6 > 0){
    price6 = qty6 * boxx6;
}

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->


total += price1 + price2 + price3 + price4 + price5 + price6;

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
}

</script>

<body>

<A href="" onclick="alert('thank you')">click me</a>



<!-- <form name="form1" method="post" action="connect46.php" enctype="multipart/form-data"> -->
<form name="form1" method="post" enctype="text/plain">
<u><center><font face="calibri" size=7>Seniors Out and about</font></center></u>
<u><center><font face="calibri" size=7 color="blue">Store Front</font></center></u>
<br>
<b><u><font face="calibri" font size=5>Personalized Items:</font></u></b>
<br>
<!--
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="small">small</font></b>
&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="medium">medium</font></b>
&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio checked name=size value="large">large</font></b>
&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="xlarge">xlarge</font></b>
&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="xxlarge">xxlarge</font></b><br>
-->
<table border=0>
<tr><td></td><TD>QTY</TD><td></td><TD></TD><td>PRICE</td></tr>
<TR><TD>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box1>T-Shirts</font></b>&nbsp;&nbsp;($10.00 ea.)</TD><TD><input type=text name=qty1 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T-Shirt:&nbsp;</td><td></td><td><input type=text name=price1 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="small">small</font></b>&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="medium">medium</font></b>&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio checked name=size value="large">large</font></b>&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="xlarge">xlarge</font></b>&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=radio name=size value="xxlarge">xxlarge</font></b></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box2>Pens</font></b>&nbsp;&nbsp;($.20 ea.).....................................................................................</td><TD><input type=text name=qty2 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pen:&nbsp;</td><td></td><td><input type=text name=price2 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box3>Rulers</font></b>&nbsp;&nbsp;($1.00 ea.)................................................................................</td><TD><input type=text name=qty3 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ruler:&nbsp;</td><td></td><td><input type=text name=price3 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box4>Coasters</font></b>&nbsp;&nbsp;($2.00 ea.)............................................................................</td><TD><input type=text name=qty4 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Coaster:&nbsp;</td><td></td><td><input type=text name=price4 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box5>Mugs</font></b>&nbsp;&nbsp;($7.00 ea.)..................................................................................</td><TD><input type=text name=qty5 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mug:&nbsp;</td><td></td><td><input type=text name=price5 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<b><font face="calibri" font size=4><input type=checkbox name=box6>Letter Openers</font></b>&nbsp;&nbsp;($1.00 ea.)................................................................</td><TD><input type=text name=qty6 size=2 maxlength=2></TD><td><font face="calibri" font size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Letter Opener:&nbsp;</td><td></td><td><input type=text name=price6 value=0 size=5 maxlength=5></font></b></td></tr>
<tr><td></td><TD></td><td></td><td></td><td>_______</td></tr>
<tr><td></td><TD></td><td></td><td></td><td>TOTAL<input type=text name=total style="background:yellow; font = family:arial" size=6 maxlength=6>&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value="Compute" onclick="calculate()"></td></tr>
</table>

<b><font face="calibri" font size=4>Name:&nbsp;<input type=text name=name1 size=35 maxlength=35></font></b><br>
<b><font face="calibri" font size=4>Phone Number:&nbsp;<input type=text name=phone size=15 maxlength=15></font></b><br>
<b><font face="calibri" font size=4>Email:&nbsp;<input type=text name=email1 size=15 maxlength=15></font></b>
<br>
<b><font face="calibri" font size=4>Would you like a call back?</font></b>
<b><font face="calibri" font size=4><input type=radio checked name=callback value="yes">yes</font></b>
<b><font face="calibri" font size=4><input type=radio name=callback  value="no">no</font></b>
<br>
<b><u><font face="calibri" font size=5 color="RED">Cash only accepted</font></u></b><br>
<br>
<input type="submit" value="submit">
<input type="reset" value="reset">
<span style='font-size:12.0pt'></b><input type="button" value="close" onclick="window.close();"/>
<br>
<br>
<br>
<br>

</form>

</body>
</html>
```


----------



## colinsp (Sep 5, 2007)

Yes you can have all three in one page of code.

IMHO you would be better off using php for your calculation rather than js.

You should avoid capitalisation of tags in your code and use all lower case for example

```
<A href=""
```
 should be

```
<a href=""
```
. The way the code is written has lots of duplication which is unnecessary, uses tables for layout which is not what they are intended for and looks like you are using some sort of wysiwyg editor, you will be better served by using a proper editor.


----------



## JiminSA (Dec 15, 2011)

I do not pretend to "know" javascript, but 2 things strike me:
1) your document.form identifiers occur for the first instance only.
2) your function "calculate" does not appear to be invoked (by an onclick e.g.) at any place within your html.


----------



## daubydotson (Mar 18, 2018)

thanks Colinsp
I use the windows Notepad and save my work as HTML. I find it beyond my scope to create a php file that can print to input boxes and do calculations.
thanks JiminSA,
I was just throwing things out there to see what works. I don't know php enough to write code in HTML with php calculating and displaying in a text box.

I am trying. eventually I'll get it. I just need one input box working.
thanks, DA


----------



## colinsp (Sep 5, 2007)

This is an example from something I wrote recently


```
Enter number

<?php
if (isset($_POST['convert']) ){
//do processing here like your calculations
?>
```


----------



## JiminSA (Dec 15, 2011)

Or, if you want to stick to javascript ...

```
<!doctype html>

store items

[URL]click me[/URL]



[U][CENTER]Seniors Out and about[/CENTER][/U]
[U][CENTER]Store Front[/CENTER][/U]

[B][U]Personalized Items:[/U][/B]


[TABLE]
[TR][TD][/TD][TD]QTY[/TD][TD][/TD][TD][/TD][TD]COST[/TD][/TR]
[TR][TD]    [B]T-Shirts[/B]  ($10.00 ea.)[/TD][TD][/TD][TD]            T-Shirt: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD]                [B]small[/B]  [B]medium[/B]  [B]large[/B]  [B]xlarge[/B]  [B]xxlarge[/B][/TD][/TR]

[TR][TD]    [B]Pens[/B]  ($.20 ea.).....................................................................................[/TD][TD][/TD][TD]            Pen: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD]    [B]Rulers[/B]  ($1.00 ea.)................................................................................[/TD][TD][/TD][TD]            Ruler: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD]    [B]Coasters[/B]  ($2.00 ea.)............................................................................[/TD][TD][/TD][TD]            Coaster: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD]    [B]Mugs[/B]  ($7.00 ea.)..................................................................................[/TD][TD][/TD][TD]            Mug: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD]    [B]Letter Openers[/B]  ($1.00 ea.)................................................................[/TD][TD][/TD][TD]            Letter Opener: [/TD][TD][/TD][TD]$[/B][/TD][/TR]
[TR][TD][/TD][TD][/TD][TD][/TD][TD][/TD][TD]_______[/TD][/TR]
[TR][TD][/TD][TD][/TD][TD][/TD][TD][/TD][TD]TOTAL $    [/TD][/TR]
[/TABLE]

[B]Name: [/B]
[B]Phone Number: [/B]
[B]Email: [/B]

[B]Would you like a call back?[/B]
[B]yes[/B]
[B]no[/B]

[B][U]Cash only accepted[/U][/B]

[/B]
```
My apologies, I did not see your Compute button, first time round!
The basic problem was that you were not placing your calculated variables into the form elements, which is what this code does.


----------



## daubydotson (Mar 18, 2018)

I can't get my php program to add a date next to a name field in my .txt database. Can someone help out?


----------



## daubydotson (Mar 18, 2018)

```
<?
$datafrom = $_REQUEST['rest1'] . "\n";
$filename = "data54db.txt";
$datex = (date('g:i a l F j'));

//print(date("h:i A 1 F dS, Y"));

if(!($myfile = fopen($filename, "a")))
{
  print("error: ");
  print("'$filename' could not be created\n");
  exit;
}

fputs($myfile, $datafrom);
//fputs($myfile, $datafrom . $datex);
//fputs($myfile, $datex);

fclose($myfile);
if(!($myfile = fopen($filename, "r")))
{
   print("error:");
   print("'$filename' could not be read\n");
   print("next line\n");
   exit;
}
while(!feof($myfile))
{
   $myline = fgets($myfile, 350);

if($counter == 0)
{
$counter = 1;
$color="blue";
$restsug="Restaurant Suggestions";
print("
[B][SIZE=15]$restsug[/SIZE][/B]
");
print("

\n");
//print(date("h:i A 1 F dS, Y"));
print("
\n");
}
print("$myline 
\n");
//print date('g:i a l F j');
}
fclose($myfile);
print("
\n");

?>
Thank you! your suggestion has been sent.
```


----------



## colinsp (Sep 5, 2007)

Your code is a bit odd and I am having difficulty understanding it. You do not seem to be reading the date from your txt file and you seem to be storing it twice.

One thing is that you should NOT use the shortcode opening of php you should always use


```
<?php
```


----------



## JiminSA (Dec 15, 2011)

daubydotson said:


> I can't get my php program to add a date next to a name field in my .txt database. Can someone help out?


I'd like to see a screenshot of your results if poss? Seems that you are thinking of 2 options for storing the date - appended to the form data or as a record following the form data - this from your commented out lines:

```
//fputs($myfile, $datafrom . $datex);
//fputs($myfile, $datex);
```
Uncomment one of these lines and you will store your date (don't forget to comment out the original fputs if you are using the append option)


----------



## daubydotson (Mar 18, 2018)

thank you for your help. I am trying to print and store $dataform (rest1) and $datex, next to each : other both on screen and in .txt file. I want to place both into $myfile, then be able to print $myline. I was trying to concatenate the two. Now I can either save & print the $dataform or $datex but not both. 
example: abc pizza (date and time) or
abc pizza
(date and time)

```
<html>
<head>
<title>RESTAURANTS</title>
</head>

<body lang=EN-US style='tab-interval:.5in'>

<!--<a href="SENIORS-OUT-and-ABOUT.htm"><img src="home.gif" align=right></a>-->

<center><font face="arial" size=6>Restaurants</font></center>

<center><FONT FACE="ARIAL" SIZE=4>Listing of Restaurants Visited</font></center>

<script language="JavaScript"  type="text/javascript">


function LinkBanner(){
    document.location.href =     
      "http://www." + BannerLink[CurrentBanner]
  }

<!-- *************************************************************** -->

function DisplayBanners(){
    if (document.images){
      CurrentBanner++
      if(CurrentBanner == NumOfBanners){   
        CurrentBanner = 0
      }
      document.RotateBanner.src = Banners[CurrentBanner]
      setTimeout("DisplayBanners()", 10000)
    }
  }

<!-- *************************************************************** -->

function Important_Fun_Links(Choice){
      
       Page=Choice.options[Choice.selectedIndex].value;
    if(Page != ""){
        window.location=Page;
        <!--location.href=scroll_variable;-->
    }
}   

</script>

<!-- *************************************************************** -->

<body lang=EN-US style='tab-interval:.5in'
onload="DisplayBanners()"
onload="document.Form1.linkscroll.selectedIndex=0"
onunload="document.forms[0], reset()">
<!-- onunload="document.forms[0], reset()"> -->

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
<!--<a href="SENIORS OUT AND ABOUT.htm"><img src="home.gif" align=right></a>-->

<TABLE>
<TR>

<TD colspan=2>

<select name="linkscroll" size="20" onchange="Important_Fun_Links(this)">
<option value=""></option>
<option value=""><b><u>--RESTAURANTS VISITED--</u></b></option>
<option value="&nbsp;">&nbsp;</option>
<!--<option value=""></option>-->
<FONT SIZE="2">
<!--<option value="cody.htm">Cody's Roadhouse</option>-->
<option value="longhorn.htm">Longhorn</option>
<option value="ballyhoos_grill.htm">BallyHoos Grill</option>
<option value="CRACKER BARREL.HTM">Cracker Barrel</option>
<option value="culvers.htm">Culver's</option>
<option value="olive garden.htm">Olive Garden</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="&nbsp;">&nbsp;</option>
<option value=""><b><u>--FAST FOODS--</u></B></option>
</font>
<FONT SIZE="2">
<option value="">new restaurant</option>
<option value="">new restaurant</option>
<option value="">new restaurant</option>
</FONT>
<option value=""></option>



<td VALIGN=MIDDLE>
<form name="form1" method="post" action="connect400.php" enctype="multipart/form-data">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<font face="calibri" font size=5><u>What Restaurant would you like to visit?</u></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b><font face="calibri" font size=3><input type="text" name="rest1" size=35 maxlength=35 required/></font></b>
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="submit"><input type="reset" value="reset">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style='font-size:12.0pt'></b><input type="button" value="close" onclick="window.close();"/>
</td>

<td><img src="waiter5.gif"></TD>
<td></td>

</select>


</TD>
</tr>
</table>
<br>

<div>

<button type="button"
    onclick="history.back();">Go Back</button>
<button type="button"
    onclick="history.forward();">Go Forward</button>

</div>


<!-- xxxxxxxxxxxxxxx
<?
$datafrom = $_REQUEST["rest1"] . "\n";
$filename = "data50db.txt";
if(!($myfile = fopen($filename, "a")))
{
  print("error: ");
  print("'$filename' could not be created\n");
  exit;
}

fputs($myfile, $datafrom);


fclose($myfile);
if(!($myfile = fopen($filename, "r")))
{
   print("error:");
   print("'$filename' could not be read\n");
   print("next line\n");
   exit;
}
while(!feof($myfile))
{

   $myline = fgets($myfile, 255);
<br>
print("$myline");

}
  
?>
xxxxxxxxxxxxxxxxxxxxxxx -->

<br>
<br>
<!-- <img src="m_logo.bmp" align=left> -->
</form>
</body>
</html>
```


----------



## JiminSA (Dec 15, 2011)

A word to the wise @daubydotson , tables should not be used for layout, rather use the more flexible method - css. *Check that advice out here ...*
I have rewritten your html and php script, using 'bootstrap' css - _*Check it out here *_this also provides the added advantage of being "Mobile Friendly" - very important nowadays

```
<!DOCTYPE html>
<?php
    if(!isset($_SESSION))
    {
        session_start();
    }

    if(isset($_REQUEST["rest1"]))
    {
        $datafrom = $_REQUEST['rest1'];
        $filename = "data50db.txt";
        $datex = (date('g:i a l F j'));

        //print(date("h:i A 1 F dS, Y"));

        if(!($myfile = fopen($filename, "a")))
        {
          print("error: ");
          print("'$filename' could not be created\n");
          exit;
        }

        $text = $datafrom." - ".$datex."\n";
        fputs($myfile, $text);
        //fputs($myfile, $datafrom."\n");
        //fputs($myfile, $datex."\n");

        fclose($myfile);
        if(!($myfile = fopen($filename, "r")))
        {
           print("error:");
           print("'$filename' could not be read\n");
           print("next line\n");
           exit;
        }
        $counter = 0;
        while(!feof($myfile))
        {
            $counter += 1;
            $myline = fgets($myfile);
            if($counter == 1)
            {
                $color="blue";
                $restsug="";
                print("
[B][SIZE=15]Restaurant Suggestions[/SIZE][/B]
");
                print("

\n");
                //print(date("h:i A 1 F dS, Y"));
                print("
\n");
            }
            // EOF reached?
            if(!$myline == "")
            {
                print("
[B][SIZE=15]$counter. $myline 
[/SIZE][/B]
");
            }
            //print date('g:i a l F j');
        }
        fclose($myfile);
        print("
\n");
    }
?>

    RESTAURANTS

    

    

    

    [CENTER]Restaurants[/CENTER]

    [CENTER]Listing of Restaurants Visited[/CENTER]






                    [B][U]--RESTAURANTS VISITED--[/U][/B]
                     
                    

                        
                        Longhorn
                        BallyHoos Grill
                        Cracker Barrel
                        Culver's
                        Olive Garden
                         
                        [B][U]--FAST FOODS--[/U][/B]

                        new restaurant
                        new restaurant
                        new restaurant

                Go Back
                Go Forward

                    [U]What Restaurant would you like to visit?[/U]

                    [B][/B]
                    [IMG]waiter5.gif[/IMG]

                    [/B]
```
As you can see from these lines:

```

```
I downloaded the file "bootstrap.css" and put it in a 'css' folder within an 'assets' folder in the website hierarchy - that's not mandatory (just the way I roll) - you can put it where you like - e.g. the root folder

```

```
The important part is to have it and *this is where you can get it* (and it's associated Javascript files)
In rewriting your script, I followed some guidelines, which I know will benefit you in the future - viz:

Indent your code for better readability.
Do not CAPITALISE html tags
Use the HTML5 DOCTYPE
Any further questions, please feel free to ask away 
Oh! I almost forgot The reason why the php was not actioned, was twofold - your form was not being actioned on the same page and even if it were you effectively commented it out by using these lines:

```

```


----------



## daubydotson (Mar 18, 2018)

Thank you for your help JiminSA. I had to separate the php from the htm code so that I could get the next screen page with the names and date and also the thank you message. I didn't use a var for the date. my mistake. the code you gave me would write on the input page, but it would push the input fields down the screen(page). Otherwise it was perfect. thank you again. I learn every day.

The people in our community have a lotto pool going on in Florida. We purchase 40 or more tickets. They want me to create a lotto ticket checker program. I told them I would see if I can. I didn't realize it would be that hard. I wasn't sure what path to take in coding. Do I use php or html? or both? What is the easiest and least code? Do I use case, while, do, ifelse, array or other? The books I have didn't help. I thought htm using javascript array would work. No luck. Not enough knowledge for me. Can you or someone enlighten me on what path to take. I understand there would be a lot of code, so all I ask is if someone has an idea about what to use. Not sure about bootstrap. over my head. Also, how to bring up fields from a database and place them into a form for storing numbers and then calc. hope the code I'm sending is readable. thanks again!

```
<!doctype html>

Florida Lotto Check Program



[U][CENTER]Florida Lotto-Check Program[/CENTER][/U]

[CENTER]Drawing Date: ____/____/____[/CENTER]

[CENTER]Winning Numbers[/CENTER]

[CENTER][B][/B]  
[B][/B]  
[B][/B]  
[B][/B]  
[B][/B]  
[B][/B]  
[/CENTER]

[CENTER][/CENTER]

                        [U]Ticket Numbers[/U]
        
        
        
        
[U]Total Correct NBRs[/U]
        
           
 [U]Initials[/U]
        
        
[U]Payouts[/U]

 1)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ A1_    

 2)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ B1_            6 numbers $3.5 million

 3)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ C1_            5 numbers $1,500

 4)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ D1_            4 numbers $500

 5)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ E1_            3 numbers $5

 6)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ F1_   

 7)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ G1_   

 8)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ H1_   

 9)   
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ I1_   

10)  
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ J1_   

11)  
 
 
 
 
 
  _ _ _ _ _ _ _ _ _      
  _ _ _ _ _ _ _ _ _ A2_   




Go Back
Go Forward
```


----------



## JiminSA (Dec 15, 2011)

daubydotson said:


> Thank you for your help JiminSA. I had to separate the php from the htm code so that I could get the next screen page with the names and date and also the thank you message. I didn't use a var for the date. my mistake. the code you gave me would write on the input page, but it would push the input fields down the screen(page). Otherwise it was perfect. thank you again. I learn every day.


I'm not quite sure what you mean when you say you "had to separate the php from the htm code"?
The pushing down effect can be eradicated, simply by re-positioning the PHP code after your last div - i.e. everything from <?php to ?>)
Never mind, you seem to have it sorted ...


----------



## JiminSA (Dec 15, 2011)

Regarding your Lotto project, perhaps you should have opened a new thread for it? Regardless, we'll carry on here ...
Personally, I would do it all using PHP, because my javascript is so poor and yes, you may well use case, while, do, ifelse, array as well as other instructions.
Don't throw 'Bootstrap' out the window - it's not rocket science and the more you get familiar with it the easier it becomes. It's just mobile-friendly css after all.
You are doing all your styling 'in-line' as opposed to using css (I'm curious, do you use a website builder platform or is your styling from a text book?).
If you use css, your HTML coding will be drastically reduced and IMO the easiest way to learn css is by using a pre-prepared template like 'Bootstrap'.
Using a database is a learning curve in it's own right, but unless you want to look back and see how members of your community fared in the past, I wouldn't bother - just do once-off checks on members' tickets (for now at least).
I would also just have one line of ticket entry displayed at a time, with the option to enter another line.

This project intrigues me and I haven't much on at the moment.
Given a little time, I could write something for it, which may point you in the right direction?
I could do so, if you would like


----------



## daubydotson (Mar 18, 2018)

Thank you, your help would be appreciated. I'm going to work on php code using array. The only thing I'm worried about is the screen format. All that I have seen so far with php is simple unformatted output. I just got some books from the library on php programming. Lets see what I can do. I'm going to look into css. See if I can reduce my code. I have PHP Editor. Got it free online. But, I think it is also a html editor. I'll check on that. Also, I use FileZilla for my ftp. No learning curve. I currently program using Notepad text editor for my HTML code. I save the program with an htm extension. 

I get ideas and syntax from older text books. Some from community college, others purchased at used book stores. I learned JavaScript from books and trial and error. I created my store front program using HTM, JavaScript and PHP code. I created my login program using javascript htm and case. Hard coded usernames and passwords, did not create a database. Took me a little time to create a txt database with your help. I tried first to create a MySQL database but I couldn't get it to work.Maybe because the database was not in my client directory. Not sure. I'd like to try again but, right now I'm fine. For my purposes a txt database works just fine.
Thanks again!


----------



## JiminSA (Dec 15, 2011)

I do hope you're not in rush. I should have some time to do something, over the weekend ...


----------



## JiminSA (Dec 15, 2011)

Well @daubydotson , I certainly kept myself entertained for a few hours, doing your site
It was actually more challenging than I thought You can see it working _*here*_ (I uploaded it to my site for you) and you're original page is _*here*_.
I have changed it somewhat (cosmetically) and am not doing things via javascript (I left the compute buton in there, but it does nothing), but via PHP and here is the script for the form page (test.php)...

```
<?php
if(!isset($_SESSION)) 
{ 
    session_start();
}
?>
<!DOCTYPE html>

    Florida Lotto Check Program



        [U][CENTER]Florida Lotto-Check Program[/CENTER][/U]

        [CENTER]
<?php
    if(!isset($_SESSION['draw_date']))
    {
?>   
            Draw Date: 
<?php
    }
    else
    {
?>           
            Draw Date: [B]<?=$_SESSION['draw_date']?>[/B]
<?php
    }
?>
        [/CENTER]

        [CENTER][B]Winning Numbers ...[/B][/CENTER]
<?php
    for($i = 1;$i <= 6;$i ++)
    {
        if(!isset($_SESSION['win'.$i]))
        {
            $_SESSION['win'.$i] = "";
        }
        if(isset($_SESSION['Number_'.$i]) && $_SESSION['Number_'.$i]) // A Win
        {
            switch ($i)
            {
                case 1:
                    $class1 = "mid glow";
                    break;
                case 2:
                    $class2 = "mid glow";
                    break;
                case 3:
                    $class3 = "mid glow";
                    break;
                case 4:
                    $class4 = "mid glow";
                    break;
                case 5:
                    $class5 = "mid glow";
                    break;
                case 6:
                    $class6 = "mid glow";
                    break;
            }
        }
        else
        {
            switch ($i)
            {
                case 1:
                    $class1 = "mid";
                    break;
                case 2:
                    $class2 = "mid";
                    break;
                case 3:
                    $class3 = "mid";
                    break;
                case 4:
                    $class4 = "mid";
                    break;
                case 5:
                    $class5 = "mid";
                    break;
                case 6:
                    $class6 = "mid";
                    break;
            }
        }
    }
    if(!isset($_SESSION['draw_date']))
    {
?>   
        [CENTER]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
        [/CENTER]
        [CENTER][/CENTER]

    [CENTER][/CENTER]
<?php
    }
    else
    {
?>   
        [CENTER]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
            [B]" maxlength=2 required>[/B]
        [/CENTER]

<?php
    }
?>

        [CENTER]
            [TABLE]
                [TR]
                    [TH]Ticket Owner's Initials[/TH]
                    [TH][CENTER]|------------- Ticket Numbers -------------|[/CENTER][/TH]
                    [TH]Total Correct Numbers[/TH]
                [/TR]
                [TR]
                    [TH][B]Previous Entries ...[/B][/TH]
                [/TR]
<?php
    if(!isset($entry_count))
    {
        $entry_count = 0;
    }

    If(isset($_SESSION['inits_array']))
    {
        foreach($_SESSION['inits_array'] as $initials) 
        {
            $num_array = explode("|", $_SESSION['number_value_array'][$entry_count]);
            $bucket = array_pop($num_array);

?>   
                [TR]
                    [TD]" required />[/TD]
<?php               
            $even = true;
            $i = 1;
            $win = false;
            $win_count = 0;
            foreach($num_array as $value) 
            {
                if($even) //Number
                {
                    $even = false;
                    switch ($i)
                    {
                        case 1:
                            $val_1 = $value;
                            break;
                        case 2:
                            $val_2 = $value;
                            break;
                        case 3:
                            $val_3 = $value;
                            break;
                        case 4:
                            $val_4 = $value;
                            break;
                        case 5:
                            $val_5 = $value;
                            break;
                        case 6:
                            $val_6 = $value;
                            break;
                    }
                }
                else // Boolean
                {
                    if($value) // A Win
                    {
                        $win = true;
                        $win_count ++;
                        switch ($i)
                        {
                            case 1:
                                $class1 = "mid glow";
                                break;
                            case 2:
                                $class2 = "mid glow";
                                break;
                            case 3:
                                $class3 = "mid glow";
                                break;
                            case 4:
                                $class4 = "mid glow";
                                break;
                            case 5:
                                $class5 = "mid glow";
                                break;
                            case 6:
                                $class6 = "mid glow";
                                break;
                        }
                    }
                    else // Non-winner
                    {
                        switch ($i)
                        {
                            case 1:
                                $class1 = "mid";
                                break;
                            case 2:
                                $class2 = "mid";
                                break;
                            case 3:
                                $class3 = "mid";
                                break;
                            case 4:
                                $class4 = "mid";
                                break;
                            case 5:
                                $class5 = "mid";
                                break;
                            case 6:
                                $class6 = "mid";
                                break;
                        }
                    }
                    $i ++;
                    $even = true;
                }
            }
?>       
                    [TD]" name="Number_1" type="text" id="Number_1" value="<?=$val_1?>" required />[/TD]
                    [TD]" name="Number_2" type="text" id="Number_2" value="<?=$val_2?>" required />[/TD]
                    [TD]" name="Number_3" type="text" id="Number_3" value="<?=$val_3?>" required />[/TD]
                    [TD]" name="Number_4" type="text" id="Number_4" value="<?=$val_4?>" required />[/TD]
                    [TD]" name="Number_5" type="text" id="Number_5" value="<?=$val_5?>" required />[/TD]
                    [TD]" name="Number_6" type="text" id="Number_6" value="<?=$val_6?>" required />[/TD]
<?php
            if($win)
            {
?>   
                    [TD][CENTER]" disabled />[/CENTER][/TD]
<?php
            }
            else
            {
?>
                    [TD][CENTER]" disabled />[/CENTER][/TD]
<?php
            }
            $entry_count ++;
        }
    }
?>
                [/TR]
                [TR]
                    [TH][B]New Entry ...[/B][/TH]
                [/TR]
                [TR]
                    [TD][CENTER][CENTER][/TD]
                    [TD][/TD]
                    [TD][/TD]
                    [TD][/TD]
                    [TD][/TD]
                    [TD][/TD]
                    [TD][/TD]
                [/TR]
                [TR]
                    [TD][CENTER][/CENTER][/TD]
                [/TR]
            [/TABLE]
        [/CENTER]

    [CENTER][URL=https://bespoke-webwork.com/][IMG alt="linkpic"]img/linkpic.jpg[/IMG][/URL][/CENTER]
```
 in addition I have done the form handling in a separate page (analyse.php)...

```
<?php
    if(!isset($_SESSION))
    {
        session_start();
    }
    if(isset($_REQUEST['winning_numbers']))
    {
        if(!isset($_SESSION['draw_date']))
        {
            $bucket = $_REQUEST['draw_date'];
            $bucket = strtotime($bucket);
            $format = "l jS F Y";
            $_SESSION['draw_date'] = date($format, $bucket);
        }
        $_SESSION['win_selected'] = true;
        $_SESSION['win_array'] = array();
        for($i = 1; $i <= 6 ;$i++)
        {
            $_SESSION['win'.$i] = $_REQUEST['win'.$i];
            $_SESSION['win_array'][$i-1] = $_SESSION['win'.$i];
        }
    }

    if(isset($_REQUEST['ticket_numbers']))
    {
        if(!isset($_SESSION['entries']))
        {
            $_SESSION['entries'] = 0;
        }
        $_SESSION['entries'] ++;
        $_SESSION['inits_array'][] = $_REQUEST['inits'];
        $number_value = "";
        for($i = 1; $i <= 6; $i++)
        {
            $number_value = $number_value.$_REQUEST['Number_'.$i]."|";
            if($_SESSION['win_array'][$i-1] == $_REQUEST['Number_'.$i])
            {
                $number_value = $number_value."1|"; // win = true
            }
            else
            {
                $number_value = $number_value."0|"; // win = false
            }
        }

        $_SESSION['number_value_array'][] = $number_value;
        $num_array = explode("|", $_SESSION['number_value_array'][0]);
        $bucket = array_pop($num_array);
        $even = true;
        foreach($num_array as &$value)
        {
            if($even)
            {
                echo "
 Number ".$value;
                $even = false;
            }
            else
            {
                echo "
 Boolean ".$value;
                $even = true;
            }
        }
    }
    header("Location: test.php");
?>
```
I sincerely hope that you can learn some useful things from this and if you have any questions, please ask away ...


----------



## JiminSA (Dec 15, 2011)

JiminSA said:


> A word to the wise @daubydotson , tables should not be used for layout, rather use the more flexible method - css. *Check that advice out here ...*


You've probably noticed that I seem to be contradicting myself, by using a table structure, but as it happens your layout is one of those rare ones that are best handled by tables. As you are not yet up to speed on css, I thought that I would go that route and use inline and on-page styling ...


----------



## daubydotson (Mar 18, 2018)

Thank you JiminSA. I wrote the compute portion of a lottery program I created in php. This program requires an input an data. It also needs screen appeal. It is nowhere near complete. I can't figure out the total number of matches per ticket. But now I don't need the program because I have yours. Thank you again. However I still would like to finish it. I made the code as short as I could and placed comments. If you could look at it, I would appreciate it.
I got a book that discusses CSS program code. Looks foreign to me but we will see.

I tried your program. Do I enter the tickets on the day I receive the winning numbers? Then hit submit. How many tickets can I place in the program. This is what I did:

So first, I entered the ticket numbers in the "New Entry". Then I select "Submit". I continue entering all the tickets. Then I put the winning ticket number in and press "Submit". Then on the right next to the ticket numbers, the total correct numbers appear.

I'm not sure I am doing it correctly. The total correct numbers stay at zero ("0"). I can't save the numbers. I tried the program from my email page. Please advise.

reference my php code.

```
<?php

$win[] = 22;
$win[] = 23;
$win[] = 30;
$win[] = 45;
$win[] = 50;
$win[] = 61;

$t = 0;
$i = 0;
$c = 0;

$ticket[] = 21;
$ticket[] = 24;
$ticket[] = 39;
$ticket[] = 40;
$ticket[] = 50;
$ticket[] = 61;

$ticket[] = 30;
$ticket[] = 31;
$ticket[] = 32;
$ticket[] = 33;
$ticket[] = 50;
$ticket[] = 51;

$ticket[] = 23;
$ticket[] = 43;
$ticket[] = 45;
$ticket[] = 46;
$ticket[] = 50;
$ticket[] = 51;

$ticket[] = 10;
$ticket[] = 20;
$ticket[] = 30;
$ticket[] = 40;
$ticket[] = 50;
$ticket[] = 60;

$tcount = 0;

while($t < 18) // total of ticket numbers (6 x 3 = 18)
{

       for($i = 0; $i < 6; $i++){  // scroll through winning numbers to check
         if($ticket[$t] == $win[$i]){  // check if ticket number and winning numbers match
          echo "Matched Numbers:     " . $ticket[$t] . "    and    " . $win[$i] . "<br>"; // show the winining matched numbers

         if($t == $i){
           $tcount = $tcount + 1; // count for first ticket only. need some help.
           }
          
         // ------------------ hard coding for easy reading. creates lines between matches. just for show.
           //if($t == 4 && $i == 4){
           //print("<hr>");
           //}
           //if($t == 10 && $i == 4){
           //print("<hr>");
           //}
           //if($t == 16 && $i == 4){
           //print("<hr>");
           //}
        // ------------------ hard coding for easy reading. creates lines between matches. just for show.
          //echo "-" . "i:" . $i . " and " . "t:" . $t . "<br>"; // show index of array
          }else{

          }
       }
       $t++;  // increment ticket in array
}
echo "<hr>";
echo "<br>";
echo "Winning Numbers--" . $win[0] . "-" . $win[1] . "-" . $win[2] . "-" . $win[3] . "-" . $win[4] . "-" .  $win[5] . "<br>"; // print out winning numbers for reference.
echo "<br>";
echo "<u>" . "Tickets" . "</u>" . "<br>";
echo $ticket[0] . "-" . $ticket[1] . "-" . $ticket[2] . "-" . $ticket[3] . "-" . $ticket[4] . "-" .  $ticket[5] . "     total correct: " . $tcount . "<br>"; // print tickets. needs count
echo $ticket[6] . "-" . $ticket[7] . "-" . $ticket[8] . "-" . $ticket[9] . "-" . $ticket[10] . "-" .  $ticket[11] . "     total correct: " . "<br>"; // print tickets. needs count
echo $ticket[12] . "-" . $ticket[13] . "-" . $ticket[14] . "-" . $ticket[15] . "-" . $ticket[16] . "-" .  $ticket[17] . "     total correct: " . "<br>"; // print tickets. needs count
echo $ticket[18] . "-" . $ticket[19] . "-" . $ticket[20] . "-" . $ticket[21] . "-" . $ticket[22] . "-" .  $ticket[23] . "     total correct: " . "<br>"; // print tickets. needs count
?>
```


----------



## JiminSA (Dec 15, 2011)

In my version, you first enter the Winning Numbers and submit them. Then you can start entering the tickets bought (ad infinitum), to see the results. I only recognise a winning number when the correct number is located in the correct column - is that how lotteries work? Perhaps I should recognise a winner regardless of the column it's in? Also, saving numbers - we would have to write them away to either a database or a file, something that wasn't previously mentioned and a whole new learning curve (which actually deserves a new thread)

I shall take a look at your new code later, given time.


----------



## JiminSA (Dec 15, 2011)

Your code ...
First off you have 4 (not 3) hard-coded submissions - so you need to check 24 tickets (not 18)
Change your code to loop through the entire submissions array and also to check all the winning tickets in one go, thus:

```
$wins = 0;
foreach($ticket as $ticket_no)
{
    if(in_array($ticket_no, $win)
    ( 
          echo "Matched Number:     " . $ticket_no . 
"; // show the winning matched number
          $wins ++;
    }
}     
         // ------------------ hard coding for easy reading. creates lines between matches. just for show.
           //if($t == 4 && $i == 4){
           //print("

");
           //}
           //if($t == 10 && $i == 4){
           //print("

");
           //}
           //if($t == 16 && $i == 4){
           //print("

");
           //}
        // ------------------ hard coding for easy reading. creates lines between matches. just for show.
          //echo "-" . "i:" . $i . " and " . "t:" . $t . "
"; // show index of array
```
The changes I made will affect the code which you commented out, but it also gives you a count of all the wins ($wins). So you will have to re-think, what you want to display ...
You may also want to change my code to check a ticket against all the winning tickets in one go using 'in_array'


----------



## daubydotson (Mar 18, 2018)

No. The way the lottery works is like this. Here is an example:
A person buys a ticket with the following numbers: 
10, 11, 40, 41, 43, 50
Next the day of the drawing, the following numbers are drawn(or picked):
20, 40, 45, 46, 50, 53
If the person has a match of 3 or more numbers they win some money. 6 numbers is the grand prize. The total winnings are divided among all the players. The odds are much better this way. The person in this example checks their ticket and has a match of two numbers. 40 and 50. They are not in the same column or order but they have a match. The first number of the winning numbers is checked against all of the numbers of the 1st ticket's numbers. and so on and so on. Hard to explain, but you get the idea.

I tried you program the way you said. It works. However, it works using columns like you said.

I tried the addition or changes to my lottery program that you made, but I get an error message on statement or code:
echo "matched number: " . $ticket_no . 
";
Not sure whats wrong. I never used foreach or in_array. I'll have to read up on it. The way that my program works is: The numbers that match are printed out on the screen for each ticket. But, they do not have a total number count per ticket. I can count the first ticket but not the others(cannot zero out or reinitialize). What I was going to do is, design the screen and create a database using php. My goal was to purchase the tickets way in advance. Then enter them into a database and save. On the day of the drawing I would enter the winning numbers and submit. Then the program would show all the numbers for each ticket and show the total number of matches. The number of tickets purchased is 40 or more. The program would show me the total matches per ticket very fast. If a ticket has 3 or more matches, it's a winner. This would save a lot of time. Plus, they could use the program themselves.

So, I will keep in touch. thanks daubydotson.​


----------



## JiminSA (Dec 15, 2011)

Okay my friend - have fun!


----------

