PDA

View Full Version : حرفه ای: کجای کار ایراد داره ؟



masiha68
چهارشنبه 18 بهمن 1391, 14:14 عصر
سلام به همگی
من یه فرم ساختم واسه ویرایش دسته بندی ها سایتم منتها با وجود اینکه ده ها بار کدها رو از اول نوشتم و فرم رو دوباره طراحی کردم بازم ارور میده . شما یه نگاهی بندازین ببین کجای کدم اشتباه

<?php require_once('../Connections/pop.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$lop=$_GET['idcat'];}
mysql_select_db($database_pop, $pop);
$query_showcat = "SELECT * FROM cat where idcat= $lop ";
$showcat = mysql_query($query_showcat, $pop) or die(mysql_error());
$row_showcat = mysql_fetch_assoc($showcat);
$totalRows_showcat = mysql_num_rows($showcat);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ویرایش دسته</title>
</head>

<body>
<form method="post" name="editcat">
<table width="400" border="0" >
<tr>
<td width="295" align="center">اسم دسته </td>
<td width="95" align="center"><a href="cat.php"><input type="button" value="انصراف" /> </a></td>
</tr>
<tr>
<td><input name="catneme" type="text" value="<?php echo $row_showcat['catname']; ?>" size="30" /> &nbsp;</td>
<td align="center"><input type="submit" value="ویرایش" name="editcat" /></td>
</tr>
</table>


</form>
</body>
</html>
<?php
mysql_free_result($showcat);
?>


اینم ارور
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Dead Space
چهارشنبه 18 بهمن 1391, 14:40 عصر
متغیر $lop مقدارش رشته ای هستش ؟
اگر هست پرسجو رو به این صورت تغییر بدید

$query_showcat = "SELECT * FROM cat where idcat= '$lop' ";

masiha68
چهارشنبه 18 بهمن 1391, 15:30 عصر
مگه توی پی اچ پی متغییر خودش شناسایی نمیشه (منظورم نوع متغییره) پس وقتی من دارم idcat رو بهش می دم خودش باید به int تبدیل بشه
شاید من اشتباه می کنم

Dead Space
چهارشنبه 18 بهمن 1391, 17:03 عصر
فکر کنم مقادیری که از متد GET میاد همه اول رشته ای هستن
می تونید این کار رو بکنید که مقدار حتما int بشه:

$lop = (int) $_GET['idcat'];

masiha68
چهارشنبه 18 بهمن 1391, 17:14 عصر
الان دیگه ارور نمی ده ولی خب چیزی هم نشون نمیده و چیزی رو هم اپدیت نمی کنه

masiha68
چهارشنبه 18 بهمن 1391, 23:40 عصر
به دشت پر ملال ما کسی (چرا) سر نمی زند ؟!!؟
جواب بدین خواهشا

MinusOne
پنج شنبه 19 بهمن 1391, 02:24 صبح
فایل pop.php رو چک کن احتمالا اشکال از اون باشه.

SlowCode
پنج شنبه 19 بهمن 1391, 07:10 صبح
سلام
به این صورت بنویس ببین حل میشه؟


$query_showcat = "SELECT * FROM cat where idcat= '". $lop ."' ";

Reza1607
پنج شنبه 19 بهمن 1391, 08:51 صبح
خط 33 تو همين اديتور برنامه نويس يعني اين خط

$lop=$_GET['idcat'];
رو ببريد خط بعد يعني بعد از بسته شدن آكولاد

masiha68
پنج شنبه 19 بهمن 1391, 09:42 صبح
سلام و صبح بخیر
رضا جان اون متغییر رو بردم بعد اکولاد تغییری نکرد
محسن من اون متغییر رو تبدیل کردم به رشته ولی بازم مشکل حل نشد . البته دیگه ارور نمی ده ولی توی تکست مقدار رو نشون نمیده
راستی فایل pop.php رو هم کنترل کردم مشکل از اون نبود
____
از دوستان کسی نظری نداره ؟

Reza1607
پنج شنبه 19 بهمن 1391, 10:01 صبح
متغيير

$query_showcat
رو چاپ كن ببين اون كوئري مورد نظرت هست يا نه

masiha68
پنج شنبه 19 بهمن 1391, 10:22 صبح
مشکل رو تقریبا پیدا کردم ولی بازم نمی دونم چه جوری حلش کنم
فهمیدنم که اصلا idcat از فرم قبلی (همون فرمی که اطلاعات رو می فرسته ) وارد این فرم ( فرم جاری ویرایش اطلاعات ) نمیشه
اینم فرم ایجاد دسته یه نگاهی به اینا بندازین ببینین چیزی دستگیرتون میشه

<?php require_once('../Connections/pop.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "createcat")) {
$insertSQL = sprintf("INSERT INTO cat (catname) VALUES (%s)",
GetSQLValueString($_POST['catname'], "text"));

mysql_select_db($database_pop, $pop);
$Result1 = mysql_query($insertSQL, $pop) or die(mysql_error());

$insertGoTo = "cat.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_pop, $pop);
$query_catrecord = "SELECT * FROM cat";
$catrecord = mysql_query($query_catrecord, $pop) or die(mysql_error());
$row_catrecord = mysql_fetch_assoc($catrecord);
$totalRows_catrecord = mysql_num_rows($catrecord);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>دسته بندی</title>
</head>

<body><div id="cat" align="right">
<form action="<?php echo $editFormAction; ?>" method="POST" name="createcat">
<table width="412" border="0">
<tr>
<td width="326"><input type="text" name="catname" width="100%" />


</td>
<td width="76"><input type="submit" value="ایجاد دسته جدید" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="createcat" />
<input type="hidden" name="idcat1" value="<?php echo $row_catrecord['idcat']; ?>" />
</form><br />
<div style="height:500px; overflow:auto;">
<table width="400" border="1" style="text-align:center">
<tr>
<td width="25">id</td>
<td width="212">اسم دسته</td>
<td width="69">حدف</td>
<td width="66">ویرایش</td>
</tr>
<?php do { ?>
<tr>
<td height="41"><?php echo $row_catrecord['idcat']; ?></td>
<td style="text-align:right"><?php echo $row_catrecord['catname']; ?></td>
<td><a class="active" target="_blank" onClick="window.open('catdel.php?id=<?php echo$row_catrecord['idcat'] ;?>','popupwindow','stat us=yes,scrollbal=yes,width=300,height=300'); return false;"><img src="../img/catdele.png" width="23" height="24" alt="حذف" /></a></td>
<td><a href="catedit.php?idcat<?php echo $row_catrecord['idcat']; ?> "><img src="../img/catedit.png" alt="remove" width="34" height="31" /></a></td>
</tr>
<?php } while ($row_catrecord = mysql_fetch_assoc($catrecord)); ?>
</table>

<br />
تعداد دسته های ثبت شده :
<?php echo $totalRows_catrecord ;?>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($catrecord);
?>

Reza1607
پنج شنبه 19 بهمن 1391, 10:42 صبح
تو خط 94 يك مساوي كم گذاشتين
اين رو

<td><a href="catedit.php?idcat<?php echo $row_catrecord['idcat']; ?> "><img src="../img/catedit.png" alt="remove" width="34" height="31" /></a></td>
به اين تغيير بدين

<td><a href="catedit.php?idcat=<?php echo $row_catrecord['idcat']; ?> "><img src="../img/catedit.png" alt="remove" width="34" height="31" /></a></td>

masiha68
پنج شنبه 19 بهمن 1391, 10:49 صبح
ممنون
جور شد
خطاهای منطقی .... ادم یه = رو فراموش می کنه پروژه دو روز عقب می مونه:عصبانی++: