Click here to Skip to main content
14,303,339 members
Rate this:
Please Sign up or sign in to vote.
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:


            $con= mysql_connect("localhost","root","pritam");

            if (!$con)


                die("Can not connect: " . mysql_error());





                $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>";

                $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 >
            <th style='font-size:25px;'>Title</th>
            <th style='font-size:25px;'>Body</th>
            <th colspan=2 style='font-size:25px;'>Operation</th>
            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>";

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100