Note that there are some explanatory texts on larger screens.

plurals
  1. POScript for updating the database or inserting a new row
    primarykey
    data
    text
    <p>People</p> <p>I am trying to use the same script for approving a contact to be added to the database, but the query will do an update if the primary key (id) is already there. So i set up a INSERT INTO .... ON DUPLICATE KEY UPDATE query, which is below:</p> <pre><code>$resultsc = mysql_query("INSERT INTO $contact (id,First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail,inserted) VALUES('$id','$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2',NOW()) ON DUPLICATE KEY UPDATE (First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail) VALUES ('$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2') WHERE id='$id'"); if(!$resultsc) { echo "&lt;font face='Verdana' size='2' &gt;&lt;center&gt;You have successfully approved this user for access to this site.&lt;/center&gt;&lt;br&gt;&lt;center&gt;&lt;input type='button' value='Back' onClick='history.go(-2)'&gt;&lt;/center&gt;"; die(); } else { echo "&lt;font face='Verdana' size='2' &gt;&lt;center&gt;You have not updated this contact for this site.&lt;/center&gt;&lt;br&gt;&lt;center&gt;&lt;input type='button' value='Back' onClick='history.go(-2)'&gt;&lt;/center&gt;"; } </code></pre> <p>I am not getting any errors but the database is not updating or inserting a new record. So I checked my "$contacts" variable to ensure it is is pointing to the correct table, and it is. If i just do an insert alone then the script is working fine. But when i do this query nothing happens. I am wondering what is wrong with it or should i just have a if/else with a select checking for a existing key?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload