0
私が実行しようとしていますコードの下にあるが、それは私に 'cで....非オブジェクトのプロパティを取得しようとしている....'というエラーを与えます。 このコードはindex.phpページに表示される '画像'と 'テキスト'に関する情報をプルアップする必要があります。私は是非試してみましたが、何が問題か分かりませんでした。私は方法でPHPの初心者です:)あなたが私を助けてくれたら嬉しく思います。は、私は以下のコードを実行しようとしていますが、それは私にこのエラーを与える:Cで非オブジェクトのプロパティを取得しようとすると:はXAMPP htdocsに .... index.phpの行に47
<!DOCTYPE html>
<?php
$alert = "";
//if upload button is pressed
if(isset($_POST['upload'])){
//the path to store the uploaded image
$target = "images/".basename($_FILES['image']['name']);
//connect to the database
$conn = new mysqli('localhost', 'imgcms', '', '');
//Get all the submitted data from thye form
$image = $_FILES['image']['name'];
$text = $_POST['text'];
$sql = "INSERT INTO images (image, text) VALUES ('$image', '$text')";
//Move the uploaded image into the folder: images
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
$alert = "Image uploaded successfully";
}else{
$alert = "There was a problem uploading the image";
}
}
?>
<html>
<head>
<title>ImageBlogger</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="content">
<?php
//connect to the database to display image from the database
$conn = new mysqli('localhost', 'imgcms', '', '');
$sql = "SELECT * FROM images";
$result = $conn->query($sql);
if($result->num_rows > 0){
//output data of each row: image and text
while($row = $result->fetch_assoc()){
echo "<div id='img_div'>";
echo "<img src='images/".$row['image']."'>";
echo "<p>".$row['text']."</p>";
echo "</div>";
}
}else{
echo "0 results";
}
$conn->close();
?>
<form action="index.php" method="post" autocomplete="off" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea name="text" cols"40" rows="4" placeholder="Content..."></textarea>
</div>
<div>
<input type="submit" name="upload" value="Post the content">
</div>
</form>
</div>
</body>
</html>
ねえRbaskam、 私は、コードを追加しましたし、今では言う:「クエリのエラーがある:いいえデータベース選択」と前のエラー(非オブジェクトのプロパティを取得しようとするが...)まだそこではありません。 –
43行目の接続文字列は次のようになります。あなたにはDB名はありません – rbaskam
私はそれを行っていますが、それでも「データベースが選択されていません」と以前のエラーが表示されています。私はデータベースを作成したときにデータベースのパスワードとユーザー名を使用しなかったので、2つのフィールド($ usernameと$ password)は空のままです。 –