phorce 131 Posting Whiz in Training Featured Poster
<?php
session_start();

include "db_connect.php";

$username = $_POST['username'];
$pass = $_POST['pass'];

mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";

$resultado = mysql_query($sql, $connect) or die(mysql_error());

$num = mysql_fetch_assoc($resultado);

if ($username == $num['username'] AND $pass == $num['password']) {
        echo "Yes logged in :)";
        } else {
        echo "Could not log in :(";
        }
mysql_close($con);
?>

Please can you run this code, login and tell me if it says:

Yes logged in :)
OR
Could not log in :(

phorce 131 Posting Whiz in Training Featured Poster

Change

$sql="SELECT username, password FROM alunos WHERE username='". $username. "' AND '". $pass ."'";

To:

$sql = "SELECT username, password FROM alunos WHERE username='$username' AND password='$pass'";

:)

phorce 131 Posting Whiz in Training Featured Poster

That sounds to me like it's not sessions, it's something to do with your database.. In "validpass.php" you check to see if the username/password is correct or not, if it's not correct then it will redirect you to the login form..

Are you sure your SQL query is right AND you're entering the correct details? :)

phorce 131 Posting Whiz in Training Featured Poster

Just to clarify, it works, then when you sign out.. It redirects you the page that says "Welcome, Guest!" and then when you try and sign back in, does it say "Welcome [blank]" or does it redirect you back to the login form?

This is really, really weird.. It's working perfectly fine on my system :(

phorce 131 Posting Whiz in Training Featured Poster

It's really weird haha! Can you please post what you are using for "logout"?

phorce 131 Posting Whiz in Training Featured Poster

Let's do a test =)

Create a new page (call it test.php) that has this code in it:

<?php
    session_start();

    function is_logged()
    {
        if(isset($_SESSION['loggedin']))
        {
            return true;
        }else{
           return false;
       }
   }

   if(is_logged())
   { 
        echo "Welcome, {$_SESSION['username']}";
   }else{
      echo "Welcome, Guest";
   }

And then change your "validpass.php" to this:

<?php
session_start();

include "db_connect.php";
mysql_select_db($dbname, $connect);
     
$username = $_POST['username'];
$pass = $_POST['pass'];
   
$sql="SELECT username, password FROM alunos WHERE username='". $username. "' AND '". $pass ."'";
$resultado = mysql_query($sql, $connect) or die(mysql_error());
if(mysql_affected_rows() == 1)
{
    $_SESSION['username'] = $username;
    $_SESSION['loggedin'] = 1;
    header("Location: test.php");
}else{
  header("Location: login_form.php");
}
mysql_close($con);

?>

If this doesn't work, can you please use this (in test.php):

var_dump ($_SESSION['username']);
var_dump ($_SESSION['loggedin']);

Hope this helps you =) It worked when I tried it on my server!

phorce 131 Posting Whiz in Training Featured Poster

Right, I'm really sorry about this.. >.< Let me write the script (again) and I'll see what the problem is.. :) Hopefully, this should finally work haha!

phorce 131 Posting Whiz in Training Featured Poster

That's weird haha

<?PHP
    session_start();

    include 'topo.php';
    //user 'logado' ou nao
    function is_logged()
    {
    if(isset($_SESSION['username'])) {
    return true;
    }else{
    return false;
    }
    }
    ?>
     
    <!--content-->
    <table width = 100%>
    <tr>
     
    <h2>Bem Vindo à Escola de Música de V.N.Gaia</h2>
     
    <tr>
    <font color = "green" size="3">
    Welcome,
	
	<?php
    if(is_logged())
    {
    echo $_SESSION['username'];
    }else{
    echo "Guest!";
    }
    ?>
    
	</font>
    </tr>

Removed the ob_start(); should work! That's the only thing I can think it might be.

phorce 131 Posting Whiz in Training Featured Poster

Does it work if you sign back in again? When you logout, it will unset the session and return back to "Welcome, guest"

phorce 131 Posting Whiz in Training Featured Poster
phorce 131 Posting Whiz in Training Featured Poster
<?PHP
    ob_start();
    session_start();

    include 'topo.php';
    //user 'logado' ou nao
    function is_logged()
    {
    if(isset($_SESSION['username'])) {
    return true;
    }else{
    return false;
    }
    }
    ?>
     
    <!--content-->
    <table width = 100%>
    <tr>
     
    <h2>Bem Vindo à Escola de Música de V.N.Gaia</h2>
     
    <tr>
    <font color = "green" size="3">
    Welcome,
	
	<?php
    if(is_logged())
    {
    echo $_SESSION['username'];
    }else{
    echo "Guest!";
    }
    ?>
    
	</font>
    </tr>

Try that. Just initialised the session_start();

phorce 131 Posting Whiz in Training Featured Poster
#include <iostream> 
#include<cmath>
using namespace std;
int main()
{ 
	
	for(int i=0; (i < 7); i++)
	{
		cout << "*";
	}
	
	cout << "\n ";
	
	for(int i=0; (i < 5); i++)
	{
		cout << "*";
	}
	
	cout << "\n  ";
	for(int i=0; (i < 3); i++)
	{
		cout << "*";
	}
	
	cout << "\n   ";
	cout << "*";
return EXIT_SUCCESS;
}
phorce 131 Posting Whiz in Training Featured Poster

Enscription or Encryption? I'm confused!

phorce 131 Posting Whiz in Training Featured Poster

Also if you're doing profiles (I'm guessing you want other people to view these profiles?)

You'll need to write another script that handles it, there are many ways but:

www.yoursite.com/user/view_profile.php?id={user_id}

<?php

     $id = $_GET['id'];

     echo "Viewing profile for, $id";
?>

Then you can write sql select statements that selects all the information depending on the user id.. Look at like SQL injections so it's a lot more secure!

phorce 131 Posting Whiz in Training Featured Poster

Noticed a few things.

<?php 
session_start();
include "config.php";

if (!isset($_SESSION['username']))
{
	header('location: login.php');
}

echo "Welcome, " . $_SESSION['username'];
$result = mysql_query("SELECT username, full_name FROM user WHERE username='$username'")
or die(mysql_error());
$row=mysql_fetch_array($result);

echo "Hi, " . $row['full_name']; // You haven't selected "full_name"

?>
<p>Would you like to edit your <a href="editprofile.php">profile?</a><p>

What error(s) do you have? I'm guessing that the row "full_name" is storing two attributes inside i.e. "Joe Bloggs" this is bad database design!

phorce 131 Posting Whiz in Training Featured Poster

Try:

<?php
session_start();

include "db_connect.php";

$username = $_POST['username'];
$pass = $_POST['pass'];

mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";

$resultado = mysql_query($sql, $connect) or die(mysql_error());

$num = mysql_fetch_assoc($resultado);

if ($username == $num['username'] AND $pass == $num['password']) {
        $_SESSION['username'] = $username; // this will store the value of username in the session value.
	header("Location: index.php");
	} else {
	header("Location: login_form.php");
	}
mysql_close($con);
?>

You can also reduce the code by querying the username AND password together in one query.

phorce 131 Posting Whiz in Training Featured Poster

Did the session thing work?

And no problem, if you need anything else, feel free to ask =)

phorce 131 Posting Whiz in Training Featured Poster
<?PHP

include 'topo.php';

//user 'logado' ou nao
function is_logged()
{
   if(isset($_SESSION['username'])) { 
     return true;
 }else{
    return false;
 }
} 
?>

<!--content-->
<table width = 100%>
<tr>

<h2>Bem Vindo à Escola de Música de V.N.Gaia</h2>

<tr>
<font color = "green" size="3">
Welcome, 
<?php 
if(is_logged())
{
   echo $_SESSION['username']; 
}else{
  echo "Guest!";
}
?> 
</font>
</tr>

<td class = "table_title">
<h3> A Nossa Escola </h3>
<p align = "justify"> 
A Escola de Música de V.N.Gaia existe desde 1979. O nosso principal objectivo é incentivar o gosto musical de todas as pessoas seja qual for a idade.
<br/>
Os nossos Cursos estão divididos por graus (1º ao 5º) e no final de cada ano lectivo serão inseridas as notas dos alunos.
Essas notas resultam do trabalho, não só individual mas também a integração em grupo. 
</p>
</td>

<td width = 3%></td>

<td width = 20% class = "table_title"> 
<h3> Cursos </h3>
<table>
<tr>

<tr>
<td>Guitarra Elétrica</td>
</tr>

<tr>
<td> Piano</td>
</tr>

<tr>
<td> Violoncelo</td>
</tr>

<tr>
<td> Saxofone</td>
</tr>

<tr>
<td> <a href = "cursos.php"> <img src = "images/button.jpg"></img> </a> </td>
</tr>

</tr>
</table>
</td>


<td width = 3%></td>


<!----------JAVASCRIPT VALIDAR LOGIN---------------->
<script>
function validar() {
	if (document.getElementById("username").value.length==0) { 
		alert("Introduza o seu Login");
		document.getElementById("username").focus();
		return false;		
	}
	if (document.getElementById("pass").value.length==0) { 
		alert("Introduza a sua Password");
		document.getElementById("pass").focus();
		return false;		
	}
}
</script>

<?php
if(!is_logged())
{
?>
<!-------------------FORM LOGIN--------------------->
<td class = "table_title">
<h3> Log In </h3>
<form name="loginform" METHOD="POST" action="validapass.php" onsubmit="return validar()">
	<table class=textologin align="center" cellspacing="0" cellpadding="0" width="25%">
        <tr><td height="50"></td></tr>
			<tr>
               <td width="50">Username:&nbsp;</td>
               <td width="150" align="left"><input …
phorce 131 Posting Whiz in Training Featured Poster

By the looks of this script (I haven't ran it) but you're storing the users data in XML.. This isn't the safest route to go down..

I wouldn't go down the "Javascript" route either, do a simple check to see if the user is signed in or not.. You're already setting a session (username) if the user has successfully signed in.. Just do a check on it!

phorce 131 Posting Whiz in Training Featured Poster

I THINK (Don't blame me if I'm wrong -- Just a suggestion)

But you want it so that:

1. Checks to see if the disclaimer has been checked (This would auto be set to 0)
2. The user clicks on something like "accept" which then they submit a button
-- This would set the value to 1 and redirect the user to whatever page.

As Ardav rightly said, have a page that checks to see if the user has checked the disclaimer:

if(!isset($_SESSION['dis']))header("Location: read_disclaimer.php");

read_disclaimer.php
But, you need a way to to set it so something like:

<?php
     session_start();
     if(!isset($_POST['submitted']) && $_SESSION['dis'] != 1) // Check if form hasn't been submitted/session hasn't been set
     {
          echo '<form method="post" action="">';
		   // rest of the input boxes etc
		
			echo '<input type="submit" name="submit" value="Continue">';
			echo '<input type="hidden" name="submitted" value="TRUE">';
	  }else{
		
		// The form has been submitted.
		$_SESSION['dis'] = 1; // Set's the disclaimer to be 1
		header("Location: the_page.php"); // Redirect to whatever page you want
	}
?>

Does this make any sense? I may be wrong, just offering my opinion :)

phorce 131 Posting Whiz in Training Featured Poster

there is code to make space betwen text, if you do like 10x space it will still be one space but one simple code read full space.
bye

You don't mean the "code" &nbsp; do you? This will allow space between text..

phorce 131 Posting Whiz in Training Featured Poster

I'd have a function that checks to see if the user is logged in or not:

<?php
   function is_logged()
   {
       if(isset($_SESSION['username'])) { // user is signed in
          return true;
     }else{
       return false;
     }
   }
?>

And then for each page (Let's say Guitar) have this:

<?php

     if(is_logged())
     {
          // Display button for particular music thing
     }else{
        // display nothing 
     }
?>

Then you can re-use the same code over and over again and for each page, run the function :)

phorce 131 Posting Whiz in Training Featured Poster

I don't get why you have two index pages? :S

If for example your index.php page contained the login form, and the index_log didn't contain the login form but contained "Hello {username}" then wouldn't it be easier to have one index file that did:

<?php

   if(isset($_SESSION['username'])) { // user is signed in
       // display "Hello username"
   }else{
     // displat the login form
   }
?>

and then just refresh to index.php? And if it's failed, just display a message?

phorce 131 Posting Whiz in Training Featured Poster

Hey Jonny :)

Which University are you studying at?

phorce 131 Posting Whiz in Training Featured Poster

Could you please tell us what the errors are? Also, noticed a few things:

1) Your "idno" should be set as AUTO_INCREMENT inside your database.
2) You should define your variables better, or, at least define them and run some checks on them before they get entered into the database.

phorce 131 Posting Whiz in Training Featured Poster

It's unclear what you want to do...

<?php
session_start();

include "db_connect.php";
mysql_select_db($dbname, $connect);

$username = $_POST['username'];
$password  = $_POST['pass'];

$sql="SELECT username, password FROM alunos WHERE username='". $username. " AND password='".$password. "'";
$resultado = mysql_query($sql, $connect) or die(mysql_error());
if(mysql_affected_rows() == 1)
{
       header("Location: index.php");
}else{
    header("Location: login_form.php");
}
mysql_close($con);
?>

What is "index_log.php"? Are you declaring your sessions/cookies in this file?

Hope this helps =)

phorce 131 Posting Whiz in Training Featured Poster

to log out just unset variables you did set and destroy the session. I can see validation in JS, that is bad unless it there is of course another check in Server side.

Hello I do not want to seem to contradict you but I've always been taught that validation (client side) is a good way rather than doing it server side, this is because:

1) Reduces time : Why have something that has to wait for something (the server) when you can get an instant response?

2) What is the point of submitting data to the server, only to throw an error that certain information hasn't been submitted?

3) What if the server is down?

=)

phorce 131 Posting Whiz in Training Featured Poster

Hey, I think this would be a complex application to write. But, is possible.. For example: If you know the algorithm of your application, interpret this as symbols/images..

e.g.
for every "if statement" display a diamond & write the conditions

I'd go down that route anyway!

phorce 131 Posting Whiz in Training Featured Poster

I know how arrays work. The problem is that I don't know how to put the numbers in order. Example if I input 20 number:
10, 2, 2, 3, 1, 2, 6 ,9 ,6 ,4 ,11 ,21 ,32 ,21 ,25 ,36 ,36, 35 ,25, 26

How could I get the answer to be in descending order by the program.

You could just do a bubble sort after the another number was inputted..

phorce 131 Posting Whiz in Training Featured Poster

Okay.. This is how I would do it..

1. Check to see if the user is online

2. Store it using JSON which would output something like this:

{"user1":"true","user2":"false"}
// user1 is signed in, user2 isn't

3. Then use something like curl to get this information
www.domain1.com/checkUser.php?key=20420420
(The key for security)

4. Decode the json and then do whatever you want on the variable.

Does this make sense, or, have I just confused you even more?

I don't see why you're storing the values in a .txt file!

phorce 131 Posting Whiz in Training Featured Poster

I'm no expert, but I think this is what you're trying to do:

- Execute a script on "domain1.com" that checks if the user is logged in
- Stores the result in JSON

- On "domain2.com" have a script that reads the JSON and then checks whether someone is signed in

Is this correct?

phorce 131 Posting Whiz in Training Featured Poster

Hello, I dunno if this helps but noticed a few things in your code:

int main{

-- Does this even compile?

for (;t<choice;)

-- What are you trying to do here?

results = searchList(random [i],t,temp);

-- I think you're trying to store "results" from a function, but, where is the function "searchList"?

:)

phorce 131 Posting Whiz in Training Featured Poster

What is the problem using Googles API's? Can you post the google api code that you wrote to translate?

phorce 131 Posting Whiz in Training Featured Poster

Thank you for your help im going to try it later bit busy right now
could you explainwht you mean in main by

return Exit_SUCCESS;
}

Basically, it's a return type.. Just returns like "TRUE" or "FALSE" you should add it to every main/function (that isn't void)

int numbers(int number1, int number2)
{
    if(number1 > number2)
    {
      return true;
    }else{
      return false;
    }
}

if(numbers(1, 4))
{
    cout << "False";
}else{
   cout << "True";
}

Make sense? =)

phorce 131 Posting Whiz in Training Featured Poster

i dunno if this would work but:

Class "Lottery.h"

class Lottery
{
    public:
        Lottery();
    
        Lottery(int &theBalls);
        void setBall(int theBall);
        int getBall();
    private:
        int ball;
        int balls[500];
    
};

Functions "Lottery.cpp"

#include<iostream>
#include<string>
#include "Lottery.h";

Lottery::Lottery(){};

Lottery::Lottery(int &theBalls)
{
    // Could store them into an array
    // Can someone help with this?
    
}

void Lottery::setBall(int theBall)
{
    ball = theBall;
    
}

int Lottery::getBall()
{
    return ball;
    
}

Main "main.cpp"

#include <iostream>
#include "Lottery.h"

using namespace std;
Lottery lottery[500];


void january()
{
    lottery[0].setBall(10);
    lottery[1].setBall(20);
    lottery[2].setBall(30);
    
}

void feb()
{
    lottery[3].setBall(3403234);
    lottery[4].setBall(2140214);
    lottery[5].setBall(2140214);
}

int main()
{    
    january();
    cout << lottery[0].getBall() << endl;
    
    return EXIT_SUCCESS;
}

If that makes sense? I don't want to go into like Maps and stuff. Do you have to do it using a class?

Hope this helps you though... For the Mode, you could get the data range of a specific month!

phorce 131 Posting Whiz in Training Featured Poster

They'd just be an array.. 2 seconds, let me try something :)

phorce 131 Posting Whiz in Training Featured Poster

Firstly... Your class can be written a lot better:

class

class Lottery 
{
	public:
	         void setBall(int theBall);
		 int getBall();
	private:
		int ball;
};

functions

#include<iostream>
#include<string>
#include"Lottery.h";//include the lottery object header
using namespace std;
//constructor

lottery::lottery(int theBall)
{
     ball = theBall;
}

void lottery::setBall(int theBall)
{
   ball = theBall;
}
int lottery::getBall()
{
    return ball;
}

And then in main you could have:

#include <iostream>
#include "lottery.h"
using namespace std;
int main(int argc, char *argv[]) {

	Lottery lottery[500]; // 500 objects
	
	lottery[0].setBall(40);
	
	return EXIT_SUCCESS;
}

Then you'd have an array to work with. I haven't compiled this, but, this seems to be a much better way to set out classes than what you have (Not saying you're wrong, an excellent attempt) But.. You don't need to declare that many integers when you can use arrays :)

phorce 131 Posting Whiz in Training Featured Poster

Could you please post your code (so far) So we have something to work on =)

phorce 131 Posting Whiz in Training Featured Poster

Hey, can you post what you have in your "My Documents.txt" file and, for future reference put your code in tags (Y)

Also, you wouldn't need 15 arrays, only one array that stores the values.. That's the point of an array! :)

phorce 131 Posting Whiz in Training Featured Poster

Hello

Sessions or cookies (specifically cookies) can work effectively for this problem.

Alternatively, you could store whether they have accepted into a database, via their IP or username..

phorce 131 Posting Whiz in Training Featured Poster

Please could you post what you have so far please? Show us something we can work on, without having to guess what you're using!

Also, have a look into the LINQ library which could sort the DOB easier.

Hope this helps =)

phorce 131 Posting Whiz in Training Featured Poster

Hello, basically I have two tables:

People
Orders

Now I want to grant the first person in "Peoples" with all privileges, now I've tried to do this:

GRANT ALL
ON Orders 
TO {testUser |PUBLIC |role_name} 
[WITH GRANT OPTION];

Doesn't work (because they are technically not a user, therefore, cannot do anything anyway) SO, I tried to make a new user in my database using this:

CREATE USER 'testUser@localhost' IDENTIFIED BY 'mypass'

Which returns: "Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation"
Even though I'm signed in as the administrator, does anyone have any ideas?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hey thanks for the reply, this is really confusing me :(

I have like 7 tables in this database.. If I was to create a separate table for like Colour etc, I'd have like a hundred tables aha!

phorce 131 Posting Whiz in Training Featured Poster

Hello there, wonder if you can help me..

I've got to normalise a database, up to 3NF and wonder if you do the normalisation on each individual table, OR the database as a whole?

I've got this so far:

Attributes:
registration_No
Make
Model
Type
Cylinder
Body Type
Transmission
Air Conditioning
Colour
Photo
passenger

The key is registration_No and the functional dependancies are:
registration_No -> {Make, Model, Type, Cylinder, Body Type, Transmittion, Air_Conditioning, Color, Photo, Passenger}


And this table is in: 1NF, 2NF and 3NF..

Does this look ok, or am I doing it wrong?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm developing a system that emails people like a week before a particular date.. But they don't actually have to visit the page to receive the email, is this possible?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

I kinda get it.. But basically:

I will have two maps that will contain two sets of values:

Alphabet 1 (sorted) Alphabet 2
B = 10 C = 20
A = 3 B = 10
C = 2 A = 4

And then swop them..

B->C
A->B
C->A

Now would it be easier to store them into an array, do a bubble sort to get the (hightest->lowest) values?

This is easy, but I'm confused about maintaining the alphabet values is hard, for example:

If I sorted

A = 10.2;
B = 20;
C = 10;

A would be 20

But I just want B = 20 to come before A

If that makes sense? That's why I thought a map would be easier but clearly not!

phorce 131 Posting Whiz in Training Featured Poster

Thanks for your reply..

Kinda confused, a map will allow me to have two variable types (char, int) which is what I need to do!
But a vector will allow it? (I'm really new to vectors and maps)

Couldn't I just put the map into a list and then sort it like that?

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have a map that contains the alphabet (key) and a double (value) and I would like to sort the list so that the highest value is at the top but it still keeps it's key..

E.g.

#include <iostream>
#include <map>

int main()
{
     map<char, double> alphabet;
     alphabet['a'] = 10.2;
     alphabet['b'] = 20;
     alphabet['c'] = 10;

     return 0;
}

list would be:

B = 20;
A = 10.2
C = 10

Any ideas?

Also, is there a way that will allow the values to be set like a Dictionary in C# e.g.

public map<char, double> alphabet()
{
     // set the values
};

Any help would be amazing, thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I have done this manually and produced the decrypted text. Basically I used (for example):

The frequency of A = 10 (cipher text) and the frequency of E = 7 (alphabet)
But, the problem is that some of the alphabet occurs twice.. So like

C = 2
D = 2
F = 2

So it's hard to get an exact result..

phorce 131 Posting Whiz in Training Featured Poster

I private messaged you aha! Thanks by the way!