Jump to content

[SOLVED] SQL Query Update


soccadude

Recommended Posts

I have the file updatepage.php

<?php
session_start();
include ("config.php");
$user = $_SESSION['username'];
$chk="SELECT `page` FROM `users` where `username`='$user'";
$check=@mysql_query($chk) or die (mysql_error());
if($currentpage < $check) 
{
}
else
{
$query="update `users` set `page`='$currentpage' where `username`='$user'";
$result=@mysql_query($query) or die(mysql_error());
?>

 

On each page, I have $currentpage = "(an integer starting from 0 and increasing by 1 each page)"

 

What I'm trying to do is make it where if $currentpage <= page, it will do nothing. If it is not equal to that then it will update that entry in the table.

 

--------------

 

Also, I have another code that I'm working on. I am trying to compare two tables.

Table 1:

id,username,password,page

Table 2:

id,page,actualpage

 

I'm trying to have it check if page = page, then it will display actualpage. So far I have been unable to figure it out.

 

 

Thanks for your time.

 

Link to comment
https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/
Share on other sites

I cant see where you have defined $current_page.

 

Also try

 

<?php
session_start();
include ("config.php");
$user = $_SESSION['username'];
$chk="SELECT `page` FROM `users` where `username`='$user'";
$check=@mysql_query($chk) or die (mysql_error());

$row = mysql_fetch_row($check);
$currentpage = $row[0];
if($currentpage < $check) 
{
}
else
{
$query="update `users` set `page`='$currentpage' where `username`='$user'";
$result=@mysql_query($query) or die(mysql_error());
?>

I cant see where you have defined $current_page.

 

Also try

 

<?php
session_start();
include ("config.php");
$user = $_SESSION['username'];
$chk="SELECT `page` FROM `users` where `username`='$user'";
$check=@mysql_query($chk) or die (mysql_error());

$row = mysql_fetch_row($check);

if($row[0] < $check) 
{
}
else
{
$query="update `users` set `page`='$currentpage' where `username`='$user'";
$result=@mysql_query($query) or die(mysql_error());
?>

 

I have $currentpage declared on each page that you visit. and it includes the updatepage.php file

<?php
session_start();
include ("config.php");
$user = $_SESSION['username'];
$chk="SELECT `page` FROM `users` where `username`='$user'";
$check=@mysql_query($chk) or die (mysql_error());

$row = mysql_fetch_row($check);

if($currentpage < $row[0]) 
{
}
else
{
$query="update `users` set `page`='$currentpage' where `username`='$user'";
$result=@mysql_query($query) or die(mysql_error());
?>

<?php
session_start();
include ("config.php");
$user = $_SESSION['username'];
$chk= mysql_query("SELECT `page` FROM `users` where `username`='$user'") or die(mysql_error());
$row = mysql_fetch_row($chk);
if($currentpage < $row[0]) 
{
}
else
{
$query= mysql_query("update `users` set `page`='$currentpage' where `username`='$user'") or die(mysql_error());
}
?>

 

try that...

Alright, for the above coding that I was previously inquiring about.

 

What it did was a user logged in. Went to various pages, it updated the page column for that user

Page 1 wrote the integer 1 into the table

Page 2 wrote the integer 2 into the table

Page 3 wrote the integer 3 into the table, etc.

 

Well now, I'm trying to make it where if the user is logged in. They can see the value of Page 3 (i.e. indexpage.html, or chapter1.html, or chaptertwo.html, etc.)

 

In order to do this, I created another database with Id, Page, ActualPage

Page from table 1 is supposed to be compared to Page from table 2. If they are equal, it displays ActualPage from table2

 

So if the user is on page 2(according to the database). When they login, I'll be able to display chapter1.html, or even create a link to it

 

$actupage = mysql_query("SELECT `actualpage` FROM `pages` where `page`='$getlevel'")
$url = "http://".$_SERVER['HTTP_HOST'].$getlevel

echo "<a href=".$url;.">Click Here</a>";

 

Or something along those lines.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.