Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:30:47+00:00 2026-05-23T11:30:47+00:00

im currently trying to build a function where users on my website can unter

  • 0

im currently trying to build a function where users on my website can unter up too 3 different interests. My interests are inserted into the DB using AJAX, my scripts are below…

Form:

<div id="insert_response"></div>
<form action="javascript:insert()" method="post">
<input name="useridint" type="hidden" id="useridint" value="<?php echo $usersClass->userID(); ?>"/>

AJAX:

function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var useridint= encodeURI(document.getElementById('useridint').value);
var interest = encodeURI(document.getElementById('interest').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'upd_interests.php?useridint= '+useridint+'&interest=' +interest+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){ 
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = response;
}
}

PHP:

<?php require 'config.inc.php'; ?>

<!-- Verify if user exists for login -->
<?php
if(isset($_GET['useridint']) && isset($_GET['interest'])){

$url= $_GET['useridint'];
$sitename= $_GET['interest'];

$insertSite_sql = "INSERT INTO user_interests (user_id, interest) VALUES('{$url}' , '{$sitename}')";
$insertSite= mysql_query($insertSite_sql) or die(mysql_error());

echo $sitename;
} else { 
echo 'Error! Please fill all fileds!';
}
?>

What im asking is, is it possible I can somehow only have 3 records in the database for each user? So once a user has entered 3 rows, he can no longer enter more? If so what would the best option be?

Thanks


In response to @Daniel suggestion i tried the following only its now not inserting…

$res = mysql_query("select count(*) as cnt from user_interests where user_id=$useridint")
while($r=mysql_fetch_array($res))
{
if($r["cnt"] < 3)
{
if(isset($_GET['useridint']) && isset($_GET['interest'])){

$url= $_GET['useridint'];
$sitename= $_GET['interest'];

$insertSite_sql = "INSERT INTO user_interests (user_id, interest) VALUES('{$url}' , '{$sitename}')";
$insertSite= mysql_query($insertSite_sql) or die(mysql_error());

echo $sitename;
} else { 
echo 'Error! Please fill all fileds!';
}
}
  else
{
 echo "you have 3 ";
}
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:30:47+00:00Added an answer on May 23, 2026 at 11:30 am

    just run . Also it is good idea to escape user input. just in case a user decides his favorite site is ;drop databases–;

    $res = mysql_query("select count(*) as cnt from user_interests where user_id=$useridint")
    while($r=mysql_fetch_array($res))
    {
      if($r["cnt"] < 3)
      {
         insert
      }
      else
      {
         error
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a website using object-oriented functionality, and running into some issues.
I'm currently trying to build a personal website to create a presence on the
I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
Scenario : I'm currently trying to build a poor man's Google Maps using scripts
I'm currently trying to build a simple component which should monitor, if the user
I am currently trying to build on TeamCity, which uses Microsoft.Office.Interop dll. This will
I'm currently trying to build an application that inherently needs good time synchronization across
I'm currently trying to build a more or less complete set of unit tests
I am currently trying to build a very basic serial shell with my arduino.
I am trying to build an API that gives data on various cities. Currently,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.