Jump to content

Preventing Duplicate Content


Talon21

Recommended Posts

Hi,

 

I'm new to MYSQL I want to insert a PHP variables into MYSQL table the problem is it's insert the row each time the page is loaded

the code is:

 

<?php

include_once ('config.inc.php');

$pageurl = '/';

$mainKeyword = 'Main Keyword';

$title = 'title';

$keywords = 'keywords';

$description = 'description';

$header = 'header';

$site_group ='sitegroup';

 

//include secleted template

include('templates/main.php');

 

//insert variables into mysql

 

 

mysql_select_db("$dbname", $con);

$insert = "INSERT INTO convertech VALUES ('mysql_insert_id($id),'$pageurl','$mainKeyword','$title','$keywords','$description','$header','$site_group',)";

$retrieveID = mysql_insert_id();

mysql_query($insert);

mysql_close($con);

 

?>

Link to comment
Share on other sites

I could go ahead and assume what it is you're trying to do but I'll just leave it as this...

 

As long as your query functions you're always going to insert a new row in the database table with the above code.

 

What is it you want to happen? Only insert once per user visit?

Link to comment
Share on other sites

Just store the session_id() into a session as well as the row id. If it matches via some conditional you write it will either insert/update the database.

 

This is far from exact but it at least demonstrates a possible way this could happen. Basically just throw the user session id in there and compare to it. It's NOT an exact science and there can be all sorts of ways this couldn't work but it gets the job done right now :)

 

<?php
session_start();
// get the user session and store it right away
$_SESSION['user_session'] = session_id();
// check the database to see if that session exists
$sql = mysql_query("select session_id from convertech where session_id = '".mysql_real_escape_string($_SESSION['user_session'])."'");
// now see if the above query came back with anything

// doesn't exist so create a new row
if (mysql_num_rows($sql) == 0) {
$sql_insert = mysql_query("insert into table values whatever");
// does exist so update
} else {
$sql_update = mysql_query("update table set whatever = whatever");
}
?>

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.