Page 3 of 4

Re: help with sessions please

Posted: Wed Jan 12, 2011 10:17 am
by timoteo
still with the original problem ...

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:01 pm
by Neilos
Well I suggest that we keep trying tests until we pinpoint the problem. Try another if statement, this time using sessions as this might also be the problem;

Code: Select all

<?php

session_start();

$_SESSION['int'] = 1;
$_SESSION['string'] = "String";

$int = $_SESSION['int'];
$string = $_SESSION['string'];

if ($int == 1) {
echo "Saw the int";
} else {
echo "No int :(";
}

if ($string == "String") {
echo "Saw the string";
} else {
echo "No string :(";
}

?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:02 pm
by Benjamin
Note the missing =

Code: Select all

if ($string = "String") {
Should be:

Code: Select all

if ($string == "String") {

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:13 pm
by timoteo
this one gave me

Parse error: syntax error, unexpected '/' in /home/biomagn1/public_html/recommendingpeople.com/test.php on line 14

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:18 pm
by Benjamin
Looks like the double quotes aren't escaped either.

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:30 pm
by Neilos
Benjamin wrote:Note the missing =

Code: Select all

if ($string = "String") {
Should be:

Code: Select all

if ($string == "String") {
I literally posted it and pressed edit as soon as it was posted noticing this one, you guys give me no time lol.

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:31 pm
by timoteo
So what do you reckon benjamin. How can I fix this

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:37 pm
by Neilos

Code: Select all

echo "No int <img src="./images/smilies/icon_sad.gif" alt=":(" title="Sad" />";
}

if ($string == "String") {
echo "Saw the string";
} else {
echo "No string <img src="./images/smilies/icon_sad.gif" alt=":(" title="Sad" />";
This one wasn't my fault, i had a :( in the echo and phpBB posted all that junk. it was supposed to read echo "No string found :(";

I didn't review my posted code properly. ARRRGH ok try this;

Code: Select all

<?php

session_start();

$_SESSION['int'] = 1;
$_SESSION['string'] = "String";

$int = $_SESSION['int'];
$string = $_SESSION['string'];

if ($int == 1) {
echo "Saw the int.";
} else {
echo "No int found.";
}

if ($string == "String") {
echo "Saw the string.";
} else {
echo "No string found.";
}

?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:40 pm
by timoteo
looks good :D

Saw the int.Saw the string.

Re: help with sessions please

Posted: Wed Jan 12, 2011 2:56 pm
by Neilos
ok good. Try this (untested);

Code: Select all

<?php

session_start();

// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$_SESSION['string'] = "french";

$username = $_SESSION['string'];

$query = "SELECT userid FROM rsusername WHERE username='$username';";
$result = mysql_query($query);

if (!$result) {
echo "Got nothing";
} else {
echo "Got something";
}

?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 3:06 pm
by timoteo
this is what came up - not sure if good or bad but no errors anyway!!
Got nothing

had to include at top:

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 3:14 pm
by timoteo
I made an adaption and included a recordset and "Got something"
However not without problems -c ame up with

Got something
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/biomagn1/public_html/recommendingpeople.com/test.php on line 26

line 26 is empty

complete code:

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_username = "SELECT * FROM username";
$username = mysql_query($query_username, $recommendingpeople) or die(mysql_error());
$row_username = mysql_fetch_assoc($username);
$totalRows_username = mysql_num_rows($username);


session_start();

// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$_SESSION['string'] = "french";

$username = $_SESSION['string'];

$query = "SELECT userid FROM username WHERE username='$username';";
$result = mysql_query($query);

if (!$result) {
echo "Got nothing";
} else {
echo "Got something";
}


mysql_free_result($username);
?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 3:34 pm
by Neilos
timoteo wrote:had to include at top:

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
Yes sorry I forgot about connections, good spot.
timoteo wrote: mysql_select_db($database_recommendingpeople, $recommendingpeople);
Is this not done in 'Connections/recommendingpeople.php'? lol.

Code: Select all

<?php

require_once('Connections/recommendingpeople.php');

mysql_select_db($database_recommendingpeople, $recommendingpeople);

session_start();

// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$_SESSION['string'] = "french";

$username = $_SESSION['string'];

$query = "SELECT userid FROM rsusername WHERE username='$username';";
$username = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($username);

if (!$result) {
echo "Got nothing";
} else {
echo $row['userid'];
}

?>
The reason you got the error was because you changed the variable $username after setting it to the query

Re: help with sessions please

Posted: Wed Jan 12, 2011 3:53 pm
by timoteo
"Got something"

OK This worked better!!:

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_username = "SELECT * FROM username";
$username = mysql_query($query_username, $recommendingpeople) or die(mysql_error());
$row_username = mysql_fetch_assoc($username);
$totalRows_username = mysql_num_rows($username);


session_start();

// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$_SESSION['string'] = "french";
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_username = "SELECT * FROM username";
$username = mysql_query($query_username, $recommendingpeople) or die(mysql_error());
$row_username = mysql_fetch_assoc($username);
$totalRows_username = mysql_num_rows($username);


$username = $_SESSION['string'];

$query = "SELECT userid FROM username WHERE username='$username';";
$result = mysql_query($query);

if (!$result) {
echo "Got nothing";
} else {
echo "Got something";
}


?>

Re: help with sessions please

Posted: Wed Jan 12, 2011 4:05 pm
by Neilos
I think that your connection to the database was the problem. Try this now;

Code: Select all

<?php
require_once('Connections/recommendingpeople.php');

// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$username = "french";

mysql_select_db($database_recommendingpeople, $recommendingpeople);

$query = "SELECT * FROM username WHERE username='$username';";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row = mysql_fetch_assoc($result);

if (!$result) {
echo "Got nothing";
} else {
echo $row['userid'];
}


?>