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
https://forums.phpfreaks.com/topic/108824-help-please-phpsql-wont-work/
Share on other sites

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.