Jump to content

Mysql/php: Redirected when already visited


Ogre

Recommended Posts

Hello,

 

I'm currently programming a site for my school as final work.

Some stuff works, other doesn't yet

 

anyway, here is my question:

 

People have to register on the site. Once they done it, and they revisit it, they shouldn't be able to visit it anymore. I want to check this with a control sign, in my database it is named 'controle'. When 'controle' is set to 1, it means they have registered them self already and they should be redirected to another page. I wrote something but it is not correct at all. Any ideas?

 


<?php $query ="SELECT naam FROM Leerlingenkeuzes"; // Selecteren it leerlingenkeuzes
$result = mysql_query($query) or die (mysql_error());//
$query .= " WHERE naam='".$naam."' AND controle='1' AND klas='".$klas."'";

$res=mysql_fetch_row($result);

while($res = mysql_fetch_array($result))
  {
if($res['controle']='1')
{
	header ("Location: /ingeschreven.php");
	echo $res['naam'];
}
else
{
echo $res['klas'];
}

  }
?>

Link to comment
Share on other sites

So, from the beginning: nothing is in my database yet.

I go to the site, register perfectly fine. My name and class are written down in a DB, also my 'controle' character got set to 1. This means that the next time I visit the page, I shouldn't be able anymore to go to it and I should be redirected to '/ingeschreven.php'

So let's say that 'Tom Tollenaere' '6IICT' and '1' are written down in the DB

 

So basicly, when I revisit the site, I shouldn't be able to do it anymore. This is not the case. I can still visit it

 

But after that I register another person into the database, as described above, with the following values: 'test jan' '6EE' '1'

Now when I re-go to the site with either logged in as Tom Tollenaere or as test jan or as any new user, it does redirect me to /ingeschreven.php

 

So it doesn't work, it just doesn't redirect me if I only registered one person, and it redirects me every time after I registered 2 persons...

It should be individual for every person, so if person X has been there before, he shouldn't be able to visit it again, but if person Y is new, he should be able to visit it till he registered himself...

 

I hope this helped you

Link to comment
Share on other sites

For a start, this line is using the assignment operator '=', when it should have the comparison operator '=='. Based on that, I would expect it would redirect regardless of the result from the database. Make that change and see if anything is different.

if($res['controle']='1')

 

You should also follow any header() redirect with exit() to stop further execution of the script.

header('Location: somepage.php');

exit();

Link to comment
Share on other sites

It works now, this is what I had to do:

 

 

<?php$query = mysql_query("SELECT * FROM Leerlingenkeuzes WHERE naam='$naam' AND klas='$klas'");

$user = mysql_fetch_array($query);

if($user['controle'] == 1){
header ("Location: /ingeschreven.php");
exit();
}
else
{
}?>

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.