Jump to content

amavadia

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by amavadia

  1. Thank you!! had a few other errors after that but managed to sort them out. Much appreciated!
  2. Hi, I am looking to create 3 tables for a project I am just starting on, and was wondering if anyone could help spot the error(s) in my code: I am trying to run it through a php file. The server/login details are in the include file, which are correct because ive used the same file to create other parts of the database. This is the error I keep getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY (employer_id) ) ENGINE=MyISAM' at line 11 <?php include 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die('Unable to connect'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); //create customers table $query = 'CREATE TABLE IF NOT EXISTS customer ( people_id INTEGER NOT NULL AUTO_INCREMENT, first_name VARCHAR(20) NOT NULL, last_name VARCHAR(20) NOT NULL, email VARCHAR(50) NOT NULL, address_1 VARCHAR(30) NOT NULL, address_2 VARCHAR(30), county VARCHAR(30) NOT NULL, postcode VARCHAR(10) NOT NULL, telephone VARCHAR(15), customer_attribute VARCHAR(255) NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY(people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create employer table $query = 'CREATE TABLE IF NOT EXISTS employer ( employer_id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, address_1 VARCHAR(30) NOT NULL, address_2 VARCHAR(30), county VARCHAR(30) NOT NULL, postcode VARCHAR(10) NOT NULL, email VARCHAR(50) NOT NULL, telephone VARCHAR(15) NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, PRIMATY KEY (employer_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create advert table $query = 'CREATE TABLE IF NOT EXISTS advert ( advert_id INTEGER NOT NULL AUTO_INCREMENT, employer_id INTEGER NOT NULL, start_date DATE NOT NULL, finish_date DATE NOT NULL, vacancies TINYINT UNSIGNED, description TEXT[3000] NOT NULL, app_deadline DATE, location VARCHAR(30) NOT NULL, salary MEDIUMINT(6) UNSIGNED NOT NULL, web_link VARCHAR(50), app_process VARCHAR(255) NOT NULL, attributes VARCHAR(255) NOT NULL, PRIMARY KEY (advert_id) FOREIGN KEY (employer_id) REFERENCES employer(employer_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'success!'; ?> Thanks!
  3. Hi, I've just started to learn php today from a book, and ive created this example for a calculator but i keep getting an error message saying there is an unidentified variable. There is a html page with the forms on it: <HTML> <HRAD> <TITLE>Caluclation Form</TITLE> </HEAD> <BODY> <FORM METHOD="POST" ACTION="calculate.php"> <p>Value 1: <INPUT TYPE="text" NAME="val1" SIZE=10></p> <p>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></p> <p>Calculation:<br> <INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br> <INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br> <INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br> <INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</p> <p><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></p> </FORM> </BODY> </HTML> and the php script in a nother file: <php if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] == "")) { header("Location: http://127.0.0.1/calculate_form.html"); } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $POST[val1]] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $POST[val1]] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $POST[val1]] / $_POST[val2]; } ?> <HTML> <HEAD> <TITLE>Calculation Result</TITLE> </HEAD> <BODY> <p>The result of the calculation is: <?php echo "$result"; ?></p> </BODY> </HTML> When you don't enter anything into the calc, it is meant to reload the page, but i get this: The result of the calculation is: Notice: Undefined variable: result in C:\wamp\www\calculate.php on line 28 Can anyone see what the problem is? Probably something really obvious but im stumped :-\ Thanks!
×
×
  • 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.