View Full Version : _Get data into Db, what am i doing wrong

02-10-2010, 05:45 PM
My code

//inside of oop.php
public function sql_add($teacher,$subject,$due,$desc,$bigtext,$major,$date){
$sql = "INSERT INTO `hw`.`assi` (`id`, `teacher`, `class`, `due`, `simpled`, `bigtext`, `major`, `date`) VALUES
(NULL, \'{$teacher}\', \'{$subject}\', \'{$due}\', \'{$desc}\', \'{$bigtext}\', \'{$major}\', \'{$date}\');";
$dbcon = new MySQLDatabase();
$dbcon ->query($sql);

echo "<p>Adding a new Assignment</p>";
//For debugging purposes
$teacher = $_GET['teacher'];
$due = $_GET['due'];
$subject = $_GET['subject'];
$desc = $_GET['desc'];
$bigtext = $_GET['bigtext'];
$major = $_GET['major'];
$date = $_GET['date'];
echo '<pre>';

echo '</pre>';


public function query($sql) {
$this->last_query = $sql;
$result = mysql_query($sql, $this->connection);
return $result;

function __construct() {


public function open_connection() {
$this->connection = mysql_connect('localhost', '****', '*****');
if (!$this->connection) {
die("Database connection failed: " . mysql_error());
} else {
$db_select = mysql_select_db('***', $this->connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());

note $t1 = new oop()

Why do i just get

Adding a new Assignment

array(3) { ["teacher"]=> string(3) "111" ["due"]=> string(3) "222" ["function"]=> string(3) "add" } Database query failed: 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 '\'111\', \'\', \'222\', \'\', \'\', \'\', \'\')' at line 2
Please help,:confused:

02-10-2010, 05:53 PM
Those backslashes aren't needed, in fact, they are causing your syntax error.

02-10-2010, 06:02 PM
Thanks. Wow something so simple was giving me so many issues.
Why did phpmyadmin add slashes though? I just copy-pasted it and put in my variable names.