I am having troubles in my coding

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
In one of my pages after the login page,I use some data selected from a database and save them in a session but when i was about calling those data in session at the next page so that I can have those data inserted into another table.It was giving me empty data in the new table.PLSSSSSS help o!
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Would you mind posting the relevant parts of your code? It's really hard to tell where the problem might be if you don't. Oh -- and are you using the default session handlers or are you storing your session in a database?
 

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
employerappreceived.php
<?php session_start(); if(!isset($_SESSION['myusername'])) header("location:http://localhost/irs/login/loginphase.htm");?>

<?php
//store the data in session
$appdate=date('Y-m-d');
$host="localhost"; // Host name
$hostusername="root"; // Mysql username
$hostpassword="root"; // Mysql password
$db_name="jobdatabase"; // Database name
$tbl_name="appsent"; // Table name
$varholder=$_SESSION['myusername'];
$con= mysql_connect("localhost","root","root");
mysql_connect("$host", "$hostusername", "$hostpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result=mysql_query("SELECT * FROM appsent WHERE employer='$_SESSION[myusername]' ");
if (!$result) {

echo 'Could not run query: '. mysql_error();
exit;

}

$row=mysql_fetch_row($result);
//store session for the displayed application
echo '<strong>Post Applied for: </strong>'.$row[1].'<br/>';
echo '<strong>Applied by: </strong>'.$row[2].'<br/>';
echo '<strong>Requirement: </strong>'.$row[4].'<br/>';
echo '<strong>Location: </strong>'.$row[5].'<br/>';
echo '<strong>Interview Question: </strong>'.$row[6].'<br/>';
echo '<strong>Interview answer: </strong>'.$row[7].'<br/>';
echo '<strong>Area of Specification: </strong>'.$row[8].'<br/>';
echo '<strong>Closing Date: </strong>'.$row[10].'<br/>';
echo "<strong>Jobseeker's CV: </strong>".'<br/>'.$row[9].'<br/>';

$paf=$row[1] ;
$_SESSION['paf']=$paf;
echo $paf;
$pab=$row[2] ;
$_SESSION['pab']=$pab;
$pem=$row[3] ;
$_SESSION['pem']=$pem;
$preq=$row[4] ;
$_SESSION['preq']=$preq;
$ploc=$row[5] ;
$_SESSION['ploc']=$ploc;
$piq=$row[6] ;
$_SESSION['piq']=$piq;
$pia=$row[7] ;
$_SESSION['pia']=$pia;
$paos =$row[8] ;
$_SESSION['paos']=$paos;
$pcv =$row[9] ;
$_SESSION['pcv']=$pcv;
$pcd =$row[10] ;
$_SESSION['pcd']=$pcd;
$padt =$row[10] ;
$_SESSION['padt']=$padt;

echo '<form name="form1" method="post" action="appaccept.php">
<input type="submit" name="Submit" value="Accept">
<input name="Reject" type="submit" id="Reject" value="Reject">
</form>';
echo '<a href="#">'.'<img src="accept.png" width="130" height="50" />'.'</a>'.'<a href="#">'.'<img src="reject.png" width="130" height="50" />'.'</a> ';
echo '<hr>';
//----------------------------
mysql_close($con);
?>
 
Last edited:

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
appaccept.php
<?php session_start(); if(!isset($_SESSION['myusername'])) header("location:http://localhost/irs/login/loginphase.htm");?>
<?php
if(isset($_POST['Submit']))
{


$host="localhost";
$hostusername="root";
$hostpassword="root";
$db_name="jobdatabase";
$tbl_name="appconfirmation";
$con= mysql_connect("localhost","root","root");

mysql_connect("$host","$hostusername","$hostpassword") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");

$thisdate=date('Y-m-d');

$_POST=$_SESSION;

$thepaf=$_SESSION['paf']; echo $thepaf;
$thepab=$_SESSION['pab'];
$thepem=$_SESSION['pem'];
$thepreq=$_SESSION['preq'];
$theploc=$_SESSION['ploc'];
$thepiq=$_SESSION['piq'];
$thepia=$_SESSION['pia'];
$thepaos=$_SESSION['paos'];
$thepcv=$_SESSION['pcv'];
$thepcd=$_SESSION['pcd'];
$thepadt=$_SESSION['padt'];
//start off querying
$insertSQL= "INSERT INTO appconfirmation (postapplied,jobseeker,employer,requirement,location,interquest,interans,aofspeci,jobseekercv,status,appdatecon)
VALUES('$thepaf','$thepab','$thepem','$thepreq','$theploc','$thepiq','$thepia','$thepaos','$thepcv','accept','$thisdate')";


if (!mysql_query($insertSQL,$con))
{
die('Error: ' . mysql_error());
}
echo '<strong><font color="#FF0000">'."Application approved!!!"." ".':'.'</font></strong> ';
echo "<br />";
echo '<br>To view stuff, <a href="#">click here</a>.';
//end here
mysql_close($con);
}
//another one
?>
[/COLOR]in the second page i posted,the session data from the 1st page which I intended to insert into a new table was echoed empty.PLSSSSS HELP!!!!
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.

[url=http://sscce.org/]Sample code[/url] should be complete and concise. As essellar said, post the [I]relevant[/I] portions of your code rather than [URL="http://catb.org/~esr/faqs/smart-questions.html#code"]dumping all of it[/URL]. If it doesn't fit in a single post, it's definitely too much.

The sample code is vulnerable to [url=http://unixwiz.net/techtips/sql-injection.html]SQL injection[/url], which is a very serious [url=http://bobby-tables.com/]security risk[/url]. To fix this hole, switch from the outdated [URL="http://x10hosting.com/forums/programming-help/162529-php-begin-deprecation-ext-mysql-start-moving-your-development-pdo-now.html"]mysql extension[/URL] to [URL=http://php.net/PDO]PDO[/URL] and use [URL=http://www.php.net/PDO.prepared-statements]prepared statements[/URL]. If you need a PDO tutorial, try "[URL=http://www.kitebird.com/articles/php-pdo.html]Writing MySQL Scripts with PHP and PDO[/URL]". The site you save may just be your own.

Database connection creation (including managing the database credentials) should be the responsibility of one class rather than handled separately in each script. The more scripts contain user credentials, the more files there are for you to secure and the greater chance of typos screwing things up. Reduce critical code repetition. See "[URL="http://x10hosting.com/forums/tutorials/12014-php-mysql-php-4.html#post613750"][PHP] MySQL and PHP[/URL]" and "[URL="http://x10hosting.com/forums/programming-help/117523-display-all-would-secret-while-mysql-broken.html#post665590"]Display all that would be secret while Mysql is broken[/URL]" for some partial examples.

[URL="http://stackoverflow.com/questions/321299/what-is-the-reason-not-to-use-select"]Don't use [FONT="Courier New"]SELECT *[/FONT][/URL]; select only the columns you need.

Outputting database error messages to non-admin users [URL=http://msdn.microsoft.com/en-us/library/ms995351.aspx#securityerrormessages_topic2]discloses too much information[/URL]. Instead, log the MySQL error message. For some errors (such as those related to missing or invalid values), output your own [url=http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AppleHIGuidelines/Windows/Windows.html#//apple_ref/doc/uid/20000961-TP10]error message[/url] to the user and what action the user can take to address it. For the rest, inform the user that there was an internal error.

[URL="http://www.phpfreaks.com/blog/or-die-must-die"]Don't use [c]die[/c][/URL] when outputting HTML. You'll get invalid HTML.

Don't use <font>, [URL="http://brainstormsandraves.com/articles/semantics/structure/#br"]<br/>[/URL] or other non-[URL="http://webstyleguide.com/wsg3/5-site-structure/2-semantic-markup.html"]semantic[/URL] elements, or use semantic elements purely for presentation (e.g. [c]<p>&nbsp;</p>[/c] and [url=http://davespicks.com/writing/essays/notables.html]tables for layout[/url]). Use CSS.
 
Last edited:

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
the first php page coding:::::::::::::::::::::::::::::
-------------------------------------------------

<?php
//store the data in session
$appdate=date('Y-m-d');
$host="localhost"; // Host name
$hostusername="root"; // Mysql username
$hostpassword="root"; // Mysql password
$db_name="jobdatabase"; // Database name
$tbl_name="appsent"; // Table name
$varholder=$_SESSION['myusername'];
$con= mysql_connect("localhost","root","root");
mysql_connect("$host", "$hostusername", "$hostpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result=mysql_query("SELECT * FROM appsent WHERE employer='$_SESSION[myusername]' ");
if (!$result) {

echo 'Could not run query: '. mysql_error();
exit;

}

$row=mysql_fetch_row($result);
//store session for the displayed application
echo '<strong>Post Applied for: </strong>'.$row[1].'<br/>';
echo '<strong>Applied by: </strong>'.$row[2].'<br/>';
echo '<strong>Requirement: </strong>'.$row[4].'<br/>';
echo '<strong>Location: </strong>'.$row[5].'<br/>';
echo '<strong>Interview Question: </strong>'.$row[6].'<br/>';
echo '<strong>Interview answer: </strong>'.$row[7].'<br/>';
echo '<strong>Area of Specification: </strong>'.$row[8].'<br/>';
echo '<strong>Closing Date: </strong>'.$row[10].'<br/>';
echo "<strong>Jobseeker's CV: </strong>".'<br/>'.$row[9].'<br/>';

$paf=$row[1] ;
$_SESSION['paf']=$paf;
echo $paf;
$pab=$row[2] ;
$_SESSION['pab']=$pab;
$pem=$row[3] ;
$_SESSION['pem']=$pem;
$preq=$row[4] ;
$_SESSION['preq']=$preq;
$ploc=$row[5] ;
$_SESSION['ploc']=$ploc;
$piq=$row[6] ;
$_SESSION['piq']=$piq;
$pia=$row[7] ;
$_SESSION['pia']=$pia;
$paos =$row[8] ;
$_SESSION['paos']=$paos;
$pcv =$row[9] ;
$_SESSION['pcv']=$pcv;
$pcd =$row[10] ;
$_SESSION['pcd']=$pcd;
$padt =$row[10] ;
$_SESSION['padt']=$padt;



echo '<form name="form1" method="post" action="appaccept.php">
<input type="submit" name="Submit" value="Accept">
<input name="Reject" type="submit" id="Reject" value="Reject">
</form>';
echo '<a href="#">'.'<img src="accept.png" width="130" height="50" />'.'</a>'.'<a href="#">'.'<img src="reject.png" width="130" height="50" />'.'</a> ';
echo '<hr>';
//----------------------------
mysql_close($con);
?>

---------- Post added at 11:57 PM ---------- Previous post was at 11:55 PM ----------

the second php page where i was trying to call the session data:::::::::::::::::::::::::::::
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------

<?php
if(isset($_POST['Submit']))
{


$host="localhost";
$hostusername="root";
$hostpassword="root";
$db_name="jobdatabase";
$tbl_name="appconfirmation";
$con= mysql_connect("localhost","root","root");

mysql_connect("$host","$hostusername","$hostpasswo rd") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");

$thisdate=date('Y-m-d');

$_POST=$_SESSION;

$thepaf=$_SESSION['paf']; echo $thepaf;
$thepab=$_SESSION['pab'];
$thepem=$_SESSION['pem'];
$thepreq=$_SESSION['preq'];
$theploc=$_SESSION['ploc'];
$thepiq=$_SESSION['piq'];
$thepia=$_SESSION['pia'];
$thepaos=$_SESSION['paos'];
$thepcv=$_SESSION['pcv'];
$thepcd=$_SESSION['pcd'];
$thepadt=$_SESSION['padt'];
//start off querying
$insertSQL= "INSERT INTO appconfirmation (postapplied,jobseeker,employer,requirement,locati on,interquest,interans,aofspeci,jobseekercv,status ,appdatecon)
VALUES('$thepaf','$thepab','$thepem','$thepreq','$ theploc','$thepiq','$thepia','$thepaos','$thepcv', 'accept','$thisdate')";


if (!mysql_query($insertSQL,$con))
{
die('Error: ' . mysql_error());
}
echo '<strong><font color="#FF0000">'."Application approved!!!"." ".':'.'</font></strong> ';
echo "<br />";
echo '<br>To view stuff, <a href="#">click here</a>.';
//end here
mysql_close($con);
}
//another one
?>

---------- Post added 09-27-2011 at 12:01 AM ---------- Previous post was 09-26-2011 at 11:57 PM ----------

anyone to help me out................?????
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
There is far too much noise in this thread; it's almost unreadable. Go back and edit your posts as much as possible to remove the extraneous code. If that's not possible, it's better to abandon this thread and start from scratch, after following the advice from my previous post.
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
This is the relevant code:

PHP:
<?php session_start(); if(!isset($_SESSION['myusername'])) header("location:http://localhost/irs/login/loginphase.htm");?>

// html stuff and code not involved

<?php
	//store the data in session
	$appdate=date('Y-m-d');
	$host="localhost"; // Host name
	$hostusername="root"; // Mysql username
	$hostpassword="root"; // Mysql password
	$db_name="jobdatabase"; // Database name
	$tbl_name="appsent"; // Table name
	$varholder=$_SESSION['myusername'];
	$con= mysql_connect("localhost","root","root");
	mysql_connect("$host", "$hostusername", "$hostpassword")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");
	$result=mysql_query("SELECT * FROM appsent WHERE employer='$_SESSION[myusername]' ");
	if (!$result) {
		echo 'Could not run query: '. mysql_error();
		exit;
		}

	$row=mysql_fetch_row($result);
	//store session for the displayed application
	echo '<strong>Post Applied for: </strong>'.$row[1].'<br/>';
	echo '<strong>Applied by: </strong>'.$row[2].'<br/>';
	echo '<strong>Requirement: </strong>'.$row[4].'<br/>';
	echo '<strong>Location: </strong>'.$row[5].'<br/>';
	echo '<strong>Interview Question: </strong>'.$row[6].'<br/>';
	echo '<strong>Interview answer: </strong>'.$row[7].'<br/>';
	echo '<strong>Area of Specification: </strong>'.$row[8].'<br/>';
	echo '<strong>Closing Date: </strong>'.$row[10].'<br/>';
	echo "<strong>Jobseeker's CV: </strong>".'<br/>'.$row[9].'<br/>';

	$paf=$row[1] ;
	$_SESSION['paf']=$paf;
	echo $paf;
	$pab=$row[2] ;
	$_SESSION['pab']=$pab;
	$pem=$row[3] ;
	$_SESSION['pem']=$pem;
	$preq=$row[4] ;
	$_SESSION['preq']=$preq;
	$ploc=$row[5] ;
	$_SESSION['ploc']=$ploc;
	$piq=$row[6] ;
	$_SESSION['piq']=$piq;
	$pia=$row[7] ;
	$_SESSION['pia']=$pia;
	$paos =$row[8] ;
	$_SESSION['paos']=$paos;
	$pcv =$row[9] ;
	$_SESSION['pcv']=$pcv;
	$pcd =$row[10] ;
	$_SESSION['pcd']=$pcd;
	$padt =$row[10] ;
	$_SESSION['padt']=$padt;

	//irrelevant code removed
	mysql_close($con);
?>
//html removed

As you can see, half of the code is missing -- the half where you try to retrieve the data. Just in order to make the code you do have make more sense, assign the results to the variables first, then echo the variables (instead of using the row twice).

You can also run a foreach on $_SESSION to echo the keys and values as a quick test to make sure that the session contains what you think it does.

Just as an aside, you'll want to change the code to avoid using the mysql_xxx functions -- they are being deprecated, so they're going to start throwing warnings soon and will be removed from the language altogether at some point. Use PDO or mysqli_xxx instead.
 

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
please could you pls correct with codes?

---------- Post added at 12:21 AM ---------- Previous post was at 12:19 AM ----------

Even after printing or echoing the data in the first php page,it sounded right.but it is not shown in the second php page when i tried to recall the saved session data

<?php
if(isset($_POST['Submit']))
{


$host="localhost";
$hostusername="root";
$hostpassword="root";
$db_name="jobdatabase";
$tbl_name="appconfirmation";
$con= mysql_connect("localhost","root","root");

mysql_connect("$host","$hostusername","$hostpasswo rd") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");

$thisdate=date('Y-m-d');

$_POST=$_SESSION;

$thepaf=$_SESSION['paf']; echo $thepaf;
$thepab=$_SESSION['pab'];
$thepem=$_SESSION['pem'];
$thepreq=$_SESSION['preq'];
$theploc=$_SESSION['ploc'];
$thepiq=$_SESSION['piq'];
$thepia=$_SESSION['pia'];
$thepaos=$_SESSION['paos'];
$thepcv=$_SESSION['pcv'];
$thepcd=$_SESSION['pcd'];
$thepadt=$_SESSION['padt'];
//start off querying
$insertSQL= "INSERT INTO appconfirmation (postapplied,jobseeker,employer,requirement,locati on,interquest,interans,aofspeci,jobseekercv,status ,appdatecon)
VALUES('$thepaf','$thepab','$thepem','$thepreq','$ theploc','$thepiq','$thepia','$thepaos','$thepcv', 'accept','$thisdate')";


if (!mysql_query($insertSQL,$con))
{
die('Error: ' . mysql_error());
}
echo '<strong><font color="#FF0000">'."Application approved!!!"." ".':'.'</font></strong> ';
echo "<br />";
echo '<br>To view stuff, <a href="#">click here</a>.';
//end here
mysql_close($con);
}
//another one
?>
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You're becoming a help vampire. Read the previous posts until you understand them, then follow their advice before posting again.
 
Last edited:

pe_es171

New Member
Messages
23
Reaction score
0
Points
0
i have edited those codes and made only php codes alone....

---------- Post added at 11:37 AM ---------- Previous post was at 12:43 AM ----------

Problem Solved!!!I have corrected the issue....
 

ajaydhar

New Member
Messages
8
Reaction score
0
Points
1
PDO by Misson seems very good. It seems very useful to me also. Thanks a lot.
 
Top