PDA

View Full Version : PHP and MYSQL programming


highnote
12-16-2013, 11:01 AM
Anyone here know how to program in PHP and MYSQL?

I have installed a database and some php code to access the database on my server, but there are some things I don't know how to do.

There needs to be a form that people can enter text into and then have their text saved to their database record. Then on the same page as the form the data they entered needs to be displayed on a different part of the page.

I have always thought it would be fun to create betting exchange software that could be used privately so that friends could bet with each other in private events. For example, maybe a group of friends is having a KY Derby party and want to bet on the race. What usually happens is that one person has a regular betting account and makes bets for all his or her friends. Then they have to settle up after race. Usually, there is a net loss and the account balance goes down.

It would be fun if one person could act as the bank and collect money from their friends and "deposit" the money into a meta-account. All the friends could then bet among themselves. Since the pools would be so small the odds would be skewed. However, if fixed odds wagering was available the odds could more accurately reflect track odds -- which would be more reasonable. Then at any point it would be easy for the banker to cash-out any of the account holders.

Any help or thoughtful comments appreciated.

DeltaLover
12-16-2013, 11:53 AM
php and mysql work very nice together. Usually they are also combined with linux and apache to the framework called LAMP.

There are tons of related tutorials. For starters try:

http://www.w3schools.com/php/php_mysql_intro.asp

highnote
12-16-2013, 02:15 PM
Thanks, Delta.

I bought some software called PHPMagic. I built a database, like in Access, and then clicked a button and all the php code was generated. Then I uploaded all the code to my website and voila... I've now got a functioning MySQL database on my website.

The hard part for me is customizing it to do exactly what I want it to do.

I program in VB so I will eventually figure it out, but it's always nice to find shortcuts!

php and mysql work very nice together. Usually they are also combined with linux and apache to the framework called LAMP.

There are tons of related tutorials. For starters try:

http://www.w3schools.com/php/php_mysql_intro.asp

highnote
12-16-2013, 03:04 PM
This is an excellent resource Delta. Thanks!

php and mysql work very nice together. Usually they are also combined with linux and apache to the framework called LAMP.

There are tons of related tutorials. For starters try:

http://www.w3schools.com/php/php_mysql_intro.asp

DeltaLover
12-16-2013, 03:26 PM
What you try to do is preety straightforward and you will have no trouble with php + mysql. I would also advice a shift from VB to javascript as a great direction change...

michiken
12-16-2013, 08:01 PM
I am not a programmer but managed to hack my way thru php to make my own bris import software.

The code below is something I wrote as an html wrapper. I found this easier to do all of my pages in php instead of flipping back and forth between html and php. Each function has comments to show what it does. Save the code below as html-wrapper.php


<?php
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// Usage: This contains some HTML wrapping functions to make it easier to program all webpages in pure PHP.
// This file is used as an include file for the executeable pages of this program.
// You should only manually edit this file if you fully understand PHP programming.
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// HTML Wrapping Functions for Tables:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
function tbs($_w,$_s) {
//Declares the start of a table.
echo "<table width=\"$_w\" summary=\"$_s\">\n";
}

function tbe() {
//Declares the end of a table.
echo "</table>\n";
}

function trs() {
//Declares the start of a table row.
echo "<tr>\n";
}

function tre() {
//Declares the end of a table row.
echo "</tr>\n";
}

function tds($_w,$_al,$_va,$_cs,$_cl) {
//Declares the start of a table division.
if (empty($_w)) {
echo "<td align=\"$_al\" valign=\"$_va\" colspan=\"$_cs\" class=\"$_cl\">\n";
} else {
echo "<td width=\"$_w\" align=\"$_al\" valign=\"$_va\" colspan=\"$_cs\" class=\"$_cl\">\n";
}
}

function tde() {
//Declares the end of a table division.
echo "</td>\n";
}

function ths($_w,$_al,$_va,$_cs,$_cl) {
//Declares the start of a table division.
echo "<th width=\"$_w\" align=\"$_al\" valign=\"$_va\" colspan=\"$_cs\" class=\"$_cl\">\n";
}

function the() {
//Declares the end of a table division.
echo "</th>\n";
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// HTML Wrapping Functions for Text Labels:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

function txn($_tx) {
//Used to echo NORMAL text to the screen
echo "$_tx\n";
}

function txb($_tx) {
//Used to echo BOLD text to the screen
echo "<b>$_tx</b>\n";
}

function txi($_tx) {
//Used to echo ITALIC text to the screen
echo "<i>$_tx</i>\n";
}

function txu($_tx) {
//Used to echo UNDERLINED text to the screen
echo "<u>$_tx</u>\n";
}

function txs($_tx) {
//Used to echo small text to the screen
echo "<small>$_tx</small>\n";
}


function h1($_tx) {
//Used to format H1 headings
echo "<h1>$_tx</h1>\n";
}

function h2($_tx) {
//Used to format H2 headings
echo "<h2>$_tx</h2>\n";
}

function h3($_tx) {
//Used to format H3 headings
echo "<h3>$_tx</h3>\n";
}

function h4($_tx) {
//Used to format H4 headings
echo "<h4>$_tx</h4>\n";
}

function h5($_tx) {
//Used to format H5 headings
echo "<h5>$_tx</h5>\n";
}

function hr() {
//Used to format H5 headings
echo "<hr>\n";
}

function nbsp() {
//Used to echo non breaking space
echo "&nbsp;";
}

function brk($_num) {
//Used to echo various amoung of line breaks
switch($_num){
case 1:
echo "<br>\n";
break;
case 2:
echo "<br><br>\n";
break;
case 3:
echo "<br><br><br>\n";
break;
default:
echo "<br>\n";
}
}

function uls() {
//Start Unordered List
echo "<ul>\n";
}

function ult($_tx) {
//List
echo "<li>$_tx</li>\n";
}

function ule() {
//End Unordered List
echo "</ul>\n";
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// HTML Wrapping Functions for User Input Forms:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

function forms($_method,$_action) {
//Start a Form
echo "<form method=\"$_method\" action=\"$_action\">\n";
}

function formm($_method,$_action) {
//Start a Multi Part Form for Uploading Files or Images
echo "<form enctype=\"multipart/form-data\" method=\"$_method\" action=\"$_action\">\n";
}

function forme() {
//End a form.
echo "</form>\n";
}

function inputb($_name,$_class,$_val) {
//Input Button
echo "<input type=\"submit\" name=\"$_name\" value=\"$_val\" class=\"$_class\">\n";
}

function inputc($_name,$_val) {
//Checkbox
echo "<input type=\"checkbox\" name=\"$_name\" value=\"$_val\">\n";
}

function inputf($_size,$_name,$_val) {
//File Input Form Box
echo "<input type=\"file\" size=\"$_size\" name=\"$_name\" value=\"$_val\">\n";
}

function inputh($_name,$_val) {
//Input Type Hidden
echo "<input type=\"hidden\" name=\"$_name\" value=\"$_val\">\n";
}

function inputp($_size,$_name,$_val) {
//Input Password Form
echo "<input type=\"password\" size=\"$_size\" name=\"$_name\" value=\"$_val\">\n";
}

function inputr($_name,$_val) {
//Radio Button
echo "<input type=\"radio\" name=\"$_name\" value=\"$_val\">\n";
}

function inputrc($_name,$_val) {
//Radio Button
echo "<input type=\"radio\" name=\"$_name\" checked value=\"$_val\">\n";
}

function inputt($_size,$_name,$_val) {
//Input Type Text Box
echo "<input type=\"text\" size=\"$_size\" name=\"$_name\" value=\"$_val\">\n";
}

function sbs($_name) {
//Select Box Start
echo "<select name=\"$_name\">\n";
}

function sbo($_val,$_display) {
//Select Box Option
echo "<option value=\"$_val\">$_display</option>\n";
}

function sbe() {
//Select Box End
echo "</select>\n";
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// HTML Wrapping Functions for Hyperlinks:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

function lnk($_url,$_class,$_tx) {
//Regular Hyperlink with Class Variable
echo "<a href=\"$_url\" class=\"$_class\">$_tx</a>\n";
}

function lnkb($_url,$_class,$_tx) {
//New Window Hyperlink with Class Variable
echo "<a target=\"_blank\" href=\"$_url\" class=\"$_class\">$_tx</a>\n";
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// Image Source Functions:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

function imgs($_img,$_width,$_height,$_alt,$_border) {
//Regular Hyperlink with Class Variable
echo "<img src=\"$_img\" width=\"$_width\" height=\"$_height\" alt=\"$_alt\" border=\"$_border\">\n";
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// HTML Start and End Web Page:
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

function htmlstart($_title) {
// This function is used as a header file to begin a web page.
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
echo "<html>\n";
echo "<head>\n";
echo "<title>$_title</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"termv.css\" media=\"screen\">\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"print.css\" media=\"print\">\n";
echo "</head>\n";
echo "<body>\n";
echo "<center>\n";
}


function htmlend() {
echo "</center>\n";
echo "</body>\n";
echo "</html>\n";
}

?>


Here is sample code that calls the html wrapper and shows a web form for users to use. Save this as wrapper-test.php

<?php
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
// Usage: This script displays the main html index home page.
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++
// Include Standard Files.
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++
include_once('html-wrapper.php');

// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++
// Start HTML Display
// ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++
htmlstart('Welcome to my Homepage');
// Start Index Page
tbs('800','HomePage');
trs();
tds('100%','left','top',1,'c3');
h1('This is H1 text.');
txn('This is normal text.');
brk(2);
txb('This is bold text.');
brk(2);
txu('This is underlined text.');
brk(2);
tde();
tre();
tbe();
htmlend();
?>


If you are running LAMP you can put these in your Apache Folder to see how they run by opening wrapper-test.php

Or you can just browse the code to learn.

Ken

DeltaLover
12-16-2013, 08:30 PM
what exactly you try to accomplish with this code?

highnote
12-16-2013, 08:36 PM
Thanks for posting your code! I can definitely learn from it!!

I am not a programmer but managed to hack my way thru php to make my own bris import software.

The code below is something I wrote as an html wrapper. .......
Ken

highnote
12-16-2013, 08:39 PM
what exactly you try to accomplish with this code?


Who -- me or mich?

Me -- I want to build freeware betting exchange software that can be used for small groups of people who want to bet among themselves.

Rather than have a "poker night", people might want to have a "racing night" -- or a Kentucky Derby or Breeders' Cup party. This could even work for a Super Bowl party.

It would be a lot of fun to offer odds on races to your friends -- and vice-versa.

To my knowledge there is no software that does this.

DeltaLover
12-16-2013, 08:49 PM
Who -- me or mich?

Me -- I want to build freeware betting exchange software that can be used for small groups of people who want to bet among themselves.

Rather than have a "poker night", people might want to have a "racing night" -- or a Kentucky Derby or Breeders' Cup party. This could even work for a Super Bowl party.

It would be a lot of fun to offer odds on races to your friends -- and vice-versa.

To my knowledge there is no software that does this.

My question was for mich since by going through his code it is not clear what he is doing.

Your idea about a betting software is interesting. It hides several interesting challenges though, that it will be fun to resolve as your discover them!

highnote
12-16-2013, 09:16 PM
Your idea about a betting software is interesting. It hides several interesting challenges though, that it will be fun to resolve as your discover them!


There are certainly a lot of challenges to writing software for a betting exchange -- or "Party Betting" as I am calling it.

It might even be fun to do it as an open source project?

I think it would be a lot of fun to lay odds on a horse and have a friend take the other side of the bet.

michiken
12-16-2013, 11:48 PM
what exactly you try to accomplish with this code?

I just found it easier to code entirely in php rather that mix it with html. The wrapper automatically writes the html for you for simplicity.

It also make all of the code modular so you can write small pieces and reuse them over and over thru includes.

DeltaLover
12-17-2013, 12:49 AM
I just found it easier to code entirely in php rather that mix it with html. The wrapper automatically writes the html for you for simplicity.

It also make all of the code modular so you can write small pieces and reuse them over and over thru includes.


PHP is a great language for server site scripting. Still, depending on the functionality of your site, you might have the need for a lot of javascript if you are going to interact a lot with the DOM. HTML5 presents a great client side programming model, that combined with javascript, CSS3 and DOM should minimize round trips making a page to behaving closely to a classical 'fat' desktop client.