Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:55:28+00:00 2026-05-29T13:55:28+00:00

<? $test1 = mysql_connect(localhost,username,pass); if (!$test1) { die(‘Could not connect: ‘ . mysql_error()); }

  • 0
<?
$test1 = mysql_connect("localhost","username","pass");
if (!$test1)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("database", $test1);
$letter = $_SERVER[REQUEST_URI];
$letter1 = substr($letter,6);
$query = "SELECT * FROM letter WHERE username='" . $letter1 . "'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
?>

<style type="text/css">
body {
    background-image: url('<? echo $row["backpic"]; ?>');
    background-attachment:fixed;
    margin-bottom:36px;
    }
</style>

That is my code for retrieving a field from the mysql database and setting that field as a background image (the field contains a url).

For some reason this code doesn’t work. I have checked all the values and they are supposed to be correct because this exact same code exists in another file and it works perfectly there.

Please help!


There is no error generated.

By the way, there is line of code that comes before all this: include(“connectval.php”);

There that file has the same code as this but different variable names and the substring part is not there. I don’t think that interferes with this code though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:55:29+00:00Added an answer on May 29, 2026 at 1:55 pm

    If this code works in a different file but not this one, it’s likely a path problem – are the URLs in the database fully qualified or relative?

    What does the generated HTML look like? What exactly is in the database?

    Steps I’d follow to debug this:

    (I assume by “it doesn’t work” you mean you don’t see a background image? If so, you should be explicit!)

    • Work backwards – The browser isn’t showing the image. Why?
    • The browser uses the image URL to load the image – is it correct in the source of the page?
    • If the URL is correct, copy/paste it into the address bar – does the image load?
    • If it’s not correct, look at what’s in the database and work out what you need to do to correct it.

    My guess is that urls in the database are in the form: /Images/Image.jpg which works fine when the PHP is alongside the Images folder but wrong when loaded from a different folder – try making them fully qualified (http://www.example.com/Images/Image.jpg). If you can’t change the database, add the http://www.example.com yourself in code.

    EDIT:

    As suggested in comments on OP by Jared Farrish:

    Try printing out $query. Copy/paste the string into MySQL Workbench or phpMyAdmin – Do you see the correct results?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$link = mysql_connect('localhost', $username, $password); if (!$link) { die('Could not connect: ' . mysql_error());
This is my code: <?php mysql_connect(localhost,*****,********) or die(Can't connect to DB); mysql_select_db(kroltan_main) or die(Can't
$objConnect = mysql_connect(localhost,root,) or die(mysql_error()); $objDB = mysql_select_db(Test); $strSQL = SELECT * FROM UserAddedRecord
code: <?php mysql_connect(localhost, bikemap, pedalhard) or die(mysql_error()); mysql_select_db(test) or die(mysql_error()); $data = mysql_query(SELECT *
I have the following code in php: <?php $con = mysql_connect(localhost,john,john); mysql_select_db(data, $con); if
I have the following code: <?php mysql_connect(localhost, root, ); mysql_select_db(coockie); $filename =excelreport.xls; $contents =
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Should this delete all records in my SQL table? <?php $con = mysql_connect(localhost,bikemap,pedalhard); if
In database.php I have: $db['default']['username'] = IS_PRODUCTION ? 'prodUsername' : 'localDevBoxUsername'; $db['default']['password'] = IS_PRODUCTION
Here is my code - <?php $host = localhost; // Host name $username =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.