Hello, Im trying to build a poll from scratch, Im avare of alla the frees poll on the net but i want to learn it my self. I did mange to do a guestbook and to add a row I used this line

mysql_query("INSERT INTO guestbook (name, eMail, homePage, inlay) VALUES ('$name','$email','$hp','$mess');");

problem is that every it always add a row. In my poll I want two ways. Yes or no No. So if the user clicks No i want to add +1 to a row and overwrite the old value. So any hint of what I can use. Shall i have two variabelse to store in diffrents rows?

cheers knuff

    You need to use an update statement.

    http://www.mckoi.com/database/SQLSyntax.html#12

    Assuming name is unique then

    UPDATE guestbook SET
    eMail = '$email',
    homePage = '$hp',
    inlay = $m
    WHERE
    name = '$name'

    HINT: Use mysql_num_affected_rows() to see if a record was actually updated. If $name is not already in the database then no rows will be updated. You then do an insert statement.

      im half way there now. But now for my next problem. If i use the UPDATE line then it overwrites the vaule. But what i want to do is add "+1" to the number i the row. So if i type +1 in the text field it turns out to be "+1" not add-1-to-4-already. Have i wrong settings for my row in phpmyadmin, the setting i have is "varchar"?

      knuff

        Not positive I understand. You want to increment the value in a column?

        UPDATE table SET value = value + 1 WHERE ...

        value of course has to be a numeric column. varchar probbably won't work though it might be possible to convert it to an integer, increment then convert back. Check a sql syntax site.

          Write a Reply...