JankaZ Posted March 31, 2010 Share Posted March 31, 2010 How can I get a user's image from the database if a member login through the session. And how ken i display image to page. When hy register in imgage url place images url. Database colon Users row imgurl Plzz help! Quote Link to comment Share on other sites More sharing options...
the182guy Posted March 31, 2010 Share Posted March 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 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 Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 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> Quote Link to comment Share on other sites More sharing options...
the182guy Posted April 1, 2010 Share Posted April 1, 2010 There is no open parenthesis in your while loop: while $row=mysql_fetch_array($result)) should be while($row=mysql_fetch_array($result)) Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 Nothing hapen seim ERROR "; } ?> Sveiks Test. Iziet. Quote Link to comment Share on other sites More sharing options...
the182guy Posted April 1, 2010 Share Posted April 1, 2010 You have: <php should be <?php Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 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); Quote Link to comment Share on other sites More sharing options...
the182guy Posted April 1, 2010 Share Posted April 1, 2010 That is invalid SQL. See mysql_error() You need to enclose a string value with quotes like // also remember to escape $vars that go into SQL: $username = mysql_real_escape_string($username); $sql="SELECT * FROM USERS WHERE username='$username'"; Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 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> Quote Link to comment Share on other sites More sharing options...
compguru910 Posted April 1, 2010 Share Posted April 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 1.Table Users Rows 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 Quote Link to comment Share on other sites More sharing options...
JankaZ Posted April 1, 2010 Author Share Posted April 1, 2010 Sory for Double post. But plzz help I newbie and whant make this script and lern mor! And sory for Bad English Im from Lavia Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.