Jump to content

[SOLVED] I can´t load image !


cauca

Recommended Posts

Hello,

Fist i want introduce myself,

My name´s Cauca I live in Brasil;

I`m a student (Devoloped sistem to Internet).

I want help this forum with ask and question !

Thi first I have ask ;-) !

 

I´m trying loader a image with code bellow:

-> I have a image in BLOB format in MySQL;

-> I recover this img in a variable with php and show it with echo !

EX: I have a select ...

echo $img;

If I access this page direct by localhost , the img is showed with no error,

But what I want is: thi img be showed by the innerHTML

I tray

document.getElementById("ret_teste").innerHTML = "<img src='teste.php'>";

and

document.getElementById("ret_teste").innerHTML = xmlHttp.responseText

off course that I have a Ajax connection with all function ok,

I´m having a problem to mount a img in this parameters;

 

Thank´s for help me

 

God Bless us

Cauca

Link to comment
Share on other sites

Thank´s for read the topic !

 

//Code php

 

include_once("conectadb.php");

 

$teste = $_GET['teste'];

 

$query="select * from user where user_name like '%$teste%'";

 

$select = mysql_query($query);

while ($linha = mysql_fetch_array($select)){

 

$img = $linha['user_img'];

 

echo $img;

 

}

 

?>

 

//CODE AJAX

 

function teste(){

 

var inp_val = frm.inp_cont.value

 

var url="teste.php"

url=url+"?teste="+inp_val

url=url+"&sid="+Math.random()

xmlHttp.open("GET",url,true)

xmlHttp.onreadystatechange=stateChanged_r

xmlHttp.send(null)

 

function stateChanged_r()

{

document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>";

 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("ret_teste").innerHTML = "<img src='teste.php'>";

}

}

 

// the html code

 

 

 

<form name="frm">

Procurar:<input type="text" name="inp_cont" onkeyup="teste(this)"><br>

</form>

 

THANKS

 

GOD BLESS

PAULOCAUCA

 

 

Link to comment
Share on other sites

First, please wrap your code in the code tags by clicking on the # button.

 

I suggest trying a slightly different approach. You don't even need to use AJAX. Try this:

 

JavaScript:

function teste(){
  document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>";
  var inp_val = frm.inp_cont.value
  var url="teste.php"
  url=url+"?teste="+inp_val
  url=url+"&sid="+Math.random()
  document.getElementById("ret_teste").innerHTML = "<img src='"+url+"'>";
}

Link to comment
Share on other sites

sorry for the large code, sorry too because I can´t find a #button !

 

Thank´s for the help,

 

I try you code and the result is ok !

I take you code and put only this "<img src='"+url+"'>";

the result was the same result.

 

Both return only one image at a time!

I have in the DataBase personals name. I call the DB with LIKE %user_name%

I want return for example every images that name start with PA.

 

God Bless

Paulo Cauca

 

 

 

Link to comment
Share on other sites

Try this:

 

teste.php:

<?php
include_once("conectadb.php");
if ($_GET['action']=="img"){
  $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'";
  $result = mysql_query($query);
  $row = mysql_fetch_assoc($result);
  echo $row['user_img'];
}
else{
  $teste = $_GET['teste'];
  $query="select user_id from user where user_name like '%$teste%'";
  $select = mysql_query($query);
  while ($linha = mysql_fetch_assoc($select)){
    $user = $linha['user_id'];
    echo "<image src='teste.php?action=img&user_id=$user'>";
  }
}
?>

JS/AJAX:

function teste(){
  document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>";
  var inp_val = frm.inp_cont.value;
  var url="teste.php?action=users&teste="+inp_val;
  xmlHttp.open("GET",url,true);
  xmlHttp.onreadystatechange=stateChanged_r;
  xmlHttp.send(null);
  function stateChanged_r(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("ret_teste").innerHTML = xmlHttp.responseText;
    }
  }
}

Link to comment
Share on other sites

Hello, good morning ...

I put the code online in de web visit please:

www.barahinformatica.com.br/testimgfile/

 

Try type in  "Procurar:" the names above:

 

Paulo Roberto

Patricia Renata

Patrick Teste

Cristina Oliveira

Margarida Flor

 

If you starting type letter "P" the function need return Paulo's image, Patricia's image and Patrick's image.

 

Than´k

 

God Bless

PauloCauca

 

 

Corin Falador

Link to comment
Share on other sites

ok !!!

here is the code:

index.php

<html>
<head>
<script language="javascript">

var xmlHttp = false;

try {
xmlHttp = new ActiveXObject("Msxm12.XMLHTTP")
}
catch (e){
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (E){
xmlHttp = false
}
}

if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
	xmlHttp = new XMLHttpRequest ()

}


function teste(){
  document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>";
  var inp_val = frm.inp_cont.value;
  var url="teste.php?action=users&teste="+inp_val;
  xmlHttp.open("GET",url,true);
  xmlHttp.onreadystatechange=stateChanged_r;
  xmlHttp.send(null);
  function stateChanged_r(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("ret_teste").innerHTML = xmlHttp.responseText;
    }
  }
}

function inserir(){

var ins_name = insert_values.ins_name.value
var ins_file = insert_values.ins_file.value

var url="insert.php"
url=url+"?ins_name="+ins_name+"?ins_file"+ins_file
url=url+"&sid="+Math.random()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChanged_i
xmlHttp.send(null)

function stateChanged_i() 
{ 
document.getElementById('ret_insert').innerHTML = "<img src='./loader.gif'>";

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("ret_insert").innerHTML=xmlHttp.responseXML('Content-Type',"text/xml") 

} 
}

}

</script>

</head>	
<body>

<table align="center">
<tr>
<td>
<form name="insert_values" action="up.php" method="post">
Nome:<input type="text" name="ins_name">
Arquivo:<input type="file" name="ins_file">
<input type="submit" value="enviar"">
</form>
</td>
</tr>

<tr>
<td><div id="ret_insert"</div>
</td>	
</tr>

<tr>
<td colspan="2" align="center">
	<form name="frm">
		Procurar:<input type="text" name="inp_cont" onkeyup="teste(this)"><br>
	</form>
</td>
</tr>

</table>

<div id="ret_teste" align="center"></div>


</body>

</html>

 

teste.php

 

<?php
include_once("conectadb.php");
if ($_GET['action']=="img"){
  $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'";
  $result = mysql_query($query);
  $row = mysql_fetch_assoc($result);
  echo $row['user_img'];
}
else{
  $teste = $_GET['teste'];
  $query="select user_id from user where user_name like '%$teste%'";
  $select = mysql_query($query);
  while ($linha = mysql_fetch_assoc($select)){
    $user = $linha['user_id'];
    echo "<image src='teste.php?action=img&user_id=$user'>";
  }
}
?>

 

 

Thank's

 

God Bless man

Paulo

Link to comment
Share on other sites

OK, there's a problem with the query that gets the image. To test it, I went to:

http://www.barahinformatica.com.br/testimgfile/teste.php?action=users&teste=pa

and it almost shows three images. If you right-click on those images and select view image, you'll get this:

http://www.barahinformatica.com.br/testimgfile/teste.php?action=img&user_id=1

along with this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/barahinf/public_html/testimgfile/teste.php on line 6

 

So, the problem is somewhere in here:

  $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'";
  $result = mysql_query($query);
  $row = mysql_fetch_assoc($result);

Link to comment
Share on other sites

yessss I fund where are wrong :

The select was missing this

$query = "SELECT user_img [b]from user[/b] WHERE user_id = '{$_GET['user_id']}'";

 

yess

Thank's man for all

I'm lunch now srsrs

God Bless

 

Paulo Cauca

Link to comment
Share on other sites

LOL! That's funny, that was my mistake! Glad it works!

 

You may want to add a piece in the JS function that checks if the user input is blank, because if you leave it like it is and there ends up being a lot of pictures, it may take a long time to load.

 

By the way, I love your country. My wife and I spent a week in Rio de Janeiro this past February and we loved it. Plus my favorite F1 driver is Filipe Massa!

Link to comment
Share on other sites

Ok now I'll left the code more strong.

 

You came to Rio de Janeiro, is a beautiful place to visit, but have a lot of beautiful beach in other states of Brasil , for exemple BOMBINHAS - Santa Catarina, or SALVADOR - Bahia, in NORDESTE'S beach in so beautiful too !

 

Thank's for all,

God Bless you and your wife !

see you in the forum

Paulo Cauca

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.