Is there a way to do this? My attempt so far have all failed.
What i'm trying to do, is set a variable in a switch statement, that will save a piece of HTML in the sql table, based on which case was met.
Here is the current code, so that you mat see the variables and whatnot.
It works when I set $scorelink as "test", so the code itself is working ok, its finding how to create a working string to do the job.
<?php
$con = mysql_connect("localhost","u08105199","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("u08105199", $con);
echo "Your league has been created.";
$leagueName = mysql_real_escape_string($_POST['leagueName']);
$leagueType = mysql_real_escape_string($_POST['leagueType']);
$timestamp=date("d/m/Y");
switch ($leagueType)
{
case "classic":
$sql = "CREATE TABLE $leagueName
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
PlayerName varchar(15),
GamesPlayed tinyint UNSIGNED,
Wins tinyint UNSIGNED,
Losses tinyint UNSIGNED,
Draws tinyint UNSIGNED,
Points tinyint UNSIGNED
)";
break;
case "multiplayer":
$sql = "CREATE TABLE $leagueName
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
PlayerName varchar(15),
GamesPlayed tinyint UNSIGNED,
Times_1st tinyint UNSIGNED,
Times_2nd tinyint UNSIGNED,
Times_3rd tinyint UNSIGNED,
Points tinyint UNSIGNED
)";
break;
case "trueskill";
$sql = "CREATE TABLE $leagueName
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
PlayerName varchar(15),
GamesPlayed tinyint UNSIGNED,
Wins tinyint UNSIGNED,
Losses tinyint UNSIGNED,
Draws tinyint UNSIGNED,
Points tinyint UNSIGNED
)";
break;
default:
echo "No league type has been selected.";
}
$scorelink = "test";
mysql_query("INSERT INTO League_Index (LeagueName, LeagueType, DateCreated, ScoreLink)
VALUES ('$leagueName', '$leagueType', '$timestamp', '$scorelink')") or die(mysql_error());
mysql_query($sql,$con);
mysql_close($con);
?>