Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    _Get data into Db, what am i doing wrong

    My code
    PHP 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); 
    PHP Code:
    echo "<p>Adding a new Assignment</p>";
    //For debugging purposes
    var_dump($_GET);
    $teacher =  $_GET['teacher'];
    $due $_GET['due'];
    $subject $_GET['subject'];
    $desc $_GET['desc'];
    $bigtext $_GET['bigtext'];
    $major $_GET['major'];
    $date $_GET['date'];
    $t1->sql_add($teacher,$subject,$due,$desc,$bigtext,$major,$date);
    echo 
    '<pre>';

    echo 
    '</pre>'
    Mysql.php
    PHP Code:
    public function query($sql) {
            
    $this->last_query $sql;
            
    $result mysql_query($sql$this->connection);
            
    $this->confirm_query($result);
            return 
    $result;

     function 
    __construct() {
        
    $this->open_connection();
            
      }

        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,

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Those backslashes aren't needed, in fact, they are causing your syntax error.

  • Users who have thanked Fumigator for this post:

    jman888 (02-10-2010)

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •