Jump to content

Incorporating condition statement into MySQL INSERT? how?


bilis_money

Recommended Posts

Yo! brothers...

i have codes here,

[code]
//insert new record now
$query = "INSERT INTO topics (title, description, url)
VALUES ('$title_tmp', '$descrip_tmp', '$url_tmp'";
mysql_query($query) or die('Error, insert query failed');

$COerr_msgs->err_msgs('add1');
[/code]

I would like to add conditional statement with the MySQL query,
let say if the insertion of the new record into the database is successful,
then i want to add a successful message that it was successfully added.

Now how could i determine if the new record was successfully inserted?
I guess i have already known this before but maybe i have merely forgotten so.

thank you very much in advance.

Link to comment
Share on other sites

after you insterted the data into the database, you could query and fetch it again.
and if one of the array field is empty you could determin if it went ok or not!
i think something like this would do it.
just fill in the conditional statement with what you want and thats it!
[CODE]
$query ="SELECT * FROM topics WHERE title = $title_tmp";
$data = mysql_query($query);
$fetch = mysql_fetch_array($data);
if ( (empty($fetch['title'])) || (empty($fetch['description'])) || (empty($fetch['url'])) ){
}
[/CODE]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.