Jump to content

[SOLVED] Using PHP to create a table in MySql


Steviant

Recommended Posts

Hi Guys,

 

Hope you don't mind me asking for help with my first post on these forums. I'm a complete novice and have only just grasped the simple parts of PHP and MySQL.

 

I'm trying to develop an application but am stumbling a bit.

 

I've created a switch which works fine. It checks to see what is set to 'compYet' in the Member table. (I know this because it echos the 'n' message).

 

If it's set to 'n' I want it to create two tables and change it to 'y'.

In the loginpage before reaching the application a session variable is set 'logname' and I want the two tables to be called: LOGNAMEcomp and LOGNAMEjob.

 

Here's what I've got so far only it doesn't seem to work:

 

 

<?php

 

session_start();

include("ALL OF THE LOGIN DETAILS.php");

 

 

$connection = mysql_connect($host, $user,$password)

or die ("couldn't connect to server.");

$db = mysql_select_db($database, $connection)

or die ("Couldn't select database.");

 

$sql = "SELECT compYet FROM Member WHERE loginName='$_SESSION[logname]'";

$result = mysql_query($sql)

or die("Couldn't execute query.");

$beenbefore = mysql_fetch_array($result);

 

 

 

 

switch ($beenbefore["compYet"])

{

case "n":

{

echo "Not yet created";

 

/* Create a table for lognamecomp and lognamejob then set the compYet to Y in Member table*/

$createtablecomp = "CREATE TABLE '".$_SESSION['logname']."comp' ( competency VARCHAR(20) NOT NULL, PRIMARY KEY(competency) )";

$createtablejob = " CREATE TABLE '".$_SESSION['logname']."job' ( job VARCHAR(20) NOT NULL, PRIMARY KEY(job) )";

$setcomp = " UPDATE Member SET compYet = 'y' WHERE ID = '".$_SESSION['logname']."'";

$result1 = mysql_query($createtablecomp);

$result2 = mysql_query($createtablejob);

$result3 = mysql_query($setcomp);

}

 

 

break;

 

 

 

case "y":

echo "bleh";

 

break;

 

default:

echo "this is the default";

}

?>

 

any thoughts please? Thanks :)

 

Steve

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.