How to fetch data from database and insert inside of div tag

How do i fetch data from database and insert it inside of div tag in my code I have a table name PST in my database in i am inserting title and description after inserting title and description they should be inserted inside of

tag.Here’s the code help me plz.

<div class="a">

<div class="b">

        </div>
		</div>
<div class="a">
<div class="b">
        </div>

		</div>
		
	<div class="a">
<div class="b">
        </div>
		</div>	
<div class="a">
<div class="b">

        </div>
		</div>		
content	
<br><div class="a">
	<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>
</div>
</body>
</html>
<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("job",$con);
$postt=$_POST['pst'];
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("job", $connection);
$query = mysql_query("select * from describepost where pst like '$postt'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
echo "got it";
}
else
{
	echo "invalid usename or pwd";
}


?>

If this is new code that you’re writing, stop using the old mysql calls. It’s a waste of your time getting familiar with functions that have been removed from the current version of the language.

As for your question, I would simply retrieve the data as you have done in your PHP code, but using PDO calls instead of the obsolete mysql versions, and then draw the html and data from your PHP. So you’d draw all the html that comes before where you indicated “content”, then the PHP would draw the content, and then you’d separately draw the rest of the html. You can either do that by just exiting PHP using the normal closing and opening tags, or you could use echo() to output the html.

1 Like

Hello Droopsnoot you have given me one of the best ever suggestion but i have try lot of times to do the same thing and i am not getting any of the perfect result so i request you to give the solution with the code it would be a great help from your side.

OK.

<html>
<div class="a">

<div class="b">

        </div>
		</div>
<div class="a">
<div class="b">
        </div>

		</div>
		
	<div class="a">
<div class="b">
        </div>
		</div>	
<div class="a">
<div class="b">

        </div>
		</div>		
<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("job",$con);
$postt=$_POST['pst'];
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("job", $connection);
$query = mysql_query("select * from describepost where pst like '$postt'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
echo "got it";
// echo all the other content here
}
else
{
	echo "invalid usename or pwd";
}
?>
<br><div class="a">
	<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>

</div><div class="a">
<div class="b">
</div>
</div>
</body>
</html>

And, change all the database stuff to PDO.

Error occured
Undefined index: pst in C:\xampp\htdocs\job\div.php on line 52

That coming from the form you are submitting to go to that page, it needs an input named pst.

error has gone but it is not showing any of the inserted values inside of the page containing

tags

Can’t help with that, I don’t remember how mysql works, it’s such a thing of the past and so long since I used it. And I’m not inclined to go back and spend my time re-learning something that is obsolete.
The one who needs to spend some time learning is you, learning a present day method of communicating with your database, like PDO.
The good thing is that because people do actually use PDO, they will be more willing and able to help you with that.

You also need to provide more information, such as the purpose of the script/page, the structure of your tables, etc. Otherwise it’s just guesswork and blind stabs in the dark.

I am trying you to send the whole code to you but why is it not working so?

Let’s just take a step back and switch your php code from mysql_ to PDO, and then we can take it from there. The code you are using is not part of PHP anymore, and will only work with old versions of PHP.

Take a look at this SitePoint article: https://www.sitepoint.com/migrate-from-the-mysql-extension-to-pdo/. Partway through the article there is a section titled “Basic Querying” which has an example written in old mysql_ and also how that code would look like with PDO. Why don’t you use that as a guide and convert your code.

4 Likes

Have you expand this section of code:

if ($rows == 1) {
echo "got it";
// echo all the other content here
}

to echo all the stuff that the query retrieves?

3 posts were split to a new topic: Creating a Card Layout

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.