Skip to main content
Inspiring
February 15, 2007
Question

image background

  • February 15, 2007
  • 3 replies
  • 388 views
I have a php file that i want to add a image background to it. I tried with html code and i could preview it on my web server but when i try view in my browser it just keeps giving me errors like, "unexpected '<' on line 23 , and so on.
How can i add an image as a background in php ?

Thanks everyone
This topic has been closed for replies.

3 replies

Inspiring
February 16, 2007
Never mind. Got it. Should have paid more attention. Your Code worked just fine.
Onemore question. is there a code where when users can click to send a message to a board and when submitted , instead of taking to the "successfully sent page" it takes you to the board show the messages.

here's my example. Of what i don't want.
http://therainbowpride.com/myphptests/add_entry.php


this is the blog:

http://therainbowpride.com/myphptests/view_blog.php

of course i will be removing the edit/delete buttons from the public


ty so much again

Inspiring
February 15, 2007
hey again. I did what u told me :


here -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add a Blog Enty</title>
<style type="text/css">
body {
background-image: url( http://i68.photobucket.com/albums/i15/luishicks/newtest00010001.jpg);
background-repeat: no-repeat;
}
</style>
</head>

<body>
<?php // Script 12.5 - add_entry.php
// This script adds a blog entry to the datadase.

// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) { // Handle the form.

// Connect and select.
if ($dbc = @mysql_connect ('localhost', 'therainb', 'twocats')) {

if (!@mysql_select_db ('test')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}

} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error(). '</b></p>');
}

// Define the query.
$query = "INSERT INTO blog_entries (blog_id, title, entry, date_entered) VALUES (0, '{$_POST['title']}', '{$_POST['entry']}', NOW())";

// Execute the query.
if (@mysql_query ($query)) {
print '<p>The blog entry has been added.</p>';
} else {
print "<p>Could not add hte entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}

mysql_close();

}
// Display the form.
?>


<form action="add_entry.php" method="post">
<p>Entry Title: <input type="text" name="title" size="40" maxsize="100" /></p>
<p>Entry Text: <textarea name="entry" columns="40" rows="5"></textarea></p>
<input type="submit" name="submit" value="Add to the Blog!" />
</form>
</body>
</html>


but it didn't work.

is that right?
Participant
February 15, 2007
For a background image I would create a .css file and link it to the PHP page.

The code would look something like what's below, with the "imagefolder being whatever directory your image is in and the " imagename" being the name of the image. As far as the positioning goes you might need to play around with it a bit.

.pagebg {

background-image: url(imagefolder/imagename.jpg);
background-repeat: no-repeat;
background-position: left top;
}


Hope that helps
Inspiring
February 15, 2007
Thanks Mds14, this is my code. Where would i place the bg code ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add a Blog Enty</title>
</head>
<body>
<?php // Script 12.5 - add_entry.php
// This script adds a blog entry to the datadase.

// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) { // Handle the form.

// Connect and select.
if ($dbc = @mysql_connect ('localhost', 'therainb', 'twocats')) {

if (!@mysql_select_db ('test')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}

} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error(). '</b></p>');
}

// Define the query.
$query = "INSERT INTO blog_entries (blog_id, title, entry, date_entered) VALUES (0, '{$_POST['title']}', '{$_POST['entry']}', NOW())";

// Execute the query.
if (@mysql_query ($query)) {
print '<p>The blog entry has been added.</p>';
} else {
print "<p>Could not add hte entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}

mysql_close();

}
// Display the form.
?>


<form action="add_entry.php" method="post">
<p>Entry Title: <input type="text" name="title" size="40" maxsize="100" /></p>
<p>Entry Text: <textarea name="entry" columns="40" rows="5"></textarea></p>
<input type="submit" name="submit" value="Add to the Blog!" />
</form>
</body>
</html>