/    Sign up×
Community /Pin to ProfileBookmark

plz help php ms sql

i could not post follwing values in data base and when press edit button only first word is retrieved in text box not second, plz solve both problems, thanks in advance , i am pasting both file codes.

<?php
/* //////////////////////////////////////////////////
SCRIPT TYPE: Class
SCRIPT NAME: Categories
AUTHOR: shahid
WRITTEN ON: 03-May-2008
*
/
include_once ‘db.class.php’;

class categories extends db{

var $procName;
var $arrResult;
var $recCategories;
var $arrInsert;
var $arrUpdate;
var $arrValues;
var $errMsg;
var $categoryNames;

function categories(){

// ///categories_insert 1,’ssss’,’desc’,1,1,1,’6/4/2008′,0,’6/4/2008′,’ssstitle’,0
$this->arrInsert = array(“name”,”desc”,”title”,”logopath”,”lang”,”published”,”deleted”,”parentid”,”createdbyid”,”publisheddate”,”createddate”);

$this->arrUpdate = array(“id”, “name”, “desc”, “published”,”publisheddate”, “deleted”,”title”,”logopath”,”parentid”);

if($this->con==NULL){ $this->gConnect(“localhost”,”admin”,”admin”,”cellcamshop”);}

$this->errMsg = “”;

$this->categoryNames = array(“0″=>”Select…”);

}

function getAllCategories($lang){
try
{

$this->recCategories = mssql_query(“select * from categories where lang=”.$lang,$this->con);
while ($row = mssql_fetch_row($this->recCategories))
{
$this->arrResult[] = array( //for category.tpl
“id” => $row[0],
“Name” => $row[1],
“Description” => $row[2],
“Title” => $row[3],
“logopath” => $row[4],
“Published” => $row[6],
“Deleted” => $row[7],
“parentid” => $row[8],
“createdbyid” => $row[9] );

//
}

return $this->arrResult;
}
catch(Exception $ex)
{
unset($this->categoryNames);
$this->errMsg = “Category selection failed! “.$ex;
}
}

function getCategoriesName($lang){
try
{
$this->recCategories = mssql_query(“select * from categories where lang=”.$lang.” order by id”,$this->con);

for ($i = 0; $i < mssql_num_rows( $this->recCategories ); $i++)
{
$row = mssql_fetch_row($this->recCategories);
$this->categoryNames[$row[0]] = $row[3];
}

return $this->categoryNames;
}
catch(Exception $ex)
{
unset($this->categoryNames);
$this->errMsg = “Category name selection failed! “.$ex;
}
}

function addCategoriesDetails($valuesArray){
echo “<br>inserting<br>”;
try
{

$this->arrValues = $valuesArray;

$sp = mssql_init(“dbo.categories_insert”); // stored proc name

// ///echo “<BR> in TRY <br>”;
// $this->arrInsert = array(“name”,”desc”,”title”,”logopath”,”lang”,”published”,”deleted”,”parentid”,”createdbyid”,”publisheddate”,”createddate”);
mssql_bind($sp, “@”.$this->arrInsert[0], stripslashes($this->arrValues[0]), SQLVARCHAR);
mssql_bind($sp, “@”.$this->arrInsert[1], stripslashes($this->arrValues[1]), SQLVARCHAR);
mssql_bind($sp, “@”.$this->arrInsert[2], stripslashes($this->arrValues[2]), SQLVARCHAR);
mssql_bind($sp, “@”.$this->arrInsert[3], stripslashes($this->arrValues[3]), SQLVARCHAR);
mssql_bind($sp, “@”.$this->arrInsert[4], stripslashes($this->arrValues[4]), SQLINT1);
mssql_bind($sp, “@”.$this->arrInsert[5], stripslashes($this->arrValues[5]), SQLBIT);
mssql_bind($sp, “@”.$this->arrInsert[6], stripslashes($this->arrValues[6]), SQLBIT);
mssql_bind($sp, “@”.$this->arrInsert[7], stripslashes($this->arrValues[7]), SQLINT1);
mssql_bind($sp, “@”.$this->arrInsert[8], stripslashes($this->arrValues[8]), SQLINT1);
mssql_bind($sp, “@”.$this->arrInsert[9], stripslashes($this->arrValues[9]), SQLVARCHAR);
mssql_bind($sp, “@”.$this->arrInsert[10], stripslashes($this->arrValues[10]), SQLVARCHAR);

print_r($sp);

mssql_execute($sp);

mssql_close($this->con);

$this->errMsg = “New Category inserted successfully.”;
}
catch(Exception $ex)
{
$this->errMsg = “Category insertion failed! “.$ex;
}

}

function validateValues($arrValues)
{
$flag = 0;
echo “<br>validating 1 <br>”;
print_r($arrValues);
echo “<br>validating 2 <br>”;
if(count($arrValues)>0){
foreach($arrValues as $key=>$val)
{
echo “invalid==”.$val;echo “<br>”;
if($val != “”)
{
$flag = 1;
$this->errMsg = “true hea.”;
// ///echo “<br>trrrrr<br>”;
}
else
{
$this->errMsg = “Must enter “.$key;
$flag = 0;
break;
// ///echo “<br>flsss<br>==$val<br>”;
}
}echo “<br>”;
echo “in validate ==”.$flag;echo “<br>”;
}// ///if

return $flag;
}
function updateCategoriesDetails($valuesArray){
echo “updating”;
try{

$this->arrValues = $valuesArray;

$sp=” update dbo.categories set “.$this->arrUpdate[1].”='”.$this->arrValues[1].”‘,[“;
$sp.=$this->arrUpdate[2].”]='”.$this->arrValues[2].”‘,”;
$sp.=$this->arrUpdate[3].”=”.$this->arrValues[3].”,”;
$sp.=$this->arrUpdate[4].”=”.$this->arrValues[4].”,”;
$sp.=$this->arrUpdate[5].”=”.$this->arrValues[5].”,”;
$sp.=$this->arrUpdate[6].”='”.$this->arrValues[6].”‘,”;
$sp.=$this->arrUpdate[7].”='”.$this->arrValues[7].”‘,”;
$sp.=$this->arrUpdate[8].”=”.$this->arrValues[8];
$sp.=” where “.$this->arrUpdate[0].”=”.$this->arrValues[0];
echo “sp==”.$sp;
echo “<br>”;
$sp = mssql_query($sp,$this->con );
mssql_close($this->con);

$this->errMsg = “Selected Category updated successfully.”;
}
catch(Exception $ex)
{
$this->errMsg = “Category updation failed! “.$ex;
}
}

function getCategoryById($idd){
try
{
// ///echo “in get categories==”.$this->con.”==”;
if($idd==”) $idd=0;

$this->recCategories = mssql_query(“select * from categories where lang=1 and id=”.$idd,$this->con);
while ($row = mssql_fetch_row($this->recCategories))
{
$this->arrResult[] = array(
“id” => $row[0],
“Name” => $row[1],
“Title” => $row[3],
“Description” => $row[2],
“logopath” => $row[4],
“Published” => $row[6],
“Deleted” => $row[7],
“parentid” => $row[8],
“createdbyid” => $row[9],
“publisheddate” => $row[10],
“createddate” => $row[11] );

// ///$this->categoryNames[]=array($row[0]=>$row[3]);
}

return $this->arrResult;
}
catch(Exception $ex)
{
unset($this->categoryNames);
$this->errMsg = “Category selection by id failed! “.$ex;
}
}
}

?>

///////////////////////////////////////////////////////////////

php file
///////////////////////////////////////////////

<?php
require(‘libsSmarty.class.php’);
require_once(‘classescategories.class.php’);
$smarty = new Smarty();

$category = new categories();

// /// assing some default values
$smarty->assign(‘hiddenOption’,$_GET[‘UPNW’]);// ///UPNW 1 = new , 2= edit, 3= view
$smarty->assign(‘publisheddate’,date);
$smarty->assign(‘createddate’,date);
$smarty->assign(‘createdbyid’,’1′);
$smarty->assign(‘lang’,’1′);
///////////////////////////////////////////////////////////////
/////select categories to use as parent
$items_lis = $category->getCategoriesName(1);
$smarty->assign(‘parentCategories’, $items_lis);
$smarty->assign(‘categoryTitle’,’New Category Registration’);
///////////////////////////////////////////////////////////////

$pub=0;
if($_REQUEST[“published”]==’on’)
$pub = 1;
else
$pub = 0;

$del=0;
if($_REQUEST[“deleted”]==’on’)
$del = 1;
else
$del = 0;

////////////////////////////////////////////////////

// /// save the new category
if($_GET[‘UPNW’]==’1′ || $_REQUEST[“UPNW”]==’1′) // ///new
{
echo “<br>in new pub=”.$_REQUEST[“published”];

$arrValues = array($_REQUEST[“name”],$_REQUEST[“description”],$_REQUEST[“title”],$_REQUEST[“logopath”],$_REQUEST[“lang”],$pub,$_REQUEST[“deleted”],$_REQUEST[“parentid”],$_REQUEST[“createdbyid”],$_REQUEST[“publisheddate”],$_REQUEST[“createddate”]);
if( $category->validateValues($arrValues) != false)
{
$category->addCategoriesDetails($arrValues);
$smarty->assign(“StandardMsg”,$category->errMsg);
}
else
{
$smarty->assign(‘StandardMsg’,”);
}
unset($arrValues);
}
else if($_GET[‘UPNW’]==’2′ || $_REQUEST[“UPNW”]==’2′)
{
// /// Edit

$arrUpdate = array($_REQUEST[“idd”],$_REQUEST[“name”],$_REQUEST[“description”],$pub,$_REQUEST[“publisheddate”],$del
,$_REQUEST[“title”],$_REQUEST[“logopath”],$_REQUEST[“parentid”]);

$smarty->assign(‘categoryTitle’,’Edit Category Registration’);
if( $category->validateValues($arrUpdate)!=0 )
{
echo “b4 calling <br>”;
print_r($arrUpdate);
echo “<br>”;
$category->updateCategoriesDetails($arrUpdate);
$smarty->assign(“StandardMsg”,$category->errMsg);
}
else
{
$smarty->assign(“StandardMsg”,””);
}
unset($arrValues);

// ///selected category to edit
$items_list = $category->getCategoryById($_GET[“idd”]);
$smarty->assign(‘myArray1’, $items_list);

}
else if($_GET[‘UPNW’]==’3′ || $_REQUEST[“UPNW”]==’3′)// ///view
{
$smarty->assign(‘categoryTitle’,’Category Registration Detail’);
// ///selected category to edit
$items_list = $category->getCategoryById($_GET[“idd”]);
$smarty->assign(‘myArray1’, $items_list);

}
// ///echo “<br><br>”.$category->errMsg;

print_r($arrValues);

$smarty->display(‘newcategory.tpl’);
?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@muhammad_shahidauthorMay 27.2008 — how i can edit thread
Copy linkTweet thisAlerts:
@SyCoMay 30.2008 — Editing it timed out and is only available for a limited time. Post it again but please use PHP tags.
×

Success!

Help @muhammad_shahid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...