I have learn to make website using php and mysql from tutorial book
And I have some problem and I don't know how to do with it. :X
If anyone know about solution to fix it please help....

Here is my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>LOFO.in.th : LOST & FOUND (beta) PROJECT @KMITL</title>
<LINK REL="StyleSheet" HREF="css/style.css" TYPE="text/css" MEDIA=screen>
<meta http-equiv=Content-Type content="text/html; charset=tis-620">
</head>
<body>
<?php
//header("Content-Type: text/plain; charset=TIS-620");
include('config.inc.php');
function renHTML($strTemp)
{
	$strTemp=nl2br(htmlspecialchars($strTemp));
	return $strTemp;
}
$sql="SELECT * FROM lost WHERE showid=$bi";
$result=mysql_db_query($DBName,$sql);
$dbarr=mysql_fetch_array($result);
	
?>		
	
	<div id="navbox"><ul>
						<li class="logoa"></li>
						<li class="lost"><br />LOST</li>
						<li class="found"><br /><a href="#">FOUND</a></li>
					</ul>
	</div>
	<div id="lostbox">
					<div id="lost_desc">
					<?php echo renHTML($dbarr['name']);?>
						
						
						
					
					
	</div>
</body>
</html>

They say "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\AppServ\www\lofo\show_lost.php on line 19"
and when I put $dbarr=mysql_fetch_array($result) or die mysql_error(); instead...
They'll say "Parse error: syntax error, unexpected T_STRING in E:\AppServ\www\lofo\show_lost.php on line 19"

What happen to my code?
Anyone could help please?
I've been stuck with this error for a week...
So sad... :(
And sorry if my English is too bad...

Thank you very much,scodex.

Recommended Answers

All 7 Replies

Member Avatar for diafol

1. If you're using xhtml-strict, this needs to change to lower case and close:

<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />

How about:

$result=mysql_db_query($DBName,$sql);

To:

$result=mysql_query($sql);

Also check to see that your connection details in config.inc.php are correct.

$sql="SELECT * FROM lost WHERE showid=$bi";

You don't show where $bi is coming from.

I still have an error
I think config.inc.php are correct because I use it with another page and it work.
Here is config.inc.php

<?php	
$DBServer="127.0.0.1";
$DBName="lostdb";
$DBUsername="root";
$DBPassword="1234";
mysql_connect($DBServer,$DBUsername,$DBPassword)or die("Can't connect to dbserver");
mysql_select_db($DBName)or die("Can't connect to dbserver");
mysql_query("SET NAMES TIS620");
?>

$bi coming from

<a href="show_lost.php?showid=<?php echo $bi;?>" target="<?php echo $bi;?>">

from another page when click it'll go http://localhost/lofo/show_lost.php?showid=70
I think error come from mysql_fetch_array($result)....
I really don't know how to do with this :[

What is the value of $bi..? How do the get the value of $bi in the relevant page..? By what method $_GET or $_POST... Tell me.. we will clear it..

yep! there are code that $bi come from
on line 123 there have a link that's send value of $bi to show_lost.php
my algorithm of programming is very very beginner please help :X

<html>
<head><LINK REL="StyleSheet" HREF="css/style.css" TYPE="text/css" MEDIA=screen></head>
<body>
<?php
//header("Content-Type: text/plain; charset=TIS-620");
include("config.inc.php");
$sql="select *from lost ORDER BY id";
mysql_query("SET NAMES TIS620");
$dbquery=mysql_db_query($DBName,$sql);
$num_rows=mysql_num_rows($dbquery);
$i=0;
while($i<$num_rows){
	$row=mysql_fetch_array($dbquery);
	$lostid=$row["id"];
	$lostname=$row["name"];
	$losttype=$row["type"];
	$lostplace=$row["place"];
	$lostpic=$row["pic"];
	$lostday=$row["day"];
	$lostmonth=$row["month"];
	$lostyear=$row["year"];
	$lostdction=$row["dction"];
	$lostuser=$row["user"];
	$lostemail=$row["email"];
	$lostthumb=$row["thumb"];
	$newdesc=wordwrap($lostdction, 33, "\n", true);
	if ($i==$num_rows-1){
	$ai=$lostid;
	$an=$lostname;
	$at=$losttype;
	$apl=$lostplace;
	$ap=$lostpic;
	$ad=$lostday;
	$am=$lostmonth;
	$ay=$lostyear;
	$ads=$newdesc;
	$au=$lostuser;
	$ae=$lostemail;
	$ath=$lostthumb;
	if (strlen($ads>=10)){
	$ads=substr($ads,0,10);
	}
	}
	if ($i==$num_rows-2){
	$bi=$lostid;
	$bn=$lostname;
	$bt=$losttype;
	$bpl=$lostplace;
	$bp=$lostpic;
	$bd=$lostday;
	$bds=$newdesc;
	$bm=$lostmonth;
	$by=$lostyear;
	$bu=$lostuser;
	$be=$lostemail;
	$bth=$lostthumb;
	if (strlen($bds>=10)){
	$bds=substr($bds,0,10);
	}
	}
	if ($i==$num_rows-3){
	$ci=$lostid;
	$cn=$lostname;
	$ct=$losttype;
	$cpl=$lostplace;
	$cp=$lostpic;
	$cd=$lostday;
	$cm=$lostmonth;
	$cy=$lostyear;
	$cds=$newdesc;
	$cu=$lostuser;
	$ce=$lostemail;
	$cth=$lostthumb;
	if (strlen($cds>=10)){
	$cds=substr($cds,0,10);
	}
	}
	if ($i==$num_rows-4){
	$di=$lostid;
	$dn=$lostname;
	$dt=$losttype;
	$dpl=$lostplace;
	$dp=$lostpic;
	$dd=$lostday;
	$dm=$lostmonth;
	$dy=$lostyear;
	$dds=$newdesc;
	$du=$lostuser;
	$de=$lostemail;
	$dth=$lostthumb;
	if (strlen($dds>=10)){
	$dds=substr($dds,0,10);
	}
	}
	$i++;
}
?>		
					<table border="0">
						<tr>
							<td><div class="postit1"><br /><div class="hel1">&nbsp;#<?php echo $ai;?>&nbsp;<?php echo $an;?></div>
									<table border="0" class="inpost">
										<tr>
										<td><div class="thupic"><img src="<?php echo $ath;?>" width="90px" height="90px" /></div></td>
										<td><b>»ÃÐàÀ·:</b>&nbsp;<?php echo $at;?><br /><b>ʶҹ·Õè:&nbsp;</b><?php echo $apl;?><br /><b>Çѹ·Õè:</b> <?php echo $ad.'/'.$am.'/'.$ay?></td>
										</tr>
										</table>
										<table class="inpost">
										<tr>
										<td colspan="1"><b>ÃÒÂÅÐàÍÕ´:</b><br /><?php echo $ads;?><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">ÃÒÂÅÐàÍÕ´à¾ÔèÁàµÔÁ...</a>&nbsp;&nbsp;&nbsp;<a href="#">á¨é§¾º<O=</a></td>
										</tr>
										</table>
									
								</div></td>
							<td><div class="postit1"><br /><div class="hel1">&nbsp;#<?php echo $bi;?>&nbsp;<?php echo $bn;?></div>
									<table border="0" class="inpost">
										<tr>
										<td><div class="thupic"><img src="<?php echo $bth;?>" width="90px" height="90px" /></div></td>
										<td><b>»ÃÐàÀ·:</b>&nbsp;<?php echo $bt;?><br /><b>ʶҹ·Õè:&nbsp;</b><?php echo $bpl;?><br /><b>Çѹ·Õè:</b> <?php echo $bd.'/'.$bm.'/'.$by?></td>
										</tr>
										</table>
										<table class="inpost">
										<tr>
										<td colspan="1"><b>ÃÒÂÅÐàÍÕ´:</b><br /><?php echo $bds;?><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="show_lost.php?showid=<?php echo $bi;?>" target="<?php echo $bi;?>">ÃÒÂÅÐàÍÕ´à¾ÔèÁàµÔÁ...</a>&nbsp;&nbsp;&nbsp;<a href="#">á¨é§¾º<O=</a></td>
										</tr>
										</table>
									
								</div></td>
						</tr>
						<tr>
							<td><div class="postit1"><br /><div class="hel1">&nbsp;#<?php echo $ci;?>&nbsp;<?php echo $cn;?></div>
									<table border="0" class="inpost">
										<tr>
										<td><div class="thupic"><img src="<?php echo $cth;?>" width="90px" height="90px" /></div></td>
										<td><b>»ÃÐàÀ·:</b>&nbsp;<?php echo $ct;?><br /><b>ʶҹ·Õè:&nbsp;</b><?php echo $cpl;?><br /><b>Çѹ·Õè:</b> <?php echo $cd.'/'.$cm.'/'.$cy?></td>
										</tr>
										</table>
										<table class="inpost">
										<tr>
										<td colspan="1"><b>ÃÒÂÅÐàÍÕ´:</b><br /><?php echo $cds;?><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">ÃÒÂÅÐàÍÕ´à¾ÔèÁàµÔÁ...</a>&nbsp;&nbsp;&nbsp;<a href="#">á¨é§¾º<O=</a></td>
										</tr>
										</table>
									
								</div></td>
							<td><div class="postit1"><br /><div class="hel1">&nbsp;#<?php echo $di;?>&nbsp;<?php echo $dn;?></div>
									<table border="0" class="inpost">
										<tr>
										<td><div class="thupic"><img src="<?php echo $dth;?>" width="90px" height="90px" /></div></td>
										<td><b>»ÃÐàÀ·:</b>&nbsp;<?php echo $dt;?><br /><b>ʶҹ·Õè:&nbsp;</b><?php echo $dpl;?><br /><b>Çѹ·Õè:</b> <?php echo $dd.'/'.$dm.'/'.$dy?></td>
										</tr>
										</table>
										<table class="inpost">
										<tr>
										<td colspan="1"><b>ÃÒÂÅÐàÍÕ´:</b><br /><?php echo $dds;?><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">ÃÒÂÅÐàÍÕ´à¾ÔèÁàµÔÁ...</a>&nbsp;&nbsp;&nbsp;<a href="#">á¨é§¾º<O=</a></td>
										</tr>
										</table>
									
								</div></td>
						</tr>
						
								</table>
					
					</table>

</body>
</html>

let's run some standard debugging.

throw an:

echo $sql . "<br />";

right after line 17 to show the actual query being sent to the database, then run that query against the database in phpMyAdmin or whatever database management system you are using. If that also gives you an error then it must be the query, if not then there is an issue with your connection or the way you are selecting the database.

I do know that php.net is strongly suggesting to avoid using the mysql_db_query function as they are depricating it as of 5.3. If you read http://us3.php.net/manual/en/function.mysql-db-query.php, near the top is a good example of the recommended way of connecting and running a query.

when I put

echo $sql . "<br />";

after line 17

they will say SELECT * FROM lost WHERE showid=

why value of $bi don't show up?

thank you for everyone help.

Oh GOD!!!
I knew where the code go wrong
An error occured I use wrong variable...

the way to fix it is

Change :

$sql="SELECT * FROM lost WHERE showid=$bi";

To :

$sql="SELECT * FROM lost WHERE id=$showid";

:) Thank you all for helping me clear an error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.