user983248
user983248

Reputation: 2688

Insert or replace value on database

How do I insert or replace a value on the database ?

Basically I need to replace one row on the database without alter the rest of the info, in this case is the form_email row based on the id.

On a previous instance I get the email with:

$query = "SELECT `form_email` FROM `$table_name_email` WHERE `id` = $form_id";
$result = mysql_query($query) or die(mysql_error());

while($row_email = mysql_fetch_array($result_email)){
    $email = $row_email[form_email];
    echo $email;
}

But I'm having problems to understand how to inser or replace that email

This is the table structure, just in case.

CREATE TABLE IF NOT EXISTS `contactforms` (
  `id` int(11) NOT NULL auto_increment,
  `form_slug` varchar(100) NOT NULL,
  `form_title` varchar(200) NOT NULL,
  `form_action` mediumtext NOT NULL,
  `form_method` varchar(4) NOT NULL,
  `form_fields` text NOT NULL,
  `submit_button_text` varchar(200) NOT NULL,
  `custom_code` mediumtext NOT NULL,
  `form_style` int(10) NOT NULL default '0',
  `form_email` text NOT NULL,
  `form_success_message` mediumtext NOT NULL,
  `form_thank_you_page` varchar(200) NOT NULL,
  `form_success_title` varchar(150) NOT NULL default 'Form Success!',
  `form_access` text NOT NULL,
  `form_email_subject` varchar(250) NOT NULL,
  `form_email_name` varchar(100) NOT NULL,
  `form_pages` varchar(400) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;

Thanks in advance

Upvotes: 0

Views: 316

Answers (1)

Deruijter
Deruijter

Reputation: 2159

You can use the sql UPDATE statement. It allows you to update certain fields for certain records, for example (pseudo code):

UPDATE contactforms
SET form_email = '[email protected]'
WHERE id = 'someId'

This will modify all form_email fields to [email protected] for rows with id someId :)

Upvotes: 1

Related Questions