category

database functions:

<?php
function db_connect()
{
//$result = mysql_connect(’localhost’, ‘listener’, ‘abc123′);
$result = mysql_connect(’localhost’, ‘root’, ”);
if (!$result)
return false;
if (!mysql_select_db(’betting’))
return false;

return $result;
}
?>

administratoruserdata.php:

<?php
require_once(’functions/dbFunctions.php’);

function checkmemberexists($sql)
{
$conn = db_connect();
if (!$conn)
return false;

$result = mysql_query($sql) or die(”<font color=’red’>Error fetching in registration</font><br>”.mysql_error());
$rowcount = mysql_num_rows($result);
return $rowcount;
}

function addmemberAccount($sql)
{
$conn = db_connect();
if (!$conn)
return false;

$alreadyTaken = “”;

//echo “sqlbetting: $sql<br>”;
return mysql_query($sql) or die(”error inserting member data: “.mysql_error());
}

class RecordSet
{
function addRecord($sql)
{
if(mysql_query($sql))
return true;
else
return false;
}

function updateRecord($sql)
{
if(mysql_query($sql))
return true;
else
return false;
}

function getRecord($s)
{
$result=mysql_query($s);
if ($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
return $row;
}
else
{
print (mysql_error());
}
}

function getRecordNum($sql)
{
$result=mysql_query($sql);
if ($row = mysql_fetch_row($result))
{
return $row;
echo $row;
}
else
{
print (mysql_error());
}

}

}
?>

addcategory:

<?php

//Buffet Start//
ob_start();
//Session Start//
session_start();
//Session Check//
include_once( “header.php”);

include (”checklogin.php”);

include(”conn.php”);
//Get values//
$form_catname = $_POST['catname'];
$date_created = date(”Y-m-d”);
//Select values//

if ( isset( $_POST['catname'] ))
{
$catname = $_POST['catname'];
$rsCheck = mysql_query(”Select * From betcat Where betcat_name like ‘$catname’”);

if (mysql_num_rows($rsCheck))
{
echo “<meta http-equiv=’refresh’ content=’3′>”;
?>
<script language=”javascript”>
alert(”Category Already exists”)
</script>
<?php

header(”Location: cat.php”);
exit;
}
else
{
$insQry = “Insert into betcat (betcat_name, betcat_createddate)
Values (’$catname’, ‘$date_created’)”;
mysql_query( $insQry );

header(”Location: cat.php”);
exit;
}
}
?>
<h3 align=”center”>Adding Category </h3>
<form name=”form1″ method=”post” action=”" onsubmit=’return checkform()’>
<div align=”center” style=”height:300px;”>
<table height=”100″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″>
<tr>
<td>Category Name: </td>
<td><input name=”catname” type=”text” id=”catname”></td>
</tr>
<tr>
<td colspan=”2″><center>
<input type=”submit” name=”Submit” value=”Add Category”>
</center>
</td>
</tr>
</table>
</div>
</form>
<script language=’javascript’>
function checkform()
{
var cat = document.getElementById(”catname”);

if (cat.value.length == 0)
{
alert(”Category cannot be blank”);
cat.focus();
return false;
}

}
</script>
<?php
include_once( “footer.php” );
?>

addcountry:

<?php

//Buffet Start//
ob_start();
//Session Start//
session_start();
//Session Check//
include_once( “header.php”);

include (”checklogin.php”);

include(”conn.php”);

$login = $_SESSION['adminid'];
//Get values//
$form_country = $_POST['country_name'];
$date_created = date(”Y-m-d”);
//Select values//

if ( isset( $_POST['country_name'] ))
{
$country_name = $_POST['country_name'];
$rsCheck = mysql_query(”Select * From country Where country_name = ‘$country_name’”);

if (mysql_num_rows($rsCheck))
{
$err = “Country Already exists”;
}
else
{
$insQry = “Insert into country (country_name, country_createdby, country_createddate, country_modifiedby, country_modifieddate)
Values (’$form_country’, ‘$login’, ‘$date_created’, ”, ”)” or die(’Query failed: ‘ . mysql_error());
echo $insQry;
mysql_query( $insQry );

header(”Location: countrylist.php”);
exit;
}
}
?>
<h3 align=”center”>Adding Country </h3>
<form name=”form1″ method=”post” action=”" onsubmit=’return checkform()’>
<div align=”center” style=”height:300px;”>
<table height=”100″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″>
<tr>
<td>Country Name: </td>
<td><input name=”country_name” type=”text” id=”country_name”></td>
</tr>
<tr>
<td colspan=”2″><center>
<input type=”submit” name=”Submit” value=”Add Country”>
</center>
</td>
</tr>
<tr>
<td colspan=”2″><center>
<?php echo  $err;
?>

</center>
</td>
</tr>
</table>
</div>
</form>
<script language=’javascript’>
function checkform()
{
var country = document.getElementById(”country_name”);

if (country.value.length == 0)
{
alert(”Enter the country name”);
country.focus();
return false;
}

}
</script>
<?php
include_once( “footer.php” );
?>

addstate:

<?php

//Buffet Start//
ob_start();
//Session Start//
session_start();
//Session Check//
include_once( “header.php”);
include (”checklogin.php”);
include(”conn.php”);
$login = $_SESSION['adminid'];

//Get values//
$country_id=$_POST['country'];
$statename=$_POST['statename'];

$date_created = date(”Y-m-d”);

//Select values//
if ( isset( $_POST['statename'] ))
{
$rsCheck = mysql_query(”select * from country_state where cs_name=’$statename’”) or die(”I cannot Select Because”.mysql_error());
if (mysql_num_rows($rsCheck))
{
$err = “State Already exists”;
}
else
{
$insQry = “Insert into country_state ( `country_id`, `cs_id`,`cs_name`, `cs_createdby` , `cs_createddate` , `cs_modifiedby` , `cs_modifieddate` )
Values (’$country_id’, ”, ‘$statename’, ‘$login’, ‘$date_created’, ”, ”)” or die(’Query failed: ‘ . mysql_error());
mysql_query( $insQry );

header(”Location: statelist.php”);
exit;
}
}
?>
<h3 align=”center”>Adding State </h3>
<form name=”state” method=”post” action=”" onsubmit=’return checkform()’>
<div align=”center” style=”height:300px;”>
<table height=”100″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″ style=’border:1px solid silver’>
<tr>
<td height=”25″ align=”right”><div align=”right”>Country Name:</div></td>
<td width=”66%” height=”25″ align=”left”>
<div align=”left”>
<select name=”country” id=”country”>
<option>–Select Country–</option>

<?php
$sql=”SELECT * FROM country ORDER BY country_name”;
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo “<option value=$row[country_id]>$row[country_name]</option>”;
}
?>
</select>
</div></td>
</tr>
<tr>
<td><div align=”right”>State Name: </div></td>
<td><div align=”left”>
<input name=”statename” type=”text” id=”statename”>
</div></td>
</tr>

<tr>
<td colspan=”2″><center>
<input type=”submit” name=”Submit” value=”Add State”>
</center>
</td>
</tr>
<tr>
<td colspan=”2″><center>
<?php echo  $err;
?>

</center>
</td>
</tr>
</table>
</div>
</form>
<script language=’javascript’>
function checkform()
{

if(document.state.country.value==”")
{
alert(”Please Select the Country name”);
document.state.country.focus();
return false;
}
if(document.state.statename.value==”")
{
alert(”Please enter the state name”);
document.state.statename.focus();
return false;
}

}
</script>
<?php
include_once( “footer.php” );
?>

betresult:

<?php
include(”checklogin.php”);
include_once( “conn.php”);
include_once( “header.php” );
require_once(’functions/administeruserdata.php’);
?>
<?php
if (isset($_GET['catid']))
{
$catid = $_GET['catid'];
$eventid = $_GET['eventid'];

?>
<center>
<h3>Bet Result</h3>
</center>

<table align=”center” width=”50%” style=’border:1px solid silver’>
<?php
$rsCat = mysql_query( “Select * From betmaster where bet_catid = $catid and id = $eventid” );
while ($rec = mysql_fetch_array( $rsCat ))
{
$id = ucfirst($rec[bet_memid]);
echo “<tr valign=’top’ ><td class=text style=font-size:12px>Member Id</td>
<td style=font-size:12px>$id</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Condition</td>
<td style=font-size:12px>$rec[bet_condition]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Description</td>
<td style=font-size:12px>$rec[bet_descr]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Bet Amount</td>
<td style=font-size:12px>$rec[bet_amount]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Bet Date</td>
<td style=font-size:12px>$rec[bet_date]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Bet Lastdate</td>
<td style=font-size:12px>$rec[bet_lastdate]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Event Date</td>
<td style=font-size:12px>$rec[bet_event_date]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Staker Id</td>
<td style=font-size:12px>$rec[bet_stakerid]</td></tr>”;
echo “<tr valign=’top’><td class=text style=font-size:12px>Staker Amount</td>
<td style=font-size:12px>$rec[bet_stakeamount]</td></tr></table>”;
}
?>
<form name=”result” method=”post” action=”<?php echo $_SERVER['PHP_SELF'] ?>”>
<table align=”center” width=”50%” style=’border:1px solid silver’>
<tr><td class=”text” style=”font-size:12px” width=”43%”>Featured Bet</td><td>
<select name=”status” id=”status”>
<option>select</option>
<option value=”Featured” >Featured</option>
<option value=”Not Featured”>Not Featured</option>
</select>
</td></tr>
<tr>
<td class=”text” style=”font-size:12px”> Result</td>
<td ><select name=”result” id=”result”>
<option></option>
<option value=”Win”>Win</option>
<option value=”Lost”>Lost</option>
</select>  </td></tr>
<tr><td colspan=”2″ class=text style=”font-size:12px”><center>
<input type = “hidden” name = “catid” value=”<?php echo $catid ?>” />
<input type=”hidden” name = “eventid” value=”<?php echo $eventid ?>”/>
</center>
</td>
</tr>
<tr><td colspan=”2″ style=”font-size:12px”><center>
<input type=”submit” name=”submit” value=”submit” />
</center>
</td>
</tr>
</table>
</form>
<?php
}
else
{
$cat = $_POST['catid'];
$event = $_POST['eventid'];
//echo $cat . “<br>”;
//echo $event . “<br>”;
if (isset($_POST['submit'] ))
{
if ($_POST['status'] == “Featured” )
{
$obj=new RecordSet;
$getNum=$obj->getRecordNum(”SELECT * FROM betmaster WHERE bet_feature = ‘Y’”);
if($getNum == 0)
{
$obj->updateRecord(”UPDATE betmaster SET bet_feature = ‘Y’ WHERE bet_catid = $cat and id = $event”);

//$updatestatus = “UPDATE betmaster SET bet_status = ‘Y’ WHERE bet_catid = $cat and id = $event”;
//echo $updatestatus;
//mysql_query( $updatestatus ) or die(”Error updating status: ” . mysql_error());
}
}
else if ($_POST['status'] == “Not Featured”)
{
$obj=new RecordSet;
$getNum=$obj->getRecordNum(”SELECT * FROM betmaster WHERE bet_feature = ‘Y’”);
if($getNum != 0)
{
$obj->updateRecord(”UPDATE betmaster SET bet_feature = ‘X’ WHERE bet_catid = $cat and id = $event”);

//$updatestatus = “UPDATE betmaster SET bet_status = ‘Y’ WHERE bet_catid = $cat and id = $event”;
//echo $updatestatus;
//mysql_query( $updatestatus ) or die(”Error updating status: ” . mysql_error());

}
}
else if ($_POST['result'] == “Win”)
{
$obj=new RecordSet;
$getrec = $obj->getRecord(”SELECT * FROM betmaster WHERE bet_catid = $cat and id = $event”);

$obj->updateRecord(”UPDATE betmaster SET bet_winnerid = ‘$getrec[bet_memid]‘, bet_loserid = ‘$getrec[bet_stakerid]‘ WHERE bet_catid = $cat and id = $event”);
}
}
include_once( “betview.php” );
}
?>
<?php
include_once( “footer.php” );
?>

check login:

<?php
session_start();

if ( ! isset($_SESSION['adminid']) )
{
header(”Location: index.php”);
}
?>

conn.php:

<?php
$dbservertype=’mysql’;
$servername=’localhost’;
// username and password to log onto db server
$dbusername=”root”;
$dbpassword=”";
// name of database
$dbname=’betting’;

$link = mysql_connect($servername, $dbusername, $dbpassword);

if (!$link)
{
die(”Could not connect to MySQL”);
}

mysql_select_db(”$dbname”,$link) or die (”could not open db”.mysql_error());
?>

countrylist:

<?php
$curpage = “countrylist”;

include(”checklogin.php”);
include_once( “conn.php”);
include_once( “header.php” );
?>
<center>
<a href=”addcountry.php” class=”menu”>Add Country</a>
</center>
<div style=”height:350px”>
<table align=”center” width=”50%”>
<thead style=”background-color:#999999;color:#FFFFFF;font-weight:bold”>
<tr valign=”top”><td valign=”top”>S.NO</td><td valign=”top”>Country Name</td><td>Option</td></tr>
</thead>

<?php
//Paging//
$TotalRow=mysql_query(”select * from country”) or die(”I cannot Select Because”.mysql_error());
$TotalRowNum=mysql_num_rows($TotalRow);
$Start=0;
$Limit=15;
$Page=$_GET['page'];
if (isset($Page))
{
$tmp=$Page*$Limit;
$Start=$tmp-$Limit;
}

$sno=$Start;
$rsCountry = mysql_query( “Select * From country order by country_name limit $Start,$Limit” );
$numcountry=mysql_num_rows($rsCountry);
if($numcountry == 0)
{
$err=”No Data Found”;
}
while ($rec = mysql_fetch_array( $rsCountry ))
{
$sno=$sno+1;
echo “<tr valign=’top’>
<td>$sno</td>
<td>$rec[country_name]</td>
<td><a href=’editcountry.php?countryid=$rec[country_id]‘ class=menu>Edit</a></td>
</tr>”;

}
?>

<tr align=”right” style=”background-color:#999999;”><td colspan=”3″>

<?php
if($numcountry!=0)
{
$NoPage=ceil($TotalRowNum/15);
echo “<span>Page</span>”.”&nbsp;”;
for($i=1;$NoPage>=$i;$i++)
{
echo “&nbsp;”.”<a href=’countrylist.php?page=”.$i.”‘>”.$i.”</a>”;
}
}
?></td>
</tr>
</table>

</div>
<?php
include_once( “footer.php” );
?>

editcountry:

<?php

//Buffet Start//
ob_start();
//Session Start//
session_start();
//Session Check//
include_once( “header.php”);

include (”checklogin.php”);

include(”conn.php”);

if (isset($_GET['countryid']))
{
$countryvalue = $_GET['countryid'];
$sql=”Select * From country Where country_id = ‘$countryvalue’”;
//echo $sql;
$result=mysql_query($sql) or die(”<font color=’red’>Error fetching in country details</font><br>”);
$row = mysql_fetch_array($result);
$countryname = $row['country_name'];

}
$submit=$_POST['txt_update'];
if($submit==”Edit”)
{
$country=$_POST['country_name'];
$sqlcountry = “UPDATE `country` SET `country_name` = ‘$country’ where `country_id`= ‘$countryvalue’”;
//echo “sqlcat: $sqlcat<br>”;
mysql_query($sqlcountry) or die(”error updating country data: “.mysql_error());
header(”Location:countrylist.php”);
}
?>

<h3 align=”center”>Edit Country </h3>
<form name=”form1″ method=”post” action=”" onsubmit=’return checkform()’>
<div align=”center” style=”height:300px;”>
<table height=”100″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″>
<tr>
<td>Coutnry Name: </td>
<td><input name=”country_name” type=”text” id=”country_name” value=<?php echo $countryname;  ?>></td>
</tr>
<tr>
<td colspan=”2″><center>
<input name=”txt_update” type=”submit” id=”txt_update” value=”Edit”>
</center>
</td>
</tr>
</table>
</div>
</form>
<script language=’javascript’>
function checkform()
{
var editcountry = document.getElementById(”country_name”);

if (editcountry.value.length == 0)
{
alert(”Country cannot be blank”);
editcountry.focus();
return false;
}

}
</script>
<?php
include_once( “footer.php” );
?>

editstate:

<?php

//Buffet Start//
ob_start();
//Session Start//
session_start();
//Session Check//
include_once( “header.php”);

include (”checklogin.php”);

include(”conn.php”);

if (isset($_GET['stateid']))
{
$statevalue = $_GET['stateid'];
$sql=”Select * From country_state Where cs_id = ‘$statevalue’”;
//echo $sql;
$result=mysql_query($sql) or die(”<font color=’red’>Error fetching in state details</font><br>”);
$row = mysql_fetch_array($result);
$statename = $row['cs_name'];

}
$submit=$_POST['txt_update'];
if($submit==”Edit”)
{
$state=$_POST['statename'];
$sqlstate = “UPDATE `country_state` SET `cs_name` = ‘$state’ where `cs_id`= ‘$statevalue’”;
//echo “sqlcat: $sqlcat<br>”;
mysql_query($sqlstate) or die(”error updating state data: “.mysql_error());
header(”Location:statelist.php”);
}
?>

<h3 align=”center”>Edit State </h3>
<form name=”form1″ method=”post” action=”" onsubmit=’return checkform()’>
<div align=”center” style=”height:300px;”>
<table height=”100″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″>
<tr>
<td>State Name: </td>
<td><input name=”statename” type=”text” id=”statename” value=<?php echo $statename;  ?>></td>
</tr>
<tr>
<td colspan=”2″><center>
<input name=”txt_update” type=”submit” id=”txt_update” value=”Edit”>
</center>
</td>
</tr>
</table>
</div>
</form>
<script language=’javascript’>
function checkform()
{
var editstate = document.getElementById(”statename”);

if (editstate.value.length == 0)
{
alert(”State cannot be blank”);
editstate.focus();
return false;
}

}
</script>
<?php
include_once( “footer.php” );
?>

statelist:

<?php
$curpage = “statelist”;

include(”checklogin.php”);
include_once( “conn.php”);
include_once( “header.php” );
?>
<center>
<a href=”addstate.php” class=”menu”>Add State </a>
</center>
<div style=”height:350px”>
<table align=”center” width=”50%”>
<thead style=”background-color:#999999;color:#FFFFFF;font-weight:bold”>
<tr valign=”top”>
<td valign=”top”>S.NO</td>
<td valign=”top”>Country</td>
<td valign=”top”>State Name</td>
<td>Option</td>
</tr>
</thead>

<?php
//Paging//
$TotalRow=mysql_query(”select * from country_state”) or die(”I cannot Select Because”.mysql_error());
$TotalRowNum=mysql_num_rows($TotalRow);
$Start=0;
$Limit=15;
$Page=$_GET['page'];
if (isset($Page))
{
$tmp=$Page*$Limit;
$Start=$tmp-$Limit;
}

$rsState = mysql_query( “Select * From country_state order by cs_name limit $Start,$Limit” ) or die(”I cannot Select Because”.mysql_error());
$numstate=mysql_num_rows($rsState);
if($numstate == 0)
{
$err=”No Data Found”;
}

$sno=$Start;
while ($rec = mysql_fetch_array( $rsState ))
{
$sql=”select * from country where country_id=$rec[country_id]“;
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$sno=$sno+1;
echo “<tr valign=’top’>
<td>$sno</td>
<td>$row[country_name]</td>
<td>$rec[cs_name]</td>
<td><a href=’editstate.php?stateid=$rec[cs_id]‘ class=menu>Edit</a></td>
</tr>”;

}
?>

<tr align=”right” style=”background-color:#999999;”><td colspan=”4″>

<?php
if($numstate!=0)
{
$NoPage=ceil($TotalRowNum/15);
echo “<span>Page</span>”.”&nbsp;”;
for($i=1;$NoPage>=$i;$i++)
{
echo “&nbsp;”.”<a href=’statelist.php?page=”.$i.”‘>”.$i.”</a>”;
}
}
?></td>
</tr>
</table>

</div>
<?php
include_once( “footer.php” );
?>

index:

<?php

include_once( “header.php” );

include_once( “footer.php” );
?>

logout:

<?php
session_start();
unset($_SESSION['adminid']);
header(”Location: index.php”);
?>

header.php:

<?php
ob_start();
session_start();

include_once(”conn.php”);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Welcome to Betting</title>
<link href=”main.css” rel=”stylesheet” type=”text/css” />
<link href=”link.css” rel=”stylesheet” type=”text/css” />
</head>

<body>

<table border=”0″ height=”630″ align=”center” cellpadding=”0″ cellspacing=”0″ bgcolor=”#EEEEEE”>
<tr valign=”top”>
<td width=”800″><!– bgcolor=”E5E5E5″>–>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″ bgcolor=”E5E5E5″ class=”text”>

<tr>
<td width=”100″ colspan=”3″ bgcolor=”4E82B2″>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td ><img src=”images/laptop.jpg” alt=”" /><img src=”images/logo.jpg” alt=”" width=”325″ height=”141″  /></td>
<td width=”59″ bgcolor=”#4E82B2″>&nbsp;</td>
</tr>
</table>                    </td>
</tr>
<tr>
<td colspan=”3″><center>
<?php
//echo “login: $_SESSION[adminid] “;

if ( isset($_SESSION['adminid'] ))
{
if ($curpage != ‘cat’)
{
?>
<a href=”cat.php” class=”menu”>Categories</a>&nbsp;|&nbsp;
<?php
}
if ($curpage != ‘viewbets’)
{
?>
<a href=”betview.php” class=”menu”>View Bets</a>&nbsp;|&nbsp;
<?php
}
?>
<a href=”logout.php” class=”menu”>Logout</a>
<?php
}
else if (isset($_POST['adminid']))
{
//echo “after post : $_POST[adminid]<br>”;
$loginQry = “Select * From house
Where house_id like ‘$_POST[adminid]‘
And house_password = ‘$_POST[adminpwd]‘”;
echo $loginQry, “<br>”;
$rs = mysql_query( $loginQry )
or die(”login error: ” . mysql_error());

if (! mysql_num_rows($rs))
{
?>
<meta http-equiv=”refresh” content=”3,URL(index.php)” />
<h2 align=”center”>Invalid Admin Login</h2>
<?php
exit;
}
$recAdmin = mysql_fetch_array($rs);

$_SESSION['adminid'] = $recAdmin['house_id'];
header(”Location: index.php”);
exit;
}
else
{
?>
<h3 align=”center”>Admin Login</h3>
<form action=”<?php echo $_SERVER[PHP_SELF] ?>” method=”post”>
<table align=”center”>
<tr><td>Login ID: </td><td><input type=”text” name=”adminid” /></td></tr>
<tr><td>Password: </td><td><input type=”password” name=”adminpwd” /></td></tr>
<tr><td colspan=”2″ align=”center”><input type=”submit” value=”Login” /></td></tr>
</table>
</form>
<?php
}
?>
</center>
</td>
</tr>
</table>
</td>
</tr>
<tr valign=”top”>
<td>

<!– end of header –>

Leave a Comment