Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
100 changes: 100 additions & 0 deletions phpLoginBase/SecaoViewall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!--
Sites de exemplo

https://phpgurukul.com/how-to-create-a-shopping-cart-in-php/

https://codeshack.io/shopping-cart-system-php-mysql/

-->

<?php
include 'connect.php';

if(isset($_SESSION['id']) == false)
{
include 'logout.php';
}


if(isset($_POST['sub'])){

$product_id = (int)$_POST['idProduto'];
$quantity = (int)$_POST['quantity'];
$nomeProduto = $_POST['nomeProduto'];





// Product exists in database, now we can create/update the session variable for the cart
if (isset($_SESSION['cart']) && is_array($_SESSION['cart'])) {
if (array_key_exists($product_id, $_SESSION['cart'])) {
// Product exists in cart so just update the quanity
$_SESSION['cart'][$product_id] = array('quantity'=> $_SESSION['cart'][$product_id]['quantity']+$quantity,'nomeProduto'=>$nomeProduto);
} else {
// Product is not in cart so add it
$_SESSION['cart'][$product_id] = array('quantity'=>$quantity,'nomeProduto'=>$nomeProduto);
}
} else {
// There are no products in cart, this will add the first product to cart
$_SESSION['cart'] = array($product_id => array('quantity'=>$quantity,'nomeProduto'=>$nomeProduto));
}



}
// else if(isset($_POST['clear'])){
// unset($_SESSION['counter']);
// }



?>

<table border='1'>
<tr>
<th>
Produto
</th>
<th>
Preço
</th>
</tr>

<?php
$sq="select * from produto";
$qu=mysqli_query($con,$sq);
while($produto= mysqli_fetch_assoc($qu)){
?>
<tr>
<td>
<?php echo $produto['nomeProduto']?>
</td>
<td>
<?php echo $produto['precoProduto']?>
</td>
<td>
<form method="POST" enctype="multipart/form-data">
<input type="number" name="quantity" value="1" min="1" placeholder="Quantity" required>
<input type="hidden" name="idProduto" value="<?=$produto['idProduto']?>">
<input type="hidden" name="nomeProduto" value="<?=$produto['nomeProduto']?>">
<input type="submit" name="sub" value="Adicionar">
</form>
</td>
</tr>
<?php
}
?>

<!-- ---------------- -->

<?php foreach($_SESSION['cart'] as $key => $value):?>
<ul>
<li><?php echo $key." has the value ". $value['nomeProduto'] . " Quantity ". $value['quantity'] ?></li>
</ul>
<?php endforeach; ?>



<a href="home.php">Home Page </a> <br />
<a href="secaoFinishShoppingCar.php">Concluir compra </a> <br /> <br />
4 changes: 4 additions & 0 deletions phpLoginBase/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php session_start();

$con= mysqli_connect("localhost","root","","test")
?>
9 changes: 9 additions & 0 deletions phpLoginBase/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
include 'connect.php';

$sq="delete from pessoa where id='$_SESSION[id]'";
mysqli_query($con,$sq);

include 'logout.php';

?>
89 changes: 89 additions & 0 deletions phpLoginBase/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
include'connect.php';
if(isset($_POST['sub'])){
$t=$_POST['text'];
$u=$_POST['user'];
$p=$_POST['pass'];
$c=$_POST['city'];
$g=$_POST['gen'];
if($_FILES['f1']['name']){
move_uploaded_file($_FILES['f1']['tmp_name'], "image/".$_FILES['f1']['name']);
$img="image/".$_FILES['f1']['name'];
}
else{
$img=$_POST['img1'];
}
$i="update pessoa set name='$t',username='$u',password='$p',city='$c',gender='$g',image='$img' where id='$_SESSION[id]'";
mysqli_query($con, $i);
header('location:home.php');
}
$s="select*from pessoa where id='$_SESSION[id]'";
$qu= mysqli_query($con, $s);
$f=mysqli_fetch_assoc($qu);
?>
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>
Name
<input type="text" name="text" value="<?php echo $f['name']?>">
</td>
</tr>
<tr>
<td>
Username
<input type="text" name="user" value="<?php echo $f['username']?>">
</td>
</tr>
<tr>
<td>
password
<input type="password" name="pass" value="<?php echo $f['password']?>">
</td>
</tr>
<tr>
<td>
city
<select name="city">
<option value="">-select-</option>
<option value="knp"<?php if($f['city']=='knp'){ echo "selected='selected'";}?>>kanpur</option>
<option value="lko"<?php if($f['city']=='lko'){ echo "selected='selected'";}?>>lucknow</option>
</td>
</tr>
<tr>
<td>
Gender
<?php if($f['gender']=='male'){
?>
<input type="radio"name="gen" id="gen" value="male" checked>
<?php
} else {
?>
<input type="radio"name="gen" id="gen" value="male">
<?php } ?>male
<?php if($f['gender']=='female'){
?>
<input type="radio"name="gen" id="gen" value="female" checked>
<?php
} else {
?>
<input type="radio"name="gen" id="gen" value="female">
<?php } ?>female
</td>
</tr>
<tr>
<td>
Image
<img src="<?php echo $f['image']?>" width="100px" height="100px">
<input type="file" name="f1">
<input type="hidden" name="img1" value="<?php echo $f['image']?>">
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="sub">

</td>
</tr>
</table>
</form>
62 changes: 62 additions & 0 deletions phpLoginBase/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
include 'connect.php';

if(isset($_SESSION['id']) == false)
{
include 'logout.php';
}


$s="select*from pessoa where id='$_SESSION[id]'";
$qu= mysqli_query($con, $s);
$f=mysqli_fetch_assoc($qu);
?>
<html>
<head>

</head>
<body>
<table>
<tr>
<td>
Name
</td>
<td>
<?php echo $f['name'];?>
</td>
</tr>
<tr>
<td> Username</td>

<td>

<?php
echo $f['username'];?>
</td></tr>
<tr><td> Password</td>
<td>
<?php
echo $f['password']."<br>";?>
</td></tr>
<tr><td> City </td> <td>
<?php
echo $f['city']."<br>";?></td></tr>
<tr>
<td>Gender</td>
<td><?php
echo $f['gender']."<br>";?></td>
</tr>
<tr><td> Image</td><td>

<img src="<?php
echo $f['image'];?>" width="100px" height="100px">
</td>

</tr>
</table>
<a href="edit.php">Edit </a> <br />
<a href="delete.php">Delete </a> <br />
<a href="viewall.php">View All People </a> <br />
<a href="logout.php">Logout </a> <br />
</body>
</html>
Binary file added phpLoginBase/image/EnsembleByHan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added phpLoginBase/image/Screenshot_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added phpLoginBase/image/github-octocat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added phpLoginBase/image/images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions phpLoginBase/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
include'connect.php';
if(isset($_POST['sub'])){
$u=$_POST['user'];
$p=$_POST['pass'];
$s= "select * from pessoa where username='$u' and password= '$p'";
$qu= mysqli_query($con, $s);
if(mysqli_num_rows($qu)>0){
$f= mysqli_fetch_assoc($qu);
$_SESSION['id']=$f['id'];
header ('location:home.php');
}
else{
echo 'username or password does not exist';
}
}else if (isset($_POST['reg'])){
header ('location:reg.php');
}
?>
<html>

<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST" enctype="multipart/form-data">
<table>

<tr>
<td>
Username
<input type="text" name="user">
</td>
</tr>
<tr>
<td>
password
<input type="password" name="pass">
</td>
</tr>
<tr>
<td>
<input type="submit" name="sub" value="submit">
</td>
</tr>

<tr>
<td>
<input type="submit" name="reg" value="cadastro">

</td>
</tr>

</table>
</body>
</html>
8 changes: 8 additions & 0 deletions phpLoginBase/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

session_start();

unset($_SESSION['id']);
header('location:login.php');

?>
24 changes: 24 additions & 0 deletions phpLoginBase/pessoa_pedido_produto.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create table pessoa_pedido_produto(
idPedido int PRIMARY key AUTO_INCREMENT,
fk_idPessoa int,
fk_idProduto int,
quantityProduto int not null,
dataPedido datetime DEFAULT now(),
FOREIGN key(fk_idPessoa) REFERENCES pessoa(id),
FOREIGN key(fk_idProduto) REFERENCES produto(idProduto)
);




create table pessoa_pedido_produto(
id int PRIMARY key AUTO_INCREMENT,
fk_idPedido int not null,
fk_idPessoa int not null,
fk_idProduto int not null,
quantityProduto int not null,
dataPedido datetime DEFAULT now(),
FOREIGN key(fk_idPedido) REFERENCES pedido(idPedido),
FOREIGN key(fk_idPessoa) REFERENCES pessoa(id),
FOREIGN key(fk_idProduto) REFERENCES produto(idProduto)
);
Loading