Hello Everyone! I am new and my english is bad thus also a student learning to code for my project.
I have a problem and I don't know how to get a variable from different php page. Ty guys
The code of form:
<h3>Sell Your Item</h3>
<form method='post' action='createitem.php'>
<label>Product Name:</label>
<input type='text' name='productname' class='form-control' required>
<br>
<label>Product Type:</label>
<select class="form-select" aria-label="Default select example" name='producttype' required>
<option selected>Open this select menu</option>
<option value="Makeup tools">Makeup tools</option>
<option value="Makeup">Makeup</option>
<option value="Trending clothes">Trending clothes</option>
<option value="Woman">Women</option>
<option value="Men">Men</option>
<option value="Kids">Kids</option>
<option value="Shoes">Shoes</option>
<option value="Bags">Bags</option>
<option value="Kitchen wares">Kitchen wares</option>
<option value="Home appliances">Home appliances</option>
<option value="Hello kitty items">Hello kitty items</option>
<option value="Skincare">Skincare</option>
</select>
<br>
<label>Product Description:</label>
<textarea class="form-control" name="productdescription" rows="5"></textarea>
<br>
<label>Product Price:</label>
<input type='number' name='productprice' class='form-control' required>
<br>
<label>Product Image:</label>
<input type='text' name='productimg' class='form-control' placeholder="Please enter a valid image url" required>
<br>
<input type='submit' class='btn btn-primary' name='add' id='add' value='Sell Item'>
</form>
Here is where form is inserted to sqli tables:
<?php
session_start();
ob_start();
include 'dbconnection.php';
if(!isset($_SESSION['id'])){
header("Location: login.php");
exit();
}
$productname = $_POST['productname'];
$producttype = $_POST['producttype'];
$productdescription = $_POST['productdescription'];
$productprice = $_POST['productprice'];
$productimage = $_POST['productimg'];
$query = "INSERT INTO products (productname,producttype,productdescription,productprice,productimg) VALUES
('$productname','$producttype','$productdescription','$productprice','$productimage')";?>
And here is where I want to insert the id:
<pre>
<?php
include "dbconnection.php";
$query = "SELECT * FROM products where productid = 32'";
$result = mysqli_query($conn, $query);
$checkproducts = mysqli_num_rows($result) > 0;
if($checkproducts){
while($row = mysqli_fetch_array($result)){
?>
What I have tried:
I have tried some methods like last insert and I can't seem to make it work or maybe I
just don't really know. Sorry for inconvinience.