The database always gets the same identifiers

Hope this is not a bad question. I tried to understand what I was doing wrong, but I could not. I am new to php and mysql, so I'm really confused ...

I have this database (I will attach a screenshot of the workbench model for mysql) mysql database

And I'm trying to insert sales tables on sale and print_for_sale. The queries seem to work and the data is displayed in phpmyadmin. The error does not appear. However, the sales user in the sales table always has the same identifier. Even if I use a different user login. And in the print_for_sale table, fk_sale_id is always the same identifier. And price_print_for_sale is always the same. This should not happen. What am I doing wrong? Can someone help me? Thank!

sale tableprint_for_sale table

Here is my PHP code:

<?php
session_start();
$user_id = $_SESSION['user_id'];
print_r($_POST);

$id_print= $_POST['print_id'];

include('database.php');

$bought_sizes=$_POST['sizes'];

$number_of_bought_sizes= count($bought_sizes);


//header('location:index.php?area=printstore');


$sqlinsertsale = "insert into sale
    (fk_sale_user,
    fk_payment_id) 
    values(".$user_id.", 1)"; 

// , 1, .

mysql_query($sqlinsertsale); 


for($i=0; $i< $number_of_bought_sizes; $i++){

    $selectmultiple = "select * 
    from print_has_size 
    inner join size on fk_size_id = size_id
    inner join print on fk_print_id = print_id 
    where print_id =".$id_print."";

    $resultmultiple = mysql_query($selectmultiple);

    $linemultiple = mysql_fetch_assoc($resultmultiple);

    $size_price = $linemultiple["size_price"];



    $selectsale = "select * 
    from sale";

    $resultsale = mysql_query($selectsale);

    $linesale = mysql_fetch_assoc($resultsale);

    $sale_id = $linesale["sale_id"];

    //$sale_id = mysql_insert_id();

/*PARA CADA 1 DOS TAMNHO*/

$sqlinsertprintforsale = "insert into print_for_sale
    (fk_sale_id,
    price_print_for_sale) 
    values(".$sale_id.", ".$size_price.")";

mysql_query($sqlinsertprintforsale);

} 

?>

, , .

markup

: ( php-, )

<?php
session_start();
include('database.php');

$user=mysql_real_escape_string($_POST['user_login']);
$pass=mysql_real_escape_string($_POST['user_pass']);

$sql="select user_id, user_name
    from user
    where
    user_login='".$user."' 
    and user_pass = MD5('".$pass."')";

    echo $sql;

$result = mysql_query($sql);

$num_of_regs = mysql_num_rows($result);

echo "<br>".$num_of_regs;

if($num_of_regs!=1) {
    header('location:index.php?login=done');
}
else {
    $line = mysql_fetch_assoc($result);

    $user_name = $line['user_name'];
    $user_id = $line['user_id'];


    $_SESSION['user_name'] = $user_name;
    $_SESSION['user_id'] = $user_id;

    header('location:index.php');


}

?>

.

<?php
session_start();
session_destroy();
header('location:index.php');
 ?> 

, . print_for . . ... ?: (

, ,    ini_set ('display_errors', true); error_reporting (E_ALL);

: mysql_connect(): mysql : mysqli PDO /Applications/XAMPP/xamppfiles/htdocs/printstore/database.php 7

 echo $_SESSION['user_id'];

1:

user1

2: user2

, , 1 2. , " ", print_for_sale . 3 ( )

  • phpmyadmin . . , , . print_for_sale, ( ), - sale_id ​​ price_print_price, 25). , 25. -

sale_nowprint_for_sale_now

+4
2

. , , . , .

$selectsale = "select * 
from sale";

$resultsale = mysql_query($selectsale);

while($linesale = mysql_fetch_assoc($resultsale))
{
 $sale_id = $linesale["sale_id"];
}
+2

, , logout.php. . , .

<?php 

session_start();
session_destroy();

?>

, , , , .

: PDO http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059

+1
source

All Articles