• 07-05-2008, 12:13:26
    #1
    Aşağıda küçük bi kodlama yapmaya çalıştım.Amacım sitenin kaynak kodunu mysql'e kaydetmek.Ama İşlemi yaptığımda

    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 ''}" topmargin=3 marginheight=3>
    Web</sp' at line 2
    Hatasını aldım tahminimce kaynak kodunu text haline getirmem gerekicek ama nasıl? adssasd gibi bişey vardı / bunumu ne temizliyorduk.Sorun orda mı ?

    <?php
    
    /* Connecting, selecting database */
    $db_link = mysql_connect("localhost", "root", "");
    if (!$db_link) {
       die("Could not connect: " . mysql_error());
    }
    mysql_select_db("emre42") or die("Could not select database");
    
    /* Performing SQL query */
    
    $data=file_get_contents('http://www.google.com');
    $site="www.google.com";
    
    $ekleme=mysql_query("INSERT INTO beyefendi 
    (site, icerik) VALUES('$site', '$data' ) ") 
    or die(mysql_error()); 
    
    
    ?>
    Birde <html></html> yada <a></a> gibi tagların arasındaki kodları çekme var sanırım o konuda da bilgi verebilicek arkadaş var mı?Yani bölgesel alabiliyormuyuz kodları ? Şimdiden teşekürler
  • 07-05-2008, 14:03:07
    #2
    Kurumsal PLUS
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    
    $db_link = mysql_connect("localhost", "root", "");
    if (!$db_link) {
       die("Could not connect: " . mysql_error());
    }
    mysql_select_db("emre42") or die("Could not select database");
    
    
    
    $data=file_get_contents('http://www.google.com');
    $site="www.google.com";
    
    $ekleme=mysql_query(sprintf("INSERT INTO beyefendi 
    (site, icerik) VALUES(%s, %s)", GetSQLValueString($site, "text"), GetSQLValueString($data, "text"))) or die(mysql_error());
    
    ?>