Color change to php commands

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 575 Views - Last Post: 04 July 2012 - 10:51 AM Rate Topic: -----

#16 demoloution  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-November 10

Re: Color change to php commands

Posted 04 July 2012 - 05:21 AM

link me a guide or something please if you can
Was This Post Helpful? 0
  • +
  • -

#17 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: Color change to php commands

Posted 04 July 2012 - 05:23 AM

you can start with the Manual: mysql_query() (esp. look at the example)
Was This Post Helpful? 0
  • +
  • -

#18 saravana pandian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-July 12

Re: Color change to php commands

Posted 04 July 2012 - 05:43 AM

View Postdemoloution, on 03 July 2012 - 10:50 AM, said:

also in my website i want to allow user to see some of my images
i use this code:

<?php
$con = mysql_connect("localhost","root","");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("photoshare", $con);

$Title = $_POST['Title'];
$Creator = $_POST['Creator'];


$result = mysql_query("SELECT Title, Creator FROM images WHERE Title = '$Title' OR  Title LIKE '%$Title%' 
OR Creator = '$Creator' OR  Creator LIKE '%$Creator'");


// escape from PHP ... ?>

<img src="<? echo $result; ?>">

<? // starting up PHP again...


//some code
mysql_close($con);
?>



but it doeasnt display me any image.It displays me the icon you have when the image dont load correctly or is broken.
Also i noticed that in my database, the images array doesnt have any elements in it.is this wrong?
My upload code works fine i think.
Any suggestions?

I THINK, THE VARIABLE NAME AND FIELD NAME OF YOUR DATABASE SHOULD NOT BE THE SAME. JUST TRY TO CHANGE THEIR NAME PLEASE. FOR EXAMPLE REPLACE $CREATOR BY $CREATORS AND ALSO $TITLE BY $TITLES.
Was This Post Helpful? 0
  • +
  • -

#19 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: Color change to php commands

Posted 04 July 2012 - 05:45 AM

@: nope. variable names do not matter in this case, as long as they are used consistently (which is the case here).
Was This Post Helpful? 0
  • +
  • -

#20 demoloution  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-November 10

Re: Color change to php commands

Posted 04 July 2012 - 07:36 AM

Ok i worked my code a little with a lot of help and now looks like this :

<?php
$con = new PDO( 'mysql:host=localhost;dbname=photoshare', 'root', '' );

if ( ! $con ) {
    die( 'Could not connect to the database' );
}

$stmt = $dbh->prepare( "SELECT path FROM images WHERE Title = :title OR Creator = :creator" );
$stmt->bindParam( ':title ', $_POST['Title'] );
$stmt->bindParam( ':creator', $_POST['Creator'] );
$stmt->execute();

$row = $stmt->fetch( PDO::FETCH_ASSOC );

echo '<img src="' . htmlentities( $row['path'] ) . '" />'; 
?>




the following error occurs:

Notice: Undefined variable: dbh in C:\xampp\htdocs\armen\searchImages.php on line 8

Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\retalis\searchImages.php on line 8

nevermind that my bad :P
Was This Post Helpful? 0
  • +
  • -

#21 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: Color change to php commands

Posted 04 July 2012 - 10:51 AM

well, line #2 says $con, not $dbh.

lines #4-6 are superfluous. if PDO fails to connect, it throws a PDOException.

lines #9-10 should be ->bindValue(), not ->bindParam() (that is incorrect in the Manual, too)

lines #13-15 can be simplified to printf('<img src="%s">', htmlentities( $stmt->fetchColumn() ));

and the SQL should be added LIMIT 1 to avoid unnecessary data transfer.

This post has been edited by Dormilich: 04 July 2012 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2