多年没有做任何php数据库工作,相当简单的问题我确信任何有经验的人,下面是我的代码它应该从数据库获取所有结果并将这些显示到带有链接的表:
<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($query2=mysql_fetch_array($query1)) { echo "<tr><td>".$query2['filepath']."</td>"; echo "<td>".$query2['filename']."</td>"; echo "<td><a href='edit.php?id=".$query2['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>所以它失败的路线是
while($query2=mysql_fetch_array($query1))错误消息是:
警告:mysql_fetch_array()期望参数1是资源,第27行的C:\ xampp \ htdocs \ welcome.php中给出的对象
Not done any php database work for years, fairly simple question I'm sure for anyone with experience, below is my code it should take all the results from the database and display these to a table with links:
<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($query2=mysql_fetch_array($query1)) { echo "<tr><td>".$query2['filepath']."</td>"; echo "<td>".$query2['filename']."</td>"; echo "<td><a href='edit.php?id=".$query2['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>So the line it's failing on is
while($query2=mysql_fetch_array($query1))The error message is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\xampp\htdocs\welcome.php on line 27
最满意答案
而不是mysql_fetch_array你需要使用mysqli_fetch_array 。
<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($row=mysqli_fetch_array($query1)) { echo "<tr><td>".$row['filepath']."</td>"; echo "<td>".$row['filename']."</td>"; echo "<td><a href='edit.php?id=".$row['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>注意:我还将您的变量名称更改为更明智的名称。
Instead of mysql_fetch_array you need to use mysqli_fetch_array.
<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($row=mysqli_fetch_array($query1)) { echo "<tr><td>".$row['filepath']."</td>"; echo "<td>".$row['filename']."</td>"; echo "<td><a href='edit.php?id=".$row['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>Note: I also changed your variable name to a more sensible one.
更多推荐
发布评论