link me a guide or something please if you can
20 Replies - 575 Views - Last Post: 04 July 2012 - 10:51 AM
#17
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)
#18
Re: Color change to php commands
Posted 04 July 2012 - 05:43 AM
demoloution, 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:
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 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.
#19
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).
#20
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 :
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
<?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
#21
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.
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
|
|

New Topic/Question
Reply





MultiQuote


|