Jump to content

Get image form db


JankaZ

Recommended Posts

Don't you already have another thread about this?

 

Anyway, a URL in the database is no different from any other string variable like name, email etc which means you don't have to do anything different to select the URL. To get it to show on the page you'll just need to select it from the database and put the value inside the scr attribute of an image tag.

 

If you're unfamiliar with HTML then it might be worth looking at a few tutorials on that first.

Link to comment
Share on other sites

It all depends ... if you're using sessions to login, I'm assuming you store the username, or user ID in a session, in which case you can simply access your users table and make a normal query using $_SESSION['username'] or $_SESSION['userID']

 

Such as:

$username=$_SESSION['username'];
$sql="SELECT * FROM USERS WHERE username=$username";
   $result=mysql_query($sql, $db);
while $row=mysql_fetch_array($result))
     {
echo "<img src=".$imgurl.">";
      }//end while

Link to comment
Share on other sites

I have litl problem with scrip. Clousing tag >

 

ERROR

"; } ?>

Sveiks Test. Iziet.

 

SCRIPT

<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Profils</title>
</head>  
<body>
<php
$username=$_SESSION['username'];
$sql="SELECT * FROM USERS WHERE username=$username";
   $result=mysql_query($sql, $db);
while $row=mysql_fetch_array($result))
     {
echo "<img src=".$imgurl."/>";
      }
?>
<p>Sveiks<b> <?=$_SESSION['Username']?><b>. <a href="logout.php">Iziet.</a></p>

Link to comment
Share on other sites

Agen ERROR

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/lockerz/public_html/projekts/index.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lockerz/public_html/projekts/index.php on line 13

 

$sql="SELECT * FROM USERS WHERE username=$username";
   $result=mysql_query($sql, $db);

Link to comment
Share on other sites

Seim error

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/lockerz/public_html/projekts/index.php on line 15

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lockerz/public_html/projekts/index.php on line 16

 

<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Profils</title>
</head>  
<body>
<php
$username=$_SESSION['username'];
// also remember to escape $vars that go into SQL:
$username = mysql_real_escape_string($username);
$sql="SELECT * FROM USERS WHERE username='$username'";
   $result=mysql_query($sql, $db);
while $row=mysql_fetch_array($result))
     {
echo "<img src=".$imgurl."/>";
      }
?>
<p>Sveiks<b> <?=$_SESSION['Username']?><b>. <a href="logout.php">Iziet.</a></p>

Link to comment
Share on other sites

Can you post up here your table layout in your MySQL database? Check it for typos. And should USERS be capitalized? Its generally good practice for your table names to be lowercased because SQL syntax is generally capitalized so its easy to distinguish between Syntax and values.

Link to comment
Share on other sites

1.Table Users

Rows 65kzf2095d984x5koaov.jpg

 

2.And ken you upgrade my loigin page plzzz

<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
 ?>
    
    <?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
 $username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    
 $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
    
    if(mysql_num_rows($checklogin) == 1)
    {
    	 $row = mysql_fetch_array($checklogin);
        $email = $row['EmailAddress'];
        
        $_SESSION['Username'] = $username;
        $_SESSION['EmailAddress'] = $email;
        $_SESSION['LoggedIn'] = 1;
        
    	 echo "<h1>Veiksmīgi</h1>";
        echo "<p>Mēs tevi pārsūtam uz profila lapu.</p>";
        echo "<meta http-equiv='refresh' content='=2;index.php' />";
    }
    else
    {
    	 echo "<h1>Kļūda</h1>";
        echo "<p>Atvaino tavs profils netika atrasts <a href=\"login.php\">Mēģini vēlreiz</a>.</p>";
    }
}
else
{
?>
<form method="post" action="login.php" name="loginform" id="loginform">
<fieldset>
	<label for="username">Tavs lietotajvards</label><br />
        <input type="text" name="username" id="username" /><br />
	<label for="password">Tava parole</label><br />
    <input name="password" type="password" id="password" /><br />
	<input type="submit" name="login" id="login" value="Ienākt" />   <INPUT TYPE="BUTTON" VALUE="Reģistrēties" ONCLICK="window.location.href='register.php'"> 
</fieldset>
</form>
    
   <?php
}
?>

 

If someone not loged in show login else redirect to home.php

3.And what i nide to place in home.php if someone not logen in then dont show page but redirect to login.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.