Update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lammspillning
Forum Newbie
Posts: 14
Joined: Fri Aug 17, 2007 10:50 am

Update

Post by lammspillning »

Hi!
I'm trying to figure out how to update a kitchenlist when you insert a new value for datorpost and if name allready exists.
If the name doesn't exists it should insert a new person in the database.
This is the code I have currently..

Code: Select all

<?php
 
 
    function setuser($name, $datorpost) {
        $conn_id = pg_connect ("host=localhost user=cordts dbname=cordts")
                or die("No contact with kitchenlist");
        $query = "SELECT name FROM user where name = '$name'";
        $row = pg_fetch_row($query);
        if ($row[0] == $name)   {$query = "UPDATE user SET datorpost = $datorpost" WHERE name = $name;}
        else {$query = "INSERT INTO user VALUES ('$name', '$datorpost')";
        }
        pg_query ($conn_id, $query)
            or die ("Cant get persons");
        pg_close($conn_id);
        }
        
        
?>
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Update

Post by onion2k »

Code: Select all

$query = "UPDATE user SET datorpost = $datorpost" WHERE name = $name;
Putting your closing quote in the middle of your string is unlikely to work.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Update

Post by aceconcepts »

Code: Select all

 
$query = "UPDATE user SET datorpost = $datorpost WHERE name = $name";
 
Also, if you can't spot what you've done wrong try getting some error info: mysql_error()
Post Reply