Re: I am confused to mysql_query.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, August 1, 2007 1:23 am, Patrik Hasibuan wrote:
> This sql string produces proper output in my MySQL-Query:
> select image_src from products where product_id='10';
> the output is:
> gambarproduk/0/10/1.jpg
>
> But my php code does not produce anything.
>
> Please tell me what is my mistake.
> ===
> <?php
> if (isset($pid)){

//None of the following 7 lines are directly related to your current
problem...
Where did $pid come from?
Is this from GET or POST?
You should turn register_globals OFF.
You should filter this input.
You should escape this before you output it to MySQL.
Start reading here:
http://phpsec.org/

> 	$koneksi=mysql_connect("127.0.0.1","root","mysuccess");
if (!$koneksi) die("MySQL database is down. Please try later.");
> 	$stringsql="select style,
> 						description,
> 						price
> 					from styles
> 					where product_id='$pid';";
> 	$hsl=mysql_query("$stringsql","$koneksi");
"$stringsql" is silly.  Just use $stringsql

if (!$hsl){
  error_log(mysql_error($koneksi));
  die("Query failed.  Check error log.");
}

> 	while ($brs=mysql_fetch_row($hsl)){
> 		list($edisi,$deskripsi,$harga)=$brs;

Might as well do:
while (list($edisi,$deskripsi,$harga)=mysql_fetch_row($hs1)){

and avoid having the $brs PHP array waste.

> 	}
>
/////> 	$konek=mysql_connect("127.0.0.1","root","mysuccess");

You do NOT need to connect to the same database/user/pass a second
time.  Ever.  Just use the same connection.

Building up a connection is relatively expensive.

> 	if ($konek){
> 		echo "konek berhasil <br>";

Did this output happen?
You should have something error out if $konek is false, anyway.
Except you shouldn't have $konek at all, so never mind.

> 		$sqlgbr="select image_src
> 					from products
> 					where product_id='$pid';";
> 		echo "$sqlgbr <br>";
> 		$hslgbr=mysql_query("$sqlgbr","$konek");
> 		if (!$hslgbr){
> 			echo "query gambarproduk tidak berhasil <br>";
> 		}elseif ($hslgbr){
> 			echo "array gambar";
> 		}

This is more like it.
But !$hslgbr and $hslgbr are binary choices, so you really don't need
the second "if (...)" part.  Just a simple "else" will do the trick.

> 		while ($brsgbr=mysql_fetch_row($hslgbr)){
> 			list($gambarproduk)=$brsgbr;
> 			echo "urlgambar: $gambarproduk <br>";
> 		}
> 	}
> }
> ?>

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux