help with sessions please
Moderator: General Moderators
Re: help with sessions please
still with the original problem ...
Re: help with sessions please
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
Note the missing =
Should be:
Code: Select all
if ($string = "String") {Code: Select all
if ($string == "String") {Re: help with sessions please
this one gave me
Parse error: syntax error, unexpected '/' in /home/biomagn1/public_html/recommendingpeople.com/test.php on line 14
Parse error: syntax error, unexpected '/' in /home/biomagn1/public_html/recommendingpeople.com/test.php on line 14
Re: help with sessions please
Looks like the double quotes aren't escaped either.
Re: help with sessions please
I literally posted it and pressed edit as soon as it was posted noticing this one, you guys give me no time lol.Benjamin wrote:Note the missing =Should be:Code: Select all
if ($string = "String") {Code: Select all
if ($string == "String") {
Re: help with sessions please
So what do you reckon benjamin. How can I fix this
Re: help with sessions please
This one wasn't my fault, i had aCode: 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" />";
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
looks good
Saw the int.Saw the string.
Saw the int.Saw the string.
Re: help with sessions please
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
this is what came up - not sure if good or bad but no errors anyway!!
Got nothing
had to include at top:
Got nothing
had to include at top:
Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>Re: help with sessions please
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:
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
Yes sorry I forgot about connections, good spot.timoteo wrote:had to include at top:Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
Is this not done in 'Connections/recommendingpeople.php'? lol.timoteo wrote: mysql_select_db($database_recommendingpeople, $recommendingpeople);
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'];
}
?>Re: help with sessions please
"Got something"
OK This worked better!!:
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
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'];
}
?>