1

I have inserted couple of emails from a text file into database using mysqli. They get inserted though. Now when I am checking them back I am not getting any result.

Query for inserting emails from text file.

$query = "LOAD DATA LOCAL INFILE 'new.txt' INTO TABLE $table FIELDS TERMINATED BY '\n' (email)";
$result = mysqli_query($connection, $query) or trigger_error(mysqli_error($connection),E_USER_ERROR);

Query for checking them back using email not working.

$query = "SELECT email FROM $table WHERE email='email'";
$result = mysqli_query($connection, $query) or trigger_error(mysqli_connect_error(), E_USER_ERROR);
$row = mysqli_fetch_assoc($result);
$email = $row['email'];
echo $email.'<br >';

Query for checking them back using id is working.

$query = "SELECT email FROM $table WHERE id='1'";
$result = mysqli_query($connection, $query) or trigger_error(mysqli_connect_error(), E_USER_ERROR);
$row = mysqli_fetch_assoc($result);
$email = $row['email'];
echo $email.'<br >';

Output of this query shows a white space at the end of email but when I check in database there is no white space.

Please see why this is not working and suggest any possible way to do this.

Thanks

4

1 回答 1

1

您的代码无法正常工作。mysqli_query 返回一个 mysqli_result 对象。

您可以使用 mysqli_fetch_array 来获取数据:

$query = "SELECT email FROM $table WHERE email='email'";
$result = mysqli_query($connection, $query) or trigger_error(mysqli_connect_error(), E_USER_ERROR);
$row = mysqli_fetch_array($result);
$email = $row['email'];
echo $email.'<br >';

顺便说一句:当您更改错误报告设置时,PHP 会告诉您“未定义的变量 $row”。

于 2013-06-07T14:38:33.537 回答