I have created an admin panel in which I have used the PHP, I have a problem in the edit part, will you help me,
I send you my code
<?php
include_once('includes/header.php');
include_once('includes/sidebar.php');
include_once 'function.php';
$crud = new CRUD();
if(isset($_GET['delete_id']) && isset($_GET['table'])){
$crud->deleteRows($_GET['delete_id'],$_GET['table']);
}
if(isset($_POST['update']))
{
extract($_POST);
$crud->updategiftCategory($_GET['id'],$_POST['giftCategory']);
$goto = 'giftCategory.php';
echo '<script type="text/javascript">
window.location.href="'.$goto.'"
</script>';
}
?>
<center>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Category
<small>Category</small>
</h1>
</section>
<!-- Main content -->
<section class="content">
<!-- SELECT2 EXAMPLE -->
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Edit Category</h3>
<!-- <div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
</div>-->
</div>
<!-- /.box-header -->
<?php
$result = $crud->getgiftCategoryById($_GET['id']);
$row = mysql_fetch_array($result);
?>
<div class="box-body">
<form action="#" method="POST">
<div class="col-md-12">
<!-- form start -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Category Name</label>
<input type="hidden" name="id" value="<?php echo $row['id']?>">
<input type="text" class="form-control" name="category" value="<?php echo $row['category']?>">
</div></div>
</div>
</div>
<div class="box-footer">
<input type="submit" class="btn btn-primary" name="update" value="Update">
</div>
</form>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
Please post your code here so we’re able to see how far you’ve got, then describe the problem you’re having in greater detail.
this page is edit_category.php
giftCategory.php
<?include_once 'includes/header.php';
include_once 'includes/sidebar.php';
include_once 'function.php';
$crud = new CRUD();
if(isset($_GET['delete_id']) && isset($_GET['giftCategory']))
{
$crud->deletegiftCategory($_GET['delete_id'],$_GET['giftCategory']);
mysql_query($sql_query);
}
if(isset($_POST['update']))
{
$id = $_POST['edit_id'];
$category = $_POST['gift_Category'];
$crud->updategiftCategory($category,$id);
}
?>
<script type="text/javascript">
function delete_id(id,giftCategory)
{
if(confirm('Sure to Delete ?'))
{
window.location.href='giftCategory.php?delete_id='+id+'&giftCategory='+giftCategory;
}
}
</script>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<div style="float:right;margin-top: 46px;"><a href="addGiftCategory.php" class="btn btn-primary">Add Category</a></div>
<h1 class="page-header">Gift Category</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Gift Category List
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>S.No</th>
<th>Gift Category</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
$res = $crud->getGiftCategory();
if(mysql_num_rows($res)>0)
{
while($row = mysql_fetch_array($res))
{
?>
<tr class="odd gradeX">
<td><? echo ++$id;?></td>
<td><? echo $row['category'];?></td>
<td><? $id = $row['id'] ?>
<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-info dropdown-toggle">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="edit_category.php?id=<?php echo $row['user_id'];?>">edit</a></li>
<?= "<a href=\"javascript:delete_id('$id', 'giftCategory');\"><i class=\"fa fa-remove fa-fw\"></i></a>"; ?></td>
</tr>
<? } } ?>
</tbody>
</table>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</div>
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable({
responsive: true
});
});
</script>
function.php
public function addGiftCategory($category){
mysql_query("INSERT INTO giftCategory(category) VALUES('$category')");
}
public function getgiftCategory(){
return mysql_query("SELECT * FROM giftCategory order by id ASC");
}
public function updategiftCategoryById($id,$category){
mysql_query($this->connect(),"UPDATE giftCategory SET category='".$category."',modified = NOW() WHERE id=".$id." ");
}
public function getgiftCategoryById($id){
return mysql_query("SELECT * FROM giftCategory WHERE id=".$id." ");
}
this my code first page is edit_Category.php
Second is gift category.php
and there is the function.php
the error is
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in on line 45
When trying to connect to MySql either a successful MySql Object or a Boolean false is returned on failure.
Check the connection and ensure Host, UserName, PassWord, etc are all correct.
Edit:
Use PHP gettype( $mysqlConnection ); to view the returned type and also before trying to continue.
//=================================
public function getgiftCategoryById( $id = -1 )
{
$result = FALSE; // default
$sql = "SELECT * FROM giftCategory WHERE id="
.trim( $id )
. " ";
$result = mysql_query( $sql );
return $result;
}//endfunc
Well, the first thing I see is you’re using mysql_*
functions. These no longer exist in PHP7. You should be using mysqli_*
or PDO.
No, this is my old project which has been made in MySQL and its API has been created in MySQL only if I do mysqli, then I have to change all the project code.
sorry, sir, this is not working
Based on that I’d make a couple of observations then:
- You’re unlikely to get much support for the use of
mysql_*
, making your problem harder to solve - the world has moved on - As it’s an old project, I’d hazard a guess it’s the ideal base for refactoring into current technology, and something for which you’ll get more assistance.
But this is not the case that you are old enough to stop using it. Old is gold sir, I do not even say that I do not work on mysqli but the project which is made in MySQL is right in MySQL
That is your choice of course. Good luck with your search for a solution.
Did you check the PHP gettype(…) and is it returning what you expect? If not then echo the SQL query followed by die; to see the result.
If the result is not what is expected then echo previous variables to pinpoint the problem.
It is not easy to supply a solution when I do not have a copy of the database.
ohk sir
It’s a while since I’ve used the old functions, but the documentation says that this syntax is not correct:
mysql_query($this->connect(),"UPDATE giftCategory SET category='".$category."',modified = NOW() WHERE id=".$id." ");
in that the query goes first, and the link object (if required) second).
But, if this is an old project, what changed from the time when it worked well, to the time when it stopped working?
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.