I am trying to make an edit form but when I fire the editData Function it Gives me the error
which is ‘Undefined variable: name‘.I tried so Hard to Find the solution but nothing works
Maybe I’m missing something which I don’t know. I Need Help to Move Forward.
Here is my code:-
ProductControlller.php
<?php
namespace AppHttpControllers;
use AppProduct;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
class ProductController extends Controller
{
public function InsertForm()
{
return view('prodInsert');
}
public function Prodcreate(Request $request)
{
$pName=$request->input('pname');
$pPrice=$request->input('pprice');
$pDesc=$request->input('pdesc');
$pQuantity=$request->input('pquantity');
$data=array('pname' =>$pName,'pprice' =>$pPrice,'pdesc' =>$pDesc,'pquantity' =>$pQuantity);
DB::table('products')->insert($data);
echo "Record Inserted Succefully<br>";
echo "<a href='/Display'>Display Data</a><br>";
echo "<a href='/prodInsert'>Add Product</a>";
}
public function selectData(Request $request)
{
$tabledata=DB::select('select * from products');
return view('Display',['tabledata'=>$tabledata]);
}
public function deleteData(Request $request,$id){
DB::table('products')->delete($id);
return redirect('Display');
}
public function show($id)
{
$tabledata=DB::select('select * from products where id = ?',[$id]);
return view('editform',['tabledata'=>$tabledata]);
}
public function editData(Request $request,$id)
{
$pName=$request->input('name');
$pPrice=$request->input('price');
$pDesc=$request->input('desc');
$pQuantity=$request->input('quantity');
DB::update('update products set pName=?','pPrice=?','pDesc=?','pQuantity=?',[$name,$price,$desc,$quantity,$id]);
}
}
And this is my EditForm.blade.php
<!DOCTYPE html>
<html>
<head>
<title>PROD INSERT</title>
</head>
<body>
<form action="/edit/<?php echo $tabledata[0]->id; ?>">
@csrf
<h4 align="center"><a href="Display"> Click here</a> Edit</h4>
<table align="center">
<tr>
<td>Product name</td>
<td><input type="text" name="name" value="<?php echo$tableData[0]->product_name; ?>"></td>
</tr>
<tr>
<td>Product Price</td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td>Product Description</td>
<td><input type="text" name="desc"></td>
</tr>
<tr>
<td>Product Quantity</td>
<td><input type="text" name="quantity"></td>
<br>
</tr>
<td><input type="submit" name="submit"></td>
</table>
</form>
</body>
</html>
I can provide more code if needed.
Thanks for Your Support 🙂