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
https://forums.phpfreaks.com/topic/163019-solved-trying-to-learn-tables/
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

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.