Jump to content

[SOLVED] trying to learn tables


zenix

Recommended Posts

Hi, I am attempting to learn how to make a basic database that will allow input from a user of a web page to be entered into it. I am not the most efficient coder, but I'm learning and I'm new at this. Anyway, I keep getting this error that says for me to check the mysql manual for the right syntax to use near '(test_id) KEY testype(test_lname, test_fname))' at line 4. I can't see anything wrong with it. If someone could guide me in the right direction I'd really appreciate it! Here is the code I've made:

 

'
<?php


$conn = mysql_connect('localhost', 'root')or die(mysql_error());

$create = mysql_query("CREATE DATABASE IF NOT EXISTS testdb") or die(mysql_error());

mysql_select_db ("testdb");

//create table
$testdb = 'CREATE TABLE test(test_id int (11) NOT NULL auto_increment,
						 test_lname varchar(40) NOT NULL,
						 test_fname varchar(40) NOT NULL
   							 PRIMARY KEY(test_id)
						 KEY testype(test_lname, test_fname))';

$result = mysql_query($testdb) or die(mysql_error());

//Create test type table
$testype = 'CREATE TABLE testype(testype_id int(11) NOT NULL auto_incrememnt,
							  empl_pos NOT NULL,
							  primary key (testtype_id))';

//create table others
$others = 'CREATE TABLE others(others_id int (11) NOT NULL auto_increment,
						   others_mom varchar(40) NOT NULL,
						   others_dad varchar(40) NOT NULL
						   others_bro varchar(40) NOT NULL
						   others_sis varchar(40) NOT NULL
						   PRIMARY KEY(others_id))';

$results = mysql_query($others) or die(mysql_error());

echo 'Database successfully created!';

?>

Link to comment
Share on other sites

Hi

 

Nothing major. Couple of missing commas:-

 

CREATE TABLE zenix2(zenix_id int (11) NOT NULL auto_increment,

zenix_lname varchar(40) NOT NULL,

zenix_fname varchar(40) NOT NULL,

PRIMARY KEY(zenix_id),

KEY testype(zenix_lname, zenix_fname))

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.