Jump to content

Does anyone know if a script exists for this?


leeandrew

Recommended Posts

Have a basic user management system, whereby the only fuctions are join, login, logout. The only main fuction is that each user bookmarks or 'favourites' 5 pages, the number of pages can be edited by admin. And one the bookmarked pages theres a stat somewhere that says 'bookmarked by 7 users' or however many it is etc.

 

I have tried editing fanlisting scripts to do this job but cannot prevent every user from bookmarking every page... the key is setting a maximum of 5 pages per user.

 

Does anyone know of an already existing script or something similar i can edit? Any keywords to google?

 

Thanks for your help.

Link to comment
Share on other sites

you could create a database like this

bookmarks(
user_id int(15),
book_1 varchar(100),
book_2 varchar(100),
book_3 varchar(100),
book_4 varchar(100),
book_5 varchar(100),
);

then you could put urls in each bookmark cell then run a query like this to count the number of times a page has been bookmarked

SELECT COUNT(*) FROM `testb` WHERE `book_1` = 'URL' OR `book_2` = 'URL' OR `book_3` = 'URL' OR `book_4` = 'URL' OR `book_5` = 'URL';

then the number of bookmarks is in COUNT(*)

 

Scott.

 

Link to comment
Share on other sites

yeah well you have a table with your users and when they bookmark a page it puts it into one of the slots in the bookmarks table and when they fill the 5 slots up you need a scipt to ask them which bookmark to erase.  so they are limited to 5. i think this is what you are asking

 

Scott.

Link to comment
Share on other sites

I have created a simple user system at http://codeapple.com/demo/index.php. Users can register, login, logout. On the members page theres a link to 'page 1', this page i want available for bookmarking. Currently on page1.php i have a link that when clicked auto updates the database, the link directs to bookmark.php. The code im using for bookmark.php is:

 

<html>
  <body>
  <?php
  $host="-";
  $uname="-";
  $pass="-";
  $database="-";
  $tablename="users";
  
  $connection= mysql_connect($host,$uname,$pass)  or die("Database connection failed!<br>");
  $result=mysql_select_db($database) or die("Database could not be selected");
  $query = "UPDATE users SET bookmark1=\"PAGE 1\" where id=1";
  $result = mysql_query($query);

  if (!$result) {
     die(" Query could not be executed.<br>");
  } else {
  echo "<table> ";
  echo " <tr>";
  echo "   <td colspan=\"2\">";
  echo "     <center><b>PAGE 1</b> has been bookmarked</center>";
  echo "     <center><a href=./page1.php>go back</a></center>";
  echo "   </td>";
  echo "  </tr>";
  echo "</table>";
  }
  ?>
  </body>
  </html>

 

I have blanked out the database connection info; so that is not the error, it connects and updates okay.

 

The problem line is this:

  $query = "UPDATE users SET bookmark1=\"PAGE 1\" where id=1";

 

Currently when anyone clicks the link to open this page, it inserts 'PAGE 1' into a cell in table `users` called `bookmark1` but as you can see, only for the user whose ID is 1. How can i set it to whichever user is logged in and clicking the link to update their bookmark1 cell?

Link to comment
Share on other sites

i don't no how you are checking that a user is logged in you must be storing the user information in $_SESSION or in a cookie when a user is log's in you must do a database query you could have some code like this

<?php
$query='Query to check if user is logged in';
$result=mysql_query($query);
if(mysql_num_rows($result)==1){
$row=myql_etch_array($result);
$_SESSION['id']=$row['id'];
}
?>

then you could change your update query to

$query = "UPDATE users SET bookmark1=\"PAGE 1\" where id=".$_SESSION['id'];

then you are setting the bookmark for the user logged in

 

Scott.

 

Link to comment
Share on other sites

Right, that site link is wrong, the site is http://www.codeapple.com/demo2/1/login.php

 

I have 6 cells in a database table named `plus_signup`, which holds all the user details. The 6 cells are named book1, book2.. etc.

 

ATM users can manually enter text and update the info in those cells via an update form. I need to somehow place a html submit button on each page i want available for bookmarking; when a user clicks the submit button on a page it adds it to a cell.

 

I need to know how to update the database just by clicking a submit button, i dont know how ATM. Once i've got that down i can work on limiting to 6.

Link to comment
Share on other sites

on each page you could have a simple link like this

<a href="bookmark.php?page="<?php echo $_SERVER['REQUEST_URI']; ?>">Bookmark this page</a>

then bookmark.php:

<?php
if(isset($_GET['page'])){
//print form
echo '<form action="bookmark.php" method="post">
<input type="hidden" name="page" value="'.$_GET['page'].'" />
Set bookmark 
<select name="bookmark_number">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
</select>
to '.$_GET['page'].'
<input type="submit" value="Set">
</form>';
}elseif(isset($_POST['bookmark_number'])){
$query="UPDATE `plus_signup` SET `book".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `user_id` = '".$_SESSION['id']."';";
mysql_query($query);
header('Location: welcome.php');
}else{
header('Location: welcome.php');
}
?>

 

Link to comment
Share on other sites

I have this code working:

 

<?
// check the login details of the user and stop execution if not logged in
if(!isset($session['userid'])){
echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;
}

$row=mysql_fetch_object(mysql_query("select * from plus_signup where userid='$session[userid]'"));


if($row->book1 == "yes"){
$ckb="<font face='verdana, arial, helvetica' size='2' align='left'>
<b><font color='green'>BOOK1 is in your elite 6</font></b><br>
<input type='radio' value=yes checked name='book1' checked><b><font color='green'>Yes</font></b> 
<input type='radio' value=no  name='book1'>No";}


else {$ckb="<font face='verdana, arial, helvetica' size='2' align='left'>
<b><font color='red'>Make BOOK1 elite?</font></b><br>
<input type='radio' value=yes name='book1' >Yes 
<input type='radio' value=no checked name='book1' checked><b><font color='red'>No</font></b>";}

// One form with a hidden field is prepared with default values taken from field. 
echo "<form action='elitecheck.php' method=post>
<input type=hidden name=todo value=update-profile>

<table border='0' cellspacing='0' cellpadding='0' align=left width='30%'>
<tr bgcolor='#ffffff' > <td colspan='2' align='left'>
</font></td> </tr>


<td ><font face='Verdana' size='2'>  $ckb</td></tr>
<tr bgcolor='#ffffff'><td align=left colspan=2><input type=submit class=red value=Make_Elite></td></tr>


";


echo "</table><br>";


?>

 

Could i edit this to check if anything exists in cell `book1`, if yes, then it checks cell `book2`, and so on until it finds an empty cell (maximum of 6). If no then it submits the info into the cell.

 

An else if statement maybe?

 

Or possibly use a drop down box to select the cell:

 

book1

book2

book3

book4

book5

book6

 

so then the user can choose which cell they bookmark, then they can edit and overwrite as many times as they want.

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.