0

I am new here and i want to ask a simple question to all of you as i am a beginner in PHP. I have created a table in MySQL database with 4 columns named id , stuimg , stuname , studetail. also i have created a page through which values and image gets stored into these columns. Now my problem is that how can i retrieve all these information stored in these columns and display it on a page (Including Image)

you can check my code and please correct if i am doing something wrong:

<html>
<body>
    <form action="" method="post">
        <table>
            <?php
                $p=$_GET['id'];       
                include('dbconfig.php');  
                $query = "SELECT * FROM aboutstudent where id ='$p'";
                $result = mysql_query($query);
                while ($data = mysql_fetch_array($result))
                {
            ?>
                    <tr>
                        <td>Image*:</td>
                        <td><input name="image" type="file" value="<?php echo $_FILES['image']['name'];?>"  /> </td>
                    </tr>
                    <tr>
                        <td>Name*:</td>
                        <td><input name="name" type="text" value="<?php echo $data['name'];?>"  /> </td>
                    </tr>
                    <tr>
                        <td>Description*:</td>
                        <td><input name="des" type="textarea" value="<?php echo $data['description'];?>"  /> </td>
                    </tr>
            <?php } ?>
        </table>
    </form>
</body>

mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
srp003j
  • 15
  • 6

4 Answers4

1

You're trying to post to a new page without the id-variable being set.

Kurt Du Bois
  • 7,550
  • 4
  • 25
  • 33
0
<input name="image" type="file" value="<?php echo $_FILES['image']['name'];?>"  />

replace it 

<img src = "<?php $data['image']; ?>"> <!-- give full path where image is store  -->

and also remove form while loop

it means write it out of while loop

wild
  • 340
  • 1
  • 3
  • 14
0

At first, you are directly passing variable to SQL query from $_GET, which is HUGE security issue! See this post or at least use mysql_real_escape_string() like this:

$query = "SELECT * FROM aboutstudent where id ='" . mysql_real_escape_string($p) . "';";

Next, if your dbconfig.php contains correct credentilas AND connect you to database, your code looks fine, except $_FILES['image']['name'], which contains data only when input file is submited. And next, you can't set default value for input type='file'. If you have your image saved in database, use simple $data['image'];, otherwise provide more info.

Community
  • 1
  • 1
Pavel Štěrba
  • 2,822
  • 2
  • 28
  • 50
0

I have implemented your code, and this will work fine

<html>
 <body>
 <table>
<?php
  $p=$_GET['id'];       
  include('dbconfig.php');  
  $query = "SELECT * FROM aboutstudent where id ='$p'";
  $result = mysql_query($query);
  while ($data = mysql_fetch_array($result))
  {
?>
        <tr>
         <td>Image*:</td>
         <td><img src="<?php echo $_FILES['image']['name'];?>"/></td>
        </tr>

        <tr>
         <td>Name*:</td>
         <td><input name="name" type="text" value="<?php echo $data['name'];?>"  /></td>
        </tr>
        <tr>

        <td>Description*:</td>
         <td><input name="des" type="textarea" value="<?php echo $data['description'];?>"  />  
        </td>
        </tr>

        </table>
        <?php }?>
 </body>
</html>
SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62