db entry based on primary key


Posted on 16th Feb 2014 07:03 pm by admin

My "topics" table contains 10 entires
*--------------*
topicid topic
------
Did you know?Explore Trending and Topic pages for more stories like this.
*--------------*
01 Bye
02 Hi
03 Hello
.....
10 Morning
*--------------*


<?php //topics.php
require_once("includes/connection.php");
....
....
ttopics[]= //I have 10 strings here which have changed by now.

foreach ($ttopics as $ttkey)
{

//I am trying to update my "topics" table whenever these strings change, based on the topicid (primary key).

//Please correct my code.

$id = mysql_real_escape_string('topicid');
$topic = mysql_real_escape_string('topic');
$result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$id}' and topic='{$topic}' ");
if($result)
{
$num = mysql_num_rows( $result );
if ($num == 0)
{
$querypost = mysql_query ("INSERT INTO trendingtopics (topic) VALUES ('$ttkey')");
}


}


I am getting an error. Lets say the position of Morning is first and Bye is last. It should update the database accordingly. If there is a new entry, say "phpfreaks" in first position. It should update according.
No comments posted yet

Your Answer:

Login to answer
76 Like 17 Dislike
Previous forums Next forums
Other forums

Checking if a process is running (problems including psapi.dll i think...)
Ok, so all I'm trying to do is check if a program is running...

I've found out that I nee

Undefined Variable: PHP_SELF, pls help
Hi,

Im a newbie on PHP / MySQL programming and Im running a script to search one field on my

Help with simple query
Hi,

I'm trying to do a Query with a Union where I want to print the number of rows $tc conta

Unexpected T_Variable ?
Hi all,
I dont really know what I am doing!! I know I'm doing something wrong, and I know its on

Load file in PHP
I have 2 files. The first is a PHP generated XML file that's dependent by 2 inputs. The second is a

AJAX form submit
I recently built a form that submits data to my database with an ajax function that is called throug

On page view, minus credit
Hello all, please, I need a little help with this script. I am charging one credit (credits can be p

multipart emiail forms
Hi All,

I am new to the boards and I've been working on a form (which is rather massive, imo

Impact of movement type 412 E on MAP
Hi

Usage of movement type 412 E is causing huge change in MAP .

Is there any r

JSON SORT WITH PHP
I have two products that I want to sort by say "Id:17, value: xxx" using php
The page w

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash