Jump to content


Photo

Connecting mysql to PHP


  • Please log in to reply
2 replies to this topic

#1 Misomurai

Misomurai

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 31 March 2013 - 09:29 PM

Hey, can someone tell me what's wrong with this code?

My browser says that line 3 is wrong, but I'm not sure what's wrong about it.

Thanks 

 

--------------------------------------------------------------------------------------------

 

<?php
    if ($_POST['submit1'] != ''){
      $link = mysql_connect("$dbname", "$_library_lab", "$password");
      if (!$link == FALSE) {
        $database = mysql_select_db('bookmark');
        if ($database==TRUE){
          $name = $_POST['name'];
          $book = $_POST['book'];
          $bookmark = $_POST['bookmark'];
          $shiori = $_POST['shiori'];
 
          $sql="insert into bookmark (name, book, bookmark, shiori) values('{$name}','{$book}','{$bookmark}','{$shiori}')";
          $result = mysql_query($sql);
          if ($result == TRUE){
          }else{
            echo('DB insert Failure!');
          }
        }
        mysql_close($link);
      }
    }
    ?>


#2 trq

trq

    Advanced Member

  • Administrators
  • 30,723 posts
  • LocationSydney, Australia.

Posted 31 March 2013 - 09:41 PM

The variables you are passing to mysql_connect(), wehere are they defined? And why the hell are they in quotes?

ps: The mysql extension has been deprecated. All new code should be using mysqli or PDO.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#3 JaysonDotPH

JaysonDotPH

    Advanced Member

  • Members
  • PipPipPip
  • 165 posts
  • LocationPhilippines

Posted 01 April 2013 - 12:59 AM

its okay for a beginner, to protice procedural coding like you show code above. and try to reconstruct your code or else use other way for insert. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com