Jump to content

SQL errors as I attempt split data from a session into two tables


Namtip

Recommended Posts

SET UP: Windows vista

# XAMPP 1.7.3,

# Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l

# MySQL 5.1.41 + PBXT engine

# PHP 5.3.1

# phpMyAdmin

 

Error message: 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 ') VALUES ('qwerty','uiop','asd')' at line 2

 

I'm trying to get this multi page order form to insert information into two tables via a session. But it comes up with the above error message. This script worked perfectly with one table but as soon as I coded he information to go into two tables it screwed up. Is it the sprint

 

<?php   

//let's start our session, so we have access to stored data
session_start();

session_register('membership_type');
session_register('terms_and_conditions');

include 'db.inc.php';

$db = mysql_connect('localhost', 'root', '') or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db('ourgallery', $db) or die(mysql_error($db));

   
//let's create the query
$query = sprintf("INSERT INTO subscriptions (
		name, email_address, membership_type,)
	VALUES ('%s','%s','%s')",
mysql_real_escape_string($_SESSION['name']),
mysql_real_escape_string($_SESSION['email_address']),
mysql_real_escape_string($_SESSION['membership_type']));

//let's run the query
$result = mysql_query($query, $db) or die(mysql_error($db));

$query = sprintf("INSERT INTO site_user_info (
		terms_and_conditions, name_on_card,
		credit_card_number,	
		credit_card_expiration_data)
	VALUES ('%s','%s','%s','%s')",
mysql_real_escape_string($_SESSION['terms_and_conditions']),
mysql_real_escape_string($_POST['name_on_card']),
mysql_real_escape_string($_POST['credit_card_number']),
mysql_real_escape_string($_POST['credit_card_expiration_data']));

//let's run the query
$result = mysql_query($query, $db) or die(mysql_error($db));
echo '$result';

?>

 

I'm trying to insert into this database:

<?php
require 'db.inc.php';

$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));

$query = 'CREATE TABLE IF NOT EXISTS subscriptions (
			name						VARCHAR(50)	NOT NULL,
			email_address				VARCHAR(50),
			membership_type				VARCHAR(50),

	PRIMARY KEY (name)
    )
    ENGINE=MyISAM';
mysql_query($query, $db) or die (mysql_error($db));

// create the user information table
$query = 'CREATE TABLE IF NOT EXISTS site_user_info (					
			name						VARCHAR(50)	NOT NULL,
			terms_and_conditions		VARCHAR(50) NOT NULL,
			name_on_card				VARCHAR(50),
			credit_card_number			VARCHAR(50),
			credit_card_expiration_data	VARCHAR(50),

	FOREIGN KEY (name) REFERENCES subscriptions(name)
    )
    ENGINE=MyISAM';
mysql_query($query, $db) or die (mysql_error($db));

echo 'Success!';
?>

What am I doing wrong? is there a code spell checker :)? Also should I use the mysql_real_escape_string() on the user input as they become sessions variables or is it okay to wait and clean the input as it gets inserted in the table? Thanks for your help.

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.