I am doing my web app and the session variable drives me crazy, pls any one could help me. the only session variable I have is the user name which should be shown in all operations. this is the search.php code and it works just once and if i want to search again I lose the session variable:
<?php
session_start();
if (isset($_POST['mynmae'])){
$_SESSION['myname']=$user;
$user=$_POST['mynmae'];
}
<form action="" method="post">
<button type="submit" ></button>
</form>
<?php
if (isset($_SESSION['myname'] )) {
echo( "Hi " .$_SESSION['myname']. " here are the search result.");
} else {
};
$conn = mysql_connect("localhost", "root", '');
mysql_select_db("db103",$conn);
$fname = '';
if (isset($_POST['search']))
{
$fname = $_POST['search'];
}
else{}
if(isset($_SESSION["myname"])){
$user='';
$user=$_SESSION["myname"];
$sql = "SELECT * FROM telephone_guide where owner='$user' and (firstName like '%$fname%' or secondName like '%$fname%' or phonenumber like '%$fname%' or celnumber like '%$fname%')";
$result = mysql_query($sql, $conn) ;
// number of rows fetched
$num = mysql_num_rows($result);
echo("<table width=300 border=3 >");
echo("<th>Modify<th>First Name<th>Second Name<th>tele-Phone Number<th>cel_phone number<th>Date<th>Address");
while ($arr = mysql_fetch_array($result)) {
$e="Modify";
echo("<tr><td><a href='update1.php?id1=$arr[0]'>$e</td><td>$arr[2]</td><td>$arr[3]</td><td>$arr[4]</td><td>$arr[5]</td><td>$arr[6]</td><td>$arr[7]</td></tr>");
}
echo("</table>");
?>
<br>
<br>
<?php
echo("</div>");} else{
}
?>
the second one is my update code which dose not show my session variable, do not know why however edit and delete operations work correctly
<?php
session_start();
$conn = mysql_connect("localhost", "root", '');
mysql_select_db("db103",$conn);
$id=$_GET['id1'];
$sql = "SELECT * FROM telephone_guide where id='$id' ";
$result = mysql_query($sql, $conn) ;
$arr= mysql_fetch_array($result);
echo("<form name=f1 method='post'>");
if (isset($_SESSION['myname'] )) {
echo( "Dear " .$_SESSION['myname']. " you can change or delete<br>your info here.");
} else {
};
echo("<table>");
echo("<tr><td><p> ID: </p><td><input type=text name=id value=$arr[0] readonly></tr><br>");
echo("<tr><td><p>First Name:</p> <td><input type=text name=fn value=$arr[2]></tr>");
echo("<tr><td><p>second Name:</p><td><input type=text name=sn value=$arr[3]><tr>");
echo("<tr><td><p>Telephone:</p><td><input type=text name=tel value=$arr[4]></tr>");
echo("<tr><td><p>celphone:</p><td><input type=text name=cel value=$arr[5]></tr>");
echo("<tr><td><p>Birth date:</p><td><input type=text name=birth value=$arr[6]></tr>");
echo("<tr><td><p>Address:</p><td><input type=text name=add value=$arr[7]></tr>");
echo("</table>");
?>
<button type="submit" name="edit" id="edit"><b>Update</b></button>
<?php
if(isset($_REQUEST['edit'])){
$f=$_REQUEST['fn'];
$s=$_REQUEST['sn'];
$t=$_REQUEST['tel'];
$c=$_REQUEST['cel'];
$b=$_REQUEST['birth'];
$a=$_REQUEST['add'];
$conn = mysql_connect("localhost", "root", '');
mysql_select_db("db103",$conn);
$sql = "update telephone_guide set id='$_POST[id]',firstName='$f',secondName='$s',phonenumber='$t',celnumber='$c',birth='$b',adress='$a'
where id='$_REQUEST[id1]'";
$result = mysql_query($sql, $conn) ;
header('location:view.php');
}
if(isset($_REQUEST['delete'])){
$f=$_REQUEST['fn'];
$s=$_REQUEST['sn'];
$t=$_REQUEST['tel'];
$c=$_REQUEST['cel'];
$b=$_REQUEST['birth'];
$a=$_REQUEST['add'];
?>
<script>
if(window.confirm("Are you sure you want to delete this ?")) return true;
<?php
$conn = mysql_connect("localhost", "root", '');
mysql_select_db("db103",$conn);
$sql = "DELETE FROM telephone_guide WHERE id='$_REQUEST[id1]'";
$result = mysql_query($sql, $conn) ;
header('location:view.php');
}
echo("</form>");
?>
</script>
<?php
echo("<form method=post >");
?>
<button type="submit" name="delete" ><b>Delete</b></button>