Jump to content

syntax error... ARGH I WILL SHOOT THIS THING!!!!


netman182

Recommended Posts

i am having problems with this. i can't seem to figure it out.

 

I am getting this error: You have an error in your SQL syntax

 

phpmyadmin server version: Server version: 5.1.37

PHP version: 5.3

 

here is the code. can anyone help? it is probably a simple problem.

ID is an auto increment field.

the rest are text

 

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="95887rj"; // Mysql password 
$db_name="bccsl"; // Database name 
$tbl_name="managers2"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO Managers2 (ID, First, Last, City, Address, Postal, Home, Cell, Email, Username, Password, Church, Team)
VALUES
('',$_POST[firstname]','$_POST[lastname]','$_POST[city]','$_POST[address]','$_POST[postal]','$_POST[home]','$_POST[cell]','$_POST[church]','$_POST[team]','$_POST[username]','$_POST[password]')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?> 

to avoid confusion in the query I would suggest this

 

$sql = sprintf("INSERT INTO Managers2 (First, Last, City, Address, Postal, Home, Cell, Email, Username, Password, Church, Team)
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", $_POST['firstname'],$_POST['lastname'],$_POST['city'],$_POST['address'],$_POST['postal'],$_POST['home'],$_POST['cell'],$_POST['church'],$_POST['team'],$_POST['username'],$_POST['password']);

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.