...

View Full Version : sql error



mivec
04-13-2004, 05:13 AM
hi all,
i have tried doing something like a page browser where u have page numbers on top. and each page containing a maximum amount of contents.u will understand if u see the code and here it is:



switch ($_GET["mode"])
{
case "list":
$sql = "SELECT * FROM tblgallery username = '" .$_POST["txtUserID"] . "'";
$rs = mysql_query($sql);
$nRows = mysql_num_rows($rs);

/* Set the default records to be shown per page as 5 */
$pageSize = 6;

/* Page is not set then set it to page 1 */
if(!isset($_GET["page"]))
$page = 1;
else
$page = $_GET["page"];

$startPos = $page * $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
$sql .= ' LIMIT ' . $startPos . ', ' . $pageSize; //now break into paged sections
$rs = mysql_query($sql) or die('Error: ' . mysql_error());



echo('<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
echo(' <tr><td align=right><span class="nav">');

if ($page != 1) {
$prev = $page - 1;
echo '<span class="nav"><a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'">&lt;&lt;</a>';
}
else
echo ("<span class=\"nav\">&lt;&lt;");

$totalPage = $nRows / $pageSize;
for($i = 1; $i <= $totalPage; $i++) {
/* inactive page, don't add linking */
if ($i == $page){ echo '&nbsp;' . $i;}
/* page active, add linking */
else {echo '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>';}
}

if (($nRows % $pageSize) != 0) {
/* inactive page number */
if ($i == $page){ echo '&nbsp;' . $i; }
/* active page, linked */
else {echo '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>'; }
}

if( ($nRows - ($pageSize * $page)) > 0) {
$next = $page + 1;
echo '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $next . '">&gt;&gt;</a></span>';
}
else{
echo "&nbsp;&gt;&gt;</span>";
echo("</td>");
echo("</tr>");
echo("</table>");

echo('<table width="100%" border="0" cellspacing="1" cellpadding="4">');
while ($row = mysql_fetch_object($rs)) {
echo("<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
<td align=center border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>");
/* echo('<tr>
<td align=center><img src="$row->pic_Path" width="150" height="120"></td>
<td align=center class="bg"><img src="$row->pic_Path" width="150" height="120"></td>
</tr>');
echo('<tr>
<td align=center class="bg"><img src="$row->pic_Path" width="150" height="120"></td>
<td align=center ><img src="$row->pic_Path" width="150" height="120"></td>
</tr>');*/
}//close while


now the problem which i dun see is here:



$sql = "SELECT * FROM tblgallery username = '" .$_POST["txtUserID"] . "'";
$rs = mysql_query($sql);
$nRows = mysql_num_rows($rs);


and here


$startPos = $page * $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
$sql .= ' LIMIT ' . $startPos . ', ' . $pageSize; //now break into paged sections
$rs = mysql_query($sql) or die('Error: ' . mysql_error());


getting these warnings and error:



Notice: Undefined index: txtUserID in c:\program files\apache group\apache\htdocs\ewedding\photoupload.php on line 199

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ewedding\photoupload.php on line 201
Error: You have an error in your SQL syntax near '= '' LIMIT 0, 6' at line 1


i tried figuring whats the problem...so...but i can't see what's wrong...hope someone can help me.tahnks

raf
04-13-2004, 07:47 AM
you need to have a WHERE in your sql-condition (see one of your other threads). So change the selects to


$sql="SELECT * FROM tblgallery WHERE username = '".$_POST["txtUserID"]."'";

About the notice --> see one of your other threads or run a search here for errorhandling or errorreporting

mivec
04-13-2004, 02:50 PM
thanks raf for helping but i still don't get u..i mean, i practically see the same thing as i have posted. what's the * for?

raf
04-13-2004, 03:16 PM
The * got added by the forum for some reason ...

the difference is that you need to have a 'WHERE' at the start of your condition.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum