0

Hellow peoplw. I have an update syntax that is doing something else than I expect.
I want to update a table with price of the products for a selected user the form is ok but when I click update the order update only the last price inserted.Why?

p>
Here you can update your account information for viewing in your
profile.<br><br>
<?php
if (isset($_POST['submit']) &&
    $_POST['submit'] == "Update") {
    $query_update = "UPDATE preturi,user_info SET 
        Pret_manopera = '" . $_POST['email'] . "' 
        WHERE username = '" . $_SESSION['user_logged'] . "'
        AND password = '" . $_SESSION['user_password'] ."'
        AND user_info.user_id=preturi.id_ofertant
        ";
        
        $result_update = mysql_query($query_update)
        or die(mysql_error());
    
        
        
        $query1 = "SELECT * FROM preturi,user_info 
        WHERE username = '" . $_SESSION['user_logged'] . "'
        AND password = '" . $_SESSION['user_password'] . "'
        AND user_info.user_id=preturi.id_ofertant
        ";
            $result1 = mysql_query($query1)
            or die(mysql_error());
            $row = mysql_fetch_array($result1);
       
                
            

        ?>           
    <b>Informatiile din contul tau au fost modificate.</b><br>
<a href="user_personal.php">Apasa aici</a>pentru a te intoarce in contul tau.

</p>
<?php
}else{
    $query = "SELECT * FROM user_info,preturi
            WHERE username = '" . $_SESSION['user_logged']."'
            AND password ='".$_SESSION['user_password'] ."'
            AND user_info.user_id=preturi.id_ofertant";
            $result = mysql_query($query)
            or die(mysql_error());
         while ($row = mysql_fetch_array($result)){
    
?>
"<p>
<form action="updatepreturi2.php" method="post">
<?php echo $row['id_manopera'];?>": <input type="text" name="email"
size="2" value="<?php echo $row['Pret_manopera'];}}?>"><br>





<input type="submit" name="submit" value="Update"> &nbsp;
<input type="button" value="Cancel" onclick="history.go(-1);">
</form>

It must be a lot of briliant brains around here that think faster than me.
Thank you !

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MooGeek
0

Some things need to clear:
What is "<p> before <form ...

What is need of while if select query return only one record i.e. one record for user who is in session logged in.

You form tag starts in while and closing out of while loop.
Make it proper.

0

Here is simple form,
take it as assignment and play with it to use update and other queries.
Use it as your toy for learning

<?php
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$email_name = $_POST['email'];

$sql = "INSERT INTO address(firstname, lastname, email) VALUES('$first_name', '$last_name','$email_name')";
mysql_query($sql);

?>
 
<html>
	<body>
		<form action<?=$_SERVER['PHP_SELF']?> method="POST">
			<input type="text", name="fname" />
			<input type="text", name="lname" />
			<input type="text", name="email" />
			<input type="submit", value="Send" />
		</form>
	</body>
	
</html>
0
<?php
session_start(); //I think this is the problem
?>

<p>
Here you can update your account information for viewing in your
profile.<br><br>
<?php
if (isset($_POST['submit']) &&
    $_POST['submit'] == "Update") {
    $query_update = "UPDATE preturi,user_info SET 
        Pret_manopera = '" . $_POST['email'] . "' 
        WHERE username = '" . $_SESSION['user_logged'] . "'
        AND password = '" . $_SESSION['user_password'] ."'
        AND user_info.user_id=preturi.id_ofertant
        ";
        
        $result_update = mysql_query($query_update)
        or die(mysql_error());
    
        
        
        $query1 = "SELECT * FROM preturi,user_info 
        WHERE username = '" . $_SESSION['user_logged'] . "'
        AND password = '" . $_SESSION['user_password'] . "'
        AND user_info.user_id=preturi.id_ofertant
        ";
            $result1 = mysql_query($query1)
            or die(mysql_error());
            $row = mysql_fetch_array($result1);
       
                
            

        ?>           
    <b>Informatiile din contul tau au fost modificate.</b><br>
<a href="user_personal.php">Apasa aici</a>pentru a te intoarce in contul tau.

</p>
<?php
}else{
    $query = "SELECT * FROM user_info,preturi
            WHERE username = '" . $_SESSION['user_logged']."'
            AND password ='".$_SESSION['user_password'] ."'
            AND user_info.user_id=preturi.id_ofertant";
            $result = mysql_query($query)
            or die(mysql_error());
         while ($row = mysql_fetch_array($result)){
    
?>
"<p>
<form action="updatepreturi2.php" method="post">
<?php echo $row['id_manopera'];?>": <input type="text" name="email"
size="2" value="<?php echo $row['Pret_manopera'];}}?>"><br>





<input type="submit" name="submit" value="Update"> &nbsp;
<input type="button" value="Cancel" onclick="history.go(-1);">
</form>

Edited by MooGeek: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.