Page 1 of 2

session help

Posted: Fri Apr 25, 2008 6:51 pm
by jay23
im tryin to create session data that will be used to produce a out for a sms system.
what is the correct way. here is the code below please help ASAP :)

session_start();
echo '<h1>Welcome';
if (isset($_SESSION['first_name']) && ($_SESSION['ad'])&& ($_SESSION['pcode'])&& ($_SESSION['phone'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';

Re: session help

Posted: Fri Apr 25, 2008 6:55 pm
by aceconcepts
session_start() should appear just below <?PHP at the top of your script

Re: session help

Posted: Fri Apr 25, 2008 7:01 pm
by jay23
<?
session_start();
echo '<h1>Welcome';
if (isset($_SESSION['first_name']) && ($_SESSION['ad'])&& ($_SESSION['pcode'])&& ($_SESSION['phone'])) {
echo ", {$_SESSION['first_name']}!";
}

how do i read in the session tho becuse it does not echo any thing to my page. i would like first name to be echoed and the other session values to use the "if isset"

Re: session help

Posted: Fri Apr 25, 2008 7:13 pm
by aceconcepts
try echoing first_name session variable alone - see if it has a value.

Re: session help

Posted: Fri Apr 25, 2008 7:36 pm
by jay23
<?
session_start();
echo '<h1>Welcome';
if (isset($_SESSION['first_name']) && ($_SESSION['ad'])&& ($_SESSION['pcode'])&& ($_SESSION['phone'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';
// get lessson id


yes the first name works if i just echo it alone. i want the first name only to be echoed the other session variables i jus wnt to echo them into a input form

Re: session help

Posted: Fri Apr 25, 2008 8:12 pm
by aceconcepts
I think your session data is working properly - it just looks like you have anexception with your if statement.

Re: session help

Posted: Fri Apr 25, 2008 9:54 pm
by jay23
session_start();
echo '<h1>Welcome';
if (isset($_SESSION['first_name'])) && if (isset($_SESSION['ad']))&& if(isset($_SESSION['pcode']))&& if(isset($_SESSION['phone'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';

is it posible to create mutliple if(isset($_SESSION['value'])) if iset sessions. i jus wnt to echo just the first_name

how would i do this:)

Re: session help

Posted: Fri Apr 25, 2008 10:10 pm
by jay23
how do o create a color scheme for my calendar so that of a lesson is available it show in a green font and if booked a red font, the calendar is seen from a global view and should represent this.
$result = mysql_query("SELECT * FROM calendar_event WHERE status='Available'&'Booked'");

while($row = mysql_fetch_array($result))



{
echo "<font color='green'>".$row['status'];

echo "<br />";
}


?>


i tink it would work better if it was done in a "if statment"

can someone help or advise me please

Re: session help

Posted: Fri Apr 25, 2008 10:17 pm
by flying_circus
jay23 wrote:session_start();
echo '<h1>Welcome';
if (isset($_SESSION['first_name'])) && if (isset($_SESSION['ad']))&& if(isset($_SESSION['pcode']))&& if(isset($_SESSION['phone'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';

is it posible to create mutliple if(isset($_SESSION['value'])) if iset sessions. i jus wnt to echo just the first_name

how would i do this:)
Your code is full of syntax errors. You don't need those nested if's.

I generally do something like this to make it a little easier to read:

Code: Select all

<?php
  # Start Session
    session_start();
    
  # Get Variables
    $firstName = (isset($_SESSION['first_name'])) ? $_SESSION['first_name'] : '';
    $ad = (isset($_SESSION['ad'])) ? $_SESSION['ad'] : '';
    $pcode = (isset($_SESSION['pcode']))  ? $_SESSION['pcode'] : '';
    $phone = (isset($_SESSION['phone'])) ? $_SESSION['phone'] : '';
    
  # Build Output
    if(!empty($firstName) && !empty($ad) && !empty($pcode) && !empty($phone)) {
      print "<h1>Welcome $firstName</h1>";
    }
?>

Re: session help

Posted: Fri Apr 25, 2008 10:23 pm
by flying_circus
I'm thinking your original query has a syntax error

Code: Select all

<?php
  $result = mysql_query("SELECT status FROM calendar_event");
 
  while($row = mysql_fetch_array($result)) {
    if($row['status'] == 'booked') {
      print "<font color='red'>" . $row['status'] . "</font>";
    } else {
      print "<font color='green'>" . $row['status'] . "</font>";
    }
    print "<br />";
  }
?>

Re: session help

Posted: Sat Apr 26, 2008 10:31 am
by jay23
<?
# Start Session
session_start();
echo '<h1>Welcome';
# Get Variables
$firstName = (isset($_SESSION['first_name'])) ? $_SESSION['first_name'] : '';
$ad = (isset($_SESSION['ad'])) ? $_SESSION['ad'] : '';
$pcode = (isset($_SESSION['pcode'])) ? $_SESSION['pcode'] : '';
$phone = (isset($_SESSION['phone'])) ? $_SESSION['phone'] : '';

# Build Output
if(!empty($firstName) && !empty($ad) && !empty($pcode) && !empty($phone)) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';


// get lessson id

$event_id = $_GET['id'];


//echo $event_id;



if (!empty($event_id)) { $_SESSION['recordId']=$event_id; }

else { $event_id = $_SESSION['recordId']; }

if (empty($event_id) || isset($_POST['cancel'])) {

die('here1');

Header("Location: editbook.php");

exit;




}



$var1 = $_GET["username"];
$var2 = $_GET["password"];
$var3 = $_GET["destination"];
$var4 = $_GET["message"];


$var4 = urlencode($var4);
if( strlen( $var4 ) > 1)
{
echo "url:<BR>";
$url = ("http://gw1.aql.com/sms/sms_gw.php?username=" . $var1 . "&password=" . $var2 . "&destination=" . $var3 . "&message=" . $var4 );
echo $url;
$handle = fopen( $url,'r' );
$response = fread($handle,1024);
echo "response:<BR>";
echo $response;
fclose($handle);

}
//echo "id".$event_id;




require_once("config.php");

$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "calendar_event";

$query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1";
$query_result = mysql_query ($query);
while ($info = mysql_fetch_array($query_result)){
$date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year']));
$time_array = split(":", $info['event_time']);

$time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year']));

echo $event_title;



?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHPCalendar - <? echo $info['event_title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cal.css" rel="stylesheet" type="text/css"></head>

<body>
<table width="400" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="100">
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><span class="eventwhen"><u><? echo $date . " at " . $time; ?></u></span><br>
<br> <br> </td>
</tr>

<tr>
<td><span class="event">Lesson Reference</span></td>
</tr>
<tr>
<td><span class="eventslot"><? echo $info['slot_id']; ?></span><br></td>
</tr>
<tr>
<td><span class="event">Lesson Time</span></td>
</tr>
<tr>
<td><span class="eventtime"><? echo $info['event_time']; ?></span><br></td>
</tr>

<tr>
<td><span class="event">Subject Title</span></td>
</tr>
<tr>
<td><span class="eventdetail"><? echo $info['event_title']; ?></span><br>
<br></td>
</tr>



<td><span class="event">Lesson Status</span></td>
<tr>
<td><span class="eventstate"><? echo $info['status']; ?></span><br>
<br></td>
</tr>

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









<tr>
<td><a href="clickcounter.php"> book</a></td>
</tr>

</table>




<FORM >
<div>
<INPUT TYPE=hidden NAME="username" VALUE="">
<INPUT TYPE=hidden NAME="password" VALUE="">
<INPUT TYPE=hidden NAME="destination" VALUE=""><BR>
Message:<BR>
<INPUT TYPE=hidden NAME="message" VALUE ="<?echo "Your Next Lesson is on".$date." at " . $time.".Your Instructor Will Be".$info['event_title'].$_SESSION['first_name']. $_SESSION['ad'].$_SESSION['pcode'].$_SESSION['phone']. "And Will Last Between".$info['event_time']. ". IF You Wish To Cancel Lesson Please Contact The School, Stating The Following Lesson Reference Number :".$info['slot_id'];?>">
<input type="hidden" name="link" value="">
<a href="clickcounter.php" onClick="document.forms[0].link.value='Book';doucment.forms[0].submit()">Book</a>
<input type="submit"value="Book"/>
</div>




</FORM>


</body>
</html>






<? }

?>
does not work im tryin to echo the first name session on screen then imput the other sessions in a SMS input form here:
"<INPUT TYPE=hidden NAME="message" VALUE ="<?echo "Your Next Lesson is on".$date." at " . $time.".Your Instructor Will Be".$info['event_title'].$_SESSION['first_name']. $_SESSION['ad'].$_SESSION['pcode'].$_SESSION['phone']. "And Will Last Between".$info['event_time']. ". IF You Wish To Cancel Lesson Please Contact The School, Stating The Following Lesson Reference Number :".$info['slot_id'];?>">"

how can i do i realy need this to work im working on my uni project, so it has to work some1 help :)

Re: session help

Posted: Sat Apr 26, 2008 11:38 am
by RobertGonzalez
EVERAH | PLEASE USE CODE TAGS WHEN POSTING CODE IN THE FORUMS. NORMALLY WE WOULD FIX THIS FOR YOU BUT THERE ARE WAY TOO MANY POSTS FOR ANY MODERATOR TO GO BACK AND EDIT. THANKS.

Before you get into all that extra code simply do a var_dump($_SESSION) to see what is in the session array. The session_start() call does not need to be right after the opening PHP tag, but it does need to be before any output is sent to the browser.

Also you may want to look closely at your conditionals. There are easy ways to build the if you want depending on what you really want to see.

Re: session help

Posted: Sat Apr 26, 2008 1:26 pm
by jay23

Code: Select all

<?
# Start Session
session_start();
echo '<h1>Welcome';
# Get Variables
$firstName = (isset($_SESSION['first_name'])) ? $_SESSION['first_name'] : '';
$ad = (isset($_SESSION['ad'])) ? $_SESSION['ad'] : '';
$pcode = (isset($_SESSION['pcode'])) ? $_SESSION['pcode'] : '';
$phone = (isset($_SESSION['phone'])) ? $_SESSION['phone'] : '';
 
# Build Output
if(!empty($firstName) && !empty($ad) && !empty($pcode) && !empty($phone)) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';
 
 
// get lessson id
 
$event_id = $_GET['id'];
 
 
//echo $event_id;
 
 
 
if (!empty($event_id)) { $_SESSION['recordId']=$event_id; }
 
else { $event_id = $_SESSION['recordId']; }
 
if (empty($event_id) || isset($_POST['cancel'])) {
 
die('here1');
 
Header("Location: editbook.php");
 
exit;
 
 
 
 
}
 
 
 
$var1 = $_GET["username"];
$var2 = $_GET["password"];
$var3 = $_GET["destination"];
$var4 = $_GET["message"];
 
 
$var4 = urlencode($var4);
if( strlen( $var4 ) > 1)
{
echo "url:<BR>";
$url = ("http://gw1.aql.com/sms/sms_gw.php?username=" . $var1 . "&password=" . $var2 . "&destination=" . $var3 . "&message=" . $var4 );
echo $url;
$handle = fopen( $url,'r' );
$response = fread($handle,1024);
echo "response:<BR>";
echo $response;
fclose($handle);
 
}
//echo "id".$event_id;
 
 
 
 
require_once("config.php");
 
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "calendar_event";
 
$query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1";
$query_result = mysql_query ($query);
while ($info = mysql_fetch_array($query_result)){
$date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year']));
$time_array = split(":", $info['event_time']);
 
$time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year']));
 
echo $event_title;
 
 
 
?>
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHPCalendar - <? echo $info['event_title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cal.css" rel="stylesheet" type="text/css"></head>
 
<body>
<table width="400" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="100">
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><span class="eventwhen"><u><? echo $date . " at " . $time; ?></u></span><br>
<br> <br> </td>
</tr>
 
<tr>
<td><span class="event">Lesson Reference</span></td>
</tr>
<tr>
<td><span class="eventslot"><? echo $info['slot_id']; ?></span><br></td>
</tr>
<tr>
<td><span class="event">Lesson Time</span></td>
</tr>
<tr>
<td><span class="eventtime"><? echo $info['event_time']; ?></span><br></td>
</tr>
 
<tr>
<td><span class="event">Subject Title</span></td>
</tr>
<tr>
<td><span class="eventdetail"><? echo $info['event_title']; ?></span><br>
<br></td>
</tr>
 
 
 
<td><span class="event">Lesson Status</span></td>
<tr>
<td><span class="eventstate"><? echo $info['status']; ?></span><br>
<br></td>
</tr>
 
</table></td>
</tr>
 
 
 
 
 
 
 
 
 
<tr>
<td><a href="clickcounter.php"> book</a></td>
</tr>
 
</table>
 
 
 
 
<FORM >
<div>
<INPUT TYPE=hidden NAME="username" VALUE="">
<INPUT TYPE=hidden NAME="password" VALUE="">
<INPUT TYPE=hidden NAME="destination" VALUE=""><BR>
Message:<BR>
<INPUT TYPE=hidden NAME="message" VALUE ="<?echo "Your Next Lesson is on".$date." at " . $time.".Your Instructor Will Be".$info['event_title'].$_SESSION['first_name']. $_SESSION['ad'].$_SESSION['pcode'].$_SESSION['phone']. "And Will Last Between".$info['event_time']. ". IF You Wish To Cancel Lesson Please Contact The School, Stating The Following Lesson Reference Number :".$info['slot_id'];?>">
<input type="hidden" name="link" value="">
<a href="clickcounter.php" onClick="document.forms[0].link.value='Book';doucment.forms[0].submit()">Book</a>
<input type="submit"value="Book"/>
</div>
 
 
 
 
</FORM>
 
 
</body>
</html>
 
 
 
 
 
 
<? }
 
?>


does not work im tryin to echo the first name session on screen then imput the other sessions in a SMS input form here:
"<INPUT TYPE=hidden NAME="message" VALUE ="<?echo "Your Next Lesson is on".$date." at " . $time.".Your Instructor Will Be".$info['event_title'].$_SESSION['first_name']. $_SESSION['ad'].$_SESSION['pcode'].$_SESSION['phone']. "And Will Last Between".$info['event_time']. ". IF You Wish To Cancel Lesson Please Contact The School, Stating The Following Lesson Reference Number :".$info['slot_id'];?>">"

how can i do i realy need this to work im working on my uni project, so it has to work some1 help

Re: session help

Posted: Sat Apr 26, 2008 2:02 pm
by RobertGonzalez
Everah wrote:EVERAH | PLEASE USE CODE TAGS WHEN POSTING CODE IN THE FORUMS. NORMALLY WE WOULD FIX THIS FOR YOU BUT THERE ARE WAY TOO MANY POSTS FOR ANY MODERATOR TO GO BACK AND EDIT. THANKS.

Before you get into all that extra code simply do a var_dump($_SESSION) to see what is in the session array. The session_start() call does not need to be right after the opening PHP tag, but it does need to be before any output is sent to the browser.

Also you may want to look closely at your conditionals. There are easy ways to build the if you want depending on what you really want to see.
Have you tried this yet? We can offer all the help in the world but if you are not going to try it the help will not go that far.

Let us know what is in the session array.

Re: session help

Posted: Sat Apr 26, 2008 9:17 pm
by jay23
wer do i use the var_dump($_SESSION); im not that good at php i have only started learning it for a few months now. stil a novice. help