Jump to content

Problems with Storing Data


gladiator83x

Recommended Posts

[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]
Hey All,

I have a Mysql table (called End_Review) and it has 3 columns: an incrementing number, topic_title, and date. On another page I have have a listbox with many topic names. When a topic is chosen, I go to another page where this topic name is passed as $title. Each time I choose a new topic name, I want it to be stored in a database. If it is already in the database, I just want an output message that says that it has already been stored. [!--colorc--][/span][!--/colorc--]



$res=mysql_query("select * from End_Review");
if(mysql_num_rows($res)==0) echo "there is no data in table..";
else {

if ($title !=$row[topic_title]){

mysql_query("INSERT INTO End_Review (id,topic_title, date) VALUES('','$title','$test_date' ) ")
or die(mysql_error());
}

else{

$end_query= "SELECT End_Review.date FROM End_Review WHERE End_Review.topic_title='$title'";
$end_result = mysql_query($end_query) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($end_result, MYSQL_ASSOC);

foreach ($line as $col_value) {

echo "\t\t<td>$col_value3</td>\n"; }

exit("This topic has already been reviewed. Please observe the timestamp");
}}}




[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]All this code pretty much does is compare the specified title with the titles from the table and if it finds a match the associated data will be retrieved. However, my problem is whenever the specified data is not match, it keeps on populating my table with the same data. I know that it should be in the for loop, but I am confused as to where it could go? Any suggestions?[!--colorc--][/span][!--/colorc--]
Link to comment
Share on other sites

If I am understanding right?

Just use a MySQL statement to query the database to see if it exists before adding it. Something like the following example:

[code]
$sql_word_check = mysql_query("SELECT word FROM define WHERE word='$word'");
                        
$word_check = mysql_num_rows($sql_word_check);

if(($word_check > 0)){
  echo "<center><b><font face='tahoma' color='red'>Please fix the following errors: </b><br />";
  if($word_check > 0){
    echo "The word you have submitted has already been defined in our database.
    Please submit a different word or phrase!<br />";
    
     unset($word);
   }
[/code]

Of course use your own details I copies that from a dictionary I built a while back

Hope that helps
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.