Click here to Skip to main content
15,921,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to retrieve data from MySql database using php but only the first word of the retrieved field is extracted. Also after retrieving the the data I want to display it in the textarea(html) control. I've tried both but nothing seems to be working.

My code is:

XML
<?php
            $con= mysql_connect("localhost","root","pritam");

            if (!$con)
            {
                die("Can not connect: " . mysql_error());
            }
            mysql_select_db("new_blog",$con);


            if(isset($_POST['update']))
            {
                $UpdateQuery = "UPDATE user_posts SET title='$_POST[title]', body='$_POST[body]' where post_id='$_POST[hidden]'";
                mysql_query($UpdateQuery, $con);
                echo "<script type='text/javascript'> alert('Post Successfully Modified') </script>";
            };

            if(isset($_POST['delete']))
            {
                $DeleteQuery = "DELETE FROM user_posts where post_id='$_POST[hidden]'";
                mysql_query($DeleteQuery, $con);
                echo "<script type='text/javascript'> alert('Post Successfully Deleted') </script>";
            };

            $sql = "SELECT * FROM user_posts";
            $myData = mysql_query($sql,$con);

            echo "<table id=blog_post >
            <tr>
            <th style='font-size:25px;'>Title</th>
            <th style='font-size:25px;'>Body</th>
            <th colspan=2 style='font-size:25px;'>Operation</th>
            </tr>";
            while($record = mysql_fetch_array($myData))
            {
                echo "<form action=Add_Update_Delete_Post.php method=post>";
                echo "<tr>";
                echo "<td>" . "<input type='text' style='width:300px; height:30px; font-size:18px;' name='title' value=" . $record['title'] . "/> </td>";
                echo "<td>" . "<textarea rows=10 cols=60  name='body' value=" . $record['body'] . " /></textarea></td>";
                echo "<td>" . "<input type='submit' name='update' value='Modify' style='width:200px; height:35px; font-size:16px;'>" . " </td>";
                echo "<td>" . "<input type='submit' name='delete' value='Delete' style='width:200px; height:35px; font-size:16px;'>" . " </td>";
                echo "<td>" . "<input type='hidden' style='border:0;' name='hidden' value=" . $record['post_id'] . " </td>";
                echo "</tr>";
                echo "</form>";
            }
            echo "</table>";
            mysql_close($con);
        ?>
Posted

1 solution

One thing you may consider is your syntax within the fields wherein you recover your data . . . you're missing the single quotes that are supposed to go around value='something'.

Depending upon the content, the rendering you get could be all sorts of weird - HTLM is very forgiving with screwed up data, so I'd look at the page source.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900