2011-08-05 20 views
0

を働いていない私はテーブルが作成、変更されている単純なコードを持っていますが、テーブルはで始めるために作成されていない、と次のエラーが表示されている:PHP&SQL:テーブルを挿入および更新する機能が

を未定義の変数:ライン上の価格28
未定義の変数:newbrandライン上の28
未定義の変数:行にnewprice 28

ライン28:

$conexion-> modify("Mitsubishi",40000000,$price,$newbrand,$newprice); 

完全なコード:

<?php 

class MyDataBase{ 
    private $link; 

    public function __construct($server,$user,$password,$base){ 
     //Conectar 
     $this->link = mysql_connect($server,$user,$password); 
     mysql_select_db($base,$this->link); 
     } 

     public function insert($model,$brand,$price){ 
      mysql_query("INSERT INTO autos (model, brand, price) VALUES ($model,'$brand', $price)",$this->link);} 

     public function modify($model,$brand,$price,$newbrand,$newprice){ 
      mysql_query("UPDATE 'crautos'.'autos' SET 'brand' = '$newbrand', 
         'price' = '$newprice' WHERE 'autos'.'model' =5 AND 'autos'.'brand' = '$brand' AND 'autos'.'price' ='$price' LIMIT 1" ,$this->link);} 

     public function __destruct(){ 
     //desconectar 
     } 

} 


$conexion = new MyDataBase ('localhost', 'root', '','crcars'); 
$conexion-> insert(05,"Ford",50000000); 
$conexion-> modify("Mitsubishi",40000000,$price,$newbrand,$newprice); 
?> 

答えて

1

$conexion-> modify("Mitsubishi",40000000,$price,$newbrand,$newprice);

あなたは$価格の値を設定することはありません、$ newbrand、$ newprice。そしてまた、あなたのデータをエスケープしていない:

public function insert($model,$brand,$price){ 
    $model = mysql_real_escape_string($model); 
    $brand = mysql_real_escape_string($brand); 
    $price = (int)$price; 
    mysql_query("INSERT INTO autos (model, brand, price) VALUES ('$model','$brand', $price)",$this->link); 
} 

と同じあなた件のデータをエスケープする必要があり、変更のために参照してください。http://php.net/manual/fr/function.mysql-real-escape-string.php

関連する問題