Forum Moderators: coopster
So, any suggestions on what is going wrong? Here is the code -
admin.php - Which SHOULD be fine.
---------
<html>
<title>
LeagueSQL - Admin
</title>
<body>
<form action="createtable.php" method="post">
League Name: <input type="text" name="leagueName" />
<input type="submit" />
<br />
<br />
SITE UNDER DEVELOPMENT!
</form>
</body>
</html>
createtable.php - Where I believe the problem lies.
------------
<?php
$con = mysql_connect("localhost","u08105199","edited");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("u08105199", $con);
echo "db selected & connected to $con";
$leagueName=$_POST['leagueName'];
$sql = "CREATE TABLE $leagueName
(
PlayerID int NOT NULL AUTO_INCREMENT,
PlayerName varchar(15),
GamesPlayed varchar(15),
Wins int,
Losses int,
Draws int,
Points int
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>
----------
Btw, when I do run the script, the message I get is this - "db selected & connected to Resource id #2".
Are you sure that is right?
It should have this structure:
mysql_connect("[server]","[username]","[password]");
Currently as shown you have "u08105199" as your username and as the database you are selecting later on:
mysql_select_db("u08105199", $con);
That should have this structure:
mysql_select_db("[database]", $con);
The error you are getting leads me to believe you aren't connecting to the database.
echo "db selected & connected to 'u08105199'";
or create a variable for it:
$db = 'u08105199';
echo "db selected & connected to $db'";
I would personally just take it out or remove the database name from that line.
$leagueName=mysql_real_escape_string [php.net]($_POST['leagueName']);
$sql = "CREATE TABLE IF NOT EXISTS $leagueName etc...
Always escape your post data.