2011-02-23 71 views
0
$query = "INSERT INTO users (name, password) VALUES ('$myusername', '$mypassword')"; 
if (!($result = $mysqli->query($query))) 
    die("WHAT???? " . $mysqli->error . " EEEEEFFFFFFF."); 

$count = $result->num_rows; 

while ($row = $result->fetch_array()) { 
    if ($row[name] == $myusername) { 
     $mysqli->query("DELETE FROM users WHERE name='$myusername' AND password='$mypassword'"); 
     $count = 5; 
    } 
} 

當我運行它,它給了我一個錯誤: 致命錯誤:非對象上調用一個成員函數fetch_array()在/home/appstore/public_html/phpstoof/signedup.php在線26從非對象調用方法?

26行是while語句開始的地方(while(x))。 $ mysqli ALREADY mysqli()的一個實例。如果相同的代碼在另一個文件上工作,我不會看到這是一個錯誤。

回答

2

INSERT語句沒有任何提取。

+0

啊哈!謝謝一堆! – Imnotanerd 2011-02-23 04:19:55

2

正如@mellamokb所說,INSERT沒有任何提示。此外,您還使用了MySQLMySQLi的組合。

隨着MySQLi,代碼應該是這樣的:

$mysqli = new mysqli($db_host, $db_username, $db_password, $db_database); 

$str_sql = 'INSERT INTO users (name, password) VALUES (?, ?)'; 

// Create a prepared statement 
$stmt = $mysqli->prepare($str_sql); 

// Bind parameters for markers; same order and same count in prepared statement 
$stmt->bind_param('ss', $myusername, $mypassword); 

// Execute query 
$stmt->execute(); 

// ************************************************************************* 
// If you're using a SELECT statement, each output field must be bound to 
// a variable in the same order as in SELECT 
// Bind result variables 
$stmt->bind_result($_var1, $_var2, $_var3, ...); 

// Fetch results and generate output as an associative array 
while ($stmt->fetch()) 
{ 
    // Handle $_var1, $_var2, $_var3, ... 
} 
// ************************************************************************* 

// Free stored result memory 
$stmt->free_result(); 

// Close statement 
$stmt->close(); 

// Close connection 
$mysqli->close();