Jump to content

Help please? PHP/SQL wont work :(


Recommended Posts

Hi guys, I hope someone can help a total lame noob like me  :-X

 

I have been trying to make a form with the details entered into a SQL database.

 

<?php

  $username= $_POST['username'] ;

  $offence = $_POST['offence'] ;

  $punishment=$_POST['punishment'];

  $offencetext=$_POST['offence_text'];

 

$dbhost= 'localhost';

$dbuser = 'root';

$dbpass = 'a';

 

 

 

$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die('Sorry T, error!');

 

if ($conn){ echo 'Connected to MySQL';}

 

mysql_select_db("offender_list")or die(mysql_error());

 

$query=mysql_query("INSERT INTO 'watch_list' ('sername, offence,punishment,offencetext)VALUES('$username','$offence','$punishment','$offencetext')")  or die(mysql_error());

 

 

if($query){echo "Your information has been successfully added to the database.";}

else {echo mysql_error();} // remove mysql_error() before final version is completed

 

 

 

 

?>

 

 

I keep getting an error....when I run the query through MYSQL Adminstrator, it says:

 

"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 'mysql_query(INSERT INTO watch_list ('username', 'offence','punishment','offence_' at line 1"

 

I really do not know what is wrong with my code....and it is driving me nuts. I am really keen to get this working, because it is (imo) a really powerful tool. Im sorry if it is something really obvious but any help will be much appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.