Webdetector Webmaster Forums - Your favorite webmaster community
 

Advertise Here Wordpress Premium Sportscrazyforum - Where Sport is a religion dnfame.com Spruce Host chooseapixel.com

Go Back   Webdetector Webmaster Forums - Your favorite webmaster community > Developers Corner > Programming > PHP Forum

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-2008, 01:06 PM
Member
noobee
 
Join Date: May 2008
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default error when passing value from a form to SQL?

Code:
<?php
require ('config.php');
$username=$_POST['username'];
$offence=$_POST['offence'];
$punishment= $_POST['punishment'];
$table=naughty;
$con= @mysql_connect ($dbhost,$dbusername,$dbpassword); //used to conneect to the mysql database
if (!$con)

{
die ('could not connect: ' .mysql_error());
}


$sql="SELECT*FROM $table";
$result=mysql_query($sql);
if (!result)
{

echo "No table exists!";
exit ();
}

@mysql_select_db("naughtylist", $con);
$sql="CREATE TABLE `naughtylist`.`naughty` (
  `username` VARCHAR(15) NOT NULL,
  `offence` VARCHAR(45) NOT NULL,
  `punishment` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`username`)
)";


$query=mysql_query ("INSERT INTO naughty (username, offence, punishment) VALUES ('$username','$offence', '$punishment')");
$result=mysql_query($query) or die (mysql_error());

?>
The error is not helpful at all:

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 '1' at line 1..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)  
Old 06-13-2008, 07:42 AM
Member
Marketeer
 
Join Date: May 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default error when passing value from a form to SQL?

The second $sql statement is broken up over several lines, which is probably causing the error.

Try this...

Code:
$sql = "";
$sql += "CREATE TABLE `naughtylist`.`naughty` (";
$sql += "`username` VARCHAR(15) NOT NULL, ";
$sql += "`offence` VARCHAR(45) NOT NULL, ";
$sql += "`punishment` VARCHAR(45) NOT NULL, ";
$sql += "PRIMARY KEY (`username`) ";
$sql += ")";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 11:55 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Ad Management by RedTyger