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

Converting RGB values to HEX
Code: <?PHP

$file_handle = fopen("colors/rgb.csv", "r");

wh

Email with Attachments in PHP
Hi Friends

How to send email in PHP with attachment.
I know simple mail can be sent with

Unidentified index error in a simple form
I have been trying to make an HTML form that is handled by a PHP script. So far my attempts to get i

Recording popularity by day, week.. all time?
Hey everyone, I'm creating a site designed around users uploading music. How can I implement a syste

function not returning the correct value
I have a program that needs to return a value from a function. I have an output statement inside the

Unifying logins of two different scripts
I have two different game scripts which I want to embed on my own site. The problem is I don't want

PHP referral database. I would like this form to email the referrer.
Okay, Hello I've been trolling for years. This the first time I've ever asked for php help. Normally

I apologise! It's a newbie to PHP feedback form problem!
Hi,

I am a total newbie to PHP. I am also a unemployed and need to get a job. So after 100% r

date("now") prints out wrong date ?
Hi Guys
Anyone know why and how I can fix it ?

HTML form problem
Ive made a form to that i want to send to my email via PHP. but when it send only the name's etc sen

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