Forum Moderators: coopster

Message Too Old, No Replies

Pass variable date thru a URL

         

scottdufour

8:48 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



I want the user to click on the link then have it go to another page and pull the data according to the content of the link. What am I doing wrong on the syntax? An old program that used the query string in javascript works just fine. How come my php will not store the variable data?

$result = mysql_query("SELECT * FROM student WHERE fname LIKE '$search'");
while($row = mysql_fetch_array($result))
{

$sspass = $row['ss'] ;

echo '<font face=century schoolbook><a href=/scholartracker/viewstudent.php?ss= echo $sspass;>' . $row['ss'] . '</a>' . " " . $row['fname'] . " " . $row['lname'] . '</font>' ;
echo "<br /><br />";

echo $sspass;
}
break;

Here is the javascript from the other program:

<a href="eventdetail.asp?playerid2=<%=rs1.Fields("PlayerID")%>&date1=<%=range1%>&date2=<%=range2%>&fname=<%=rs1.Fields("firstname")%>&lname=<%=rs1.Fields("lastname")%>

jguz

9:03 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



Instead of:

echo '<font face=century schoolbook><a href=/scholartracker/viewstudent.php?ss= echo $sspass;>' . $row['ss'] . '</a>' . " " . $row['fname'] . " " . $row['lname'] . '</font>' ;
echo "<br /><br />";

Go with:


echo "<font face=century schoolbook><a href=/scholartracker/viewstudent.php?ss=$sspass>" . $row['ss'] . '</a>' . " " . $row['fname'] . " " . $row['lname'] . '</font>' ;
echo "<br /><br />";

You're using an echo within the string you're trying to print. Then, I swapped your single-quote to double to allow you to use the php variable inline.

scottdufour

9:13 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



that's great..thanks...now how come the passed variable will not show on the next page or pull the sql data I want to show?

<?php
session_start();

if (!isset($_SESSION['user']))
{
header("Location: login.php");
}

$sspass1 = $_get[ss];

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("scholar", $con);
echo '<b><font face="Century Schoolbook" size=5>Results Found</font></b><br /><br />';

$result = mysql_query("SELECT * FROM student WHERE ss = '$sspass1'");
while($row = mysql_fetch_array($result))
{

echo $sspass1;


}
{
die('Error: ' . mysql_error());
}


mysql_close($con)


?>

punisa

9:25 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



May I join in?

Instead of:


$sspass1 = $_get[ss];

Use this:

$sspass1 = $_GET['ss'];

All ok now?

scottdufour

9:29 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



I got it figured out. It was an issue with the GET portion. Thanks again. I'm sure I'll have more on this issue.

scottdufour

9:33 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



Now how do I get the information per student/record to show in this table? I added this code after the php stuff in the second page but it shows blank.

<table border="0" width="75%" id="table1">
<tr>
<td width="332"><b>First Name:</b></td>
<td>
<?php echo $_POST[fname];?></td>
</tr>
<tr>
<td width="332"><b>Middle Name/Maiden Name:</b></td>
<td>
<?php echo $_POST[mname];?></td>
</tr>
<tr>
<td width="332"><b>Last Name:</b></td>
<td>
<?php echo $_POST[lname];?></td>
</tr>
<tr>
<td width="332"><b>Social Security #:</b></td>
<td>
<?php echo $_POST[ss];?></td>
</tr>
<tr>
<td width="332"><b>Address:</b></td>
<td>
<?php echo $_POST[address1];?></td>
</tr>
<tr>
<td width="332"><b>City:</b></td>
<td>
<?php echo $_POST[city1];?></td>
</tr>
<tr>
<td width="332"><b>State:</b></td>
<td>
<?php echo $_POST[state1];?></td>
</tr>
<tr>
<td width="332"><b>Zip Code:</b></td>
<td>
<?php echo $_POST[zip1];?></td>
</tr>
<tr>
<td width="332"><b>Home Phone:</b></td>
<td>
<?php echo $_POST[phone1];?></td>
</tr>
<tr>
<td width="332"><b>Cell Phone:</b></td>
<td>
<?php echo $_POST[phone2];?></td>
</tr>
<tr>
<td width="332"><b>Fax:</b></td>
<td>
<?php echo $_POST[fax];?></td>
</tr>
<tr>
<td width="332"><b>Email:</b></td>
<td>
<?php echo $_POST[email];?></td>
</tr>
<tr>
<td width="332"><b>School:</b></td>
<td>
<?php echo $_POST[school];?></td>
</tr>
<tr>
<td width="332"><b>School Address:</b></td>
<td>
<?php echo $_POST[schooladdress];?></td>
</tr>
<tr>
<td width="332"><b>City:</b></td>
<td>
<?php echo $_POST[city2];?></td>
</tr>
<tr>
<td width="332"><b>State:</b></td>
<td>
<?php echo $_POST[state2];?></td>
</tr>
<tr>
<td width="332"><b>Zip Code:</b></td>
<td>
<?php echo $_POST[zip2];?></td>
</tr>
<tr>
<td width="332"><b>Major:</b></td>
<td>
<?php echo $_POST[major];?></td>
</tr>
<tr>
<td width="332"><b>Minor:</b></td>
<td>
<?php echo $_POST[minor];?></td>
</tr>
<tr>
<td width="332"><b>Degrees Completed To Date:</b></td>
<td>
<?php echo $_POST[degree];?></td>
</tr>
<tr>
<td width="332"><b>Professional Certifications:</b></td>
<td>
<?php echo $_POST[cert];?></td>
</tr>
</table>

</body>

</html>

punisa

8:47 am on May 1, 2009 (gmt 0)

10+ Year Member



Scotty it's not working like that, I suggest you read on some great start-up tutorials for php/mysql on google. It might seem tricky at beginning, but soon you'll get hang of it:)

As for your current code:


mysql_select_db("scholar", $con);
echo '<b><font face="Century Schoolbook" size=5>Results Found</font></b><br /><br />';
$result = mysql_query("SELECT * FROM student WHERE ss = '$sspass1'");
while($row = mysql_fetch_array($result))
{
// OUTPUT STUFF GOES HERE !
echo $sspass1;
}
{
die('Error: ' . mysql_error());
}

So to echo your data you would set it like this:


mysql_select_db("scholar", $con);
echo '<b><font face="Century Schoolbook" size=5>Results Found</font></b><br /><br />';
$result = mysql_query("SELECT * FROM student WHERE ss = '$sspass1'");
while($row = mysql_fetch_array($result))
{
echo '
<table border="0" width="75%" id="table1">
<tr>
<td width="332"><b>First Name:</b></td>
<td>
'.$row['fname'].'</td>
</tr>
<tr>
<td width="332"><b>Middle Name/Maiden Name:</b></td>
<td>
'.$row['mname'].'</td>
</tr>
<tr>
<td width="332"><b>Last Name:</b></td>
<td>
'.$row['lname'].'</td>
</tr>
<tr>
<td width="332"><b>Social Security #:</b></td>
<td>
'.$row['ss'].'</td>
</tr>
<tr>
<td width="332"><b>Address:</b></td>
<td>
'.$row['address1'].'</td>
</tr>
<tr>
<td width="332"><b>City:</b></td>
<td>
'.$row['city1'].'</td>
</tr>
<tr>
<td width="332"><b>State:</b></td>
<td>
'.$row['state1'].'</td>
</tr>
<tr>
<td width="332"><b>Zip Code:</b></td>
<td>
'.$row['zip1'].'</td>
</tr>
<tr>
<td width="332"><b>Home Phone:</b></td>
<td>
'.$row['phone1'].'</td>
</tr>
<tr>
<td width="332"><b>Cell Phone:</b></td>
<td>
'.$row['phone2'].'</td>
</tr>
<tr>
<td width="332"><b>Fax:</b></td>
<td>
'.$row['fax'].'</td>
</tr>
<tr>
<td width="332"><b>Email:</b></td>
<td>
'.$row['email'].'</td>
</tr>
<tr>
<td width="332"><b>School:</b></td>
<td>
'.$row['school'].'</td>
</tr>
<tr>
<td width="332"><b>School Address:</b></td>
<td>
'.$row['schooladdress'].'</td>
</tr>
<tr>
<td width="332"><b>City:</b></td>
<td>
'.$row['city2'].'</td>
</tr>
<tr>
<td width="332"><b>State:</b></td>
<td>
'.$row['state2'].'</td>
</tr>
<tr>
<td width="332"><b>Zip Code:</b></td>
<td>
'.$row['zip2'].'</td>
</tr>
<tr>
<td width="332"><b>Major:</b></td>
<td>
'.$row['major'].'</td>
</tr>
<tr>
<td width="332"><b>Minor:</b></td>
<td>
'.$row['minor'].'</td>
</tr>
<tr>
<td width="332"><b>Degrees Completed To Date:</b></td>
<td>
'.$row['degree'].'</td>
</tr>
<tr>
<td width="332"><b>Professional Certifications:</b></td>
<td>
'.$row['cert'].'</td>
</tr>
</table>';
echo $sspass1;
}
{
die('Error: ' . mysql_error());
}

- notice that we put all your output data into a single echo statement, much easier to read it like that
- $_POST command is a method for sending information from a HTML form (or using advanced ajax), not for displaying from mysql database.
For this we use "$row" - because you already declared it in this part "while($row = mysql_fetch_array($result))"
- I'm not sure if its needed, but I added small quotation marks around your output name: $row[major] to $row['major'], I *think* it also works without them, but this is just a way that majority will put it like.

scottdufour

2:36 pm on May 1, 2009 (gmt 0)

10+ Year Member



I figured it out right after I posted asking for help..lol...I did exactly what you did here.

I've been reading my arse off on all this.

My next question has to do with my session data not seeming to work anymore for my checking to see if the user is logged in and going to other pages. What is wrong you think? If I logged in then it used to let me go to anypage I want as long as I had the session code on each page. Please help.

login page:
<?php
include 'dbc.php';

$user_email = mysql_real_escape_string($_POST['email']);

if ($_POST['Submit']=='Login')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT id,user_email FROM users WHERE
user_email = '$user_email' AND
user_pwd = '$md5pass' AND user_activated='1'";

$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);

if ( $num != 0 ) {

// A matching row was found - the user is authenticated.
session_start();
list($user_id,$user_email) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION['user']= $user_email;

if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
} else
{
header("Location: home.php");
}
//echo "Logged in...";
exit();
}

header("Location: login.php?msg=Invalid Login");
//echo "Error:";
exit();
}

?>

<html>
<head><style type="text/css">
body{
text-align:center;
}


/*CSS to main Container TABLE or DIV or any PlaceHolder TAG of the web page*/
#container{
width:800px;
margin-left:auto;
margin-right:auto;
text-align:left;
}
</style>
</head>
<div id="container">
<link href="styles.css" rel="stylesheet" type="text/css">

<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><font size=6 face="Century Schoolbook">

<center></center><img border="0" src="school_books_sml.jpg" width="65" height="67"></a>ScholarTracker</font><font size=1 face="Century Schoolbook">v1.1</font><font size=1 face="Times New Roman">®</font><font face="Arial Rounded MT Bold">
</font><font size="7" face="Palatino Linotype">&nbsp;</font><font face="Rage Italic" size="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<font face="Century" size="5">&nbsp;<i>Tunica-Biloxi Education Center</i></font><font face="Tahoma" size="5"></center>
</font></tr><tr><p><p><p><tr></table><hr size=3 color=black>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center">
<table width="50%" border="3" bordercolor="black" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#000000" class="mnuheader" >
<div align="center"><font size="5" color=white face="Century Schoolbook"><strong>LOGIN PORTAL</strong></font></div></td>
</tr>
<tr>
<td class="mnubody" bordercolor="#000000" height="220" background="education_2.jpg"><form name="form1" method="post" action="">
<p align="center">&nbsp;</p>
<p align="center"><strong>
<font color="#FF0000" size="5" face="Century Schoolbook">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><font size="5" face="Century Schoolbook" color="#FFFFFF">Email:</font><font size="3" color=black face="Century Schoolbook">&nbsp; </font>
<input name="email" type="text" id="email" style="border-style: solid; border-width: 1px" size="20"></strong></p>
<p align="center"><strong>
<font size="5" face="Century Schoolbook" color="#FFFFFF">Password:</font>
<input name="pwd" type="password" id="pwd" size="20" style="border-style: solid; border-width: 1px">
</p>
<p align="center">
&nbsp;<input type="submit" name="Submit" value="Login" style="border-style: solid; border-width: 1px">
</p>
<p align="center"><a href="forgot.php">Forgot</a></p>
</form></strong></td>
</tr>

</table>
</div>
<p align="center"><p align="center"><b><font face="Times New Roman">©2009--Scott Dufour</font></b></p></div>

</html>

home page (which I can get to once logged in):
<?php

session_start();
if (!isset($_SESSION['user']))
{
header("Location: login.php");
}

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

?>

<html>
<head>

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ScholarTracker</title>
<style type="text/css">
body{
text-align:center;
}


/*CSS to main Container TABLE or DIV or any PlaceHolder TAG of the web page*/
#container{
width:800px;
margin-left:auto;
margin-right:auto;
text-align:left;
}
</style>

<script type="text/javascript" src="dropdowntabfiles/dropdowntabs.js">

</script>

<!-- CSS for Drop Down Tabs Menu #1 -->
<link rel="stylesheet" type="text/css" href="dropdowntabfiles/halfmoontabs.css" />

<script type="text/javascript">
function sizeIFrame(frameId){
try{
frame = document.getElementById(frameId);
innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
objToResize = (frame.style) ? frame.style : frame;
objToResize.height = innerDoc.body.scrollHeight + 10;
}
catch(err){
alert(err.message);
}
}
</script>

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

<META HTTP-EQUIV="Expires" CONTENT="-1">

</head>
<body>

<div id="container">

<div style="border-bottom-style: solid">
<font size=6 face="Century Schoolbook">
<a href="/scholartracker/home.php">
<img border="0" src="school_books_sml.jpg" width="65" height="67"></a>ScholarTracker</font><font size=1 face="Century Schoolbook">v1.1</font><font size=1 face="Times New Roman">®</font><font face="Arial Rounded MT Bold">
</font><font size="7" face="Palatino Linotype">&nbsp;</font><font face="Rage Italic" size="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<font face="Century" size="5">&nbsp;<i>Tunica-Biloxi Education Center</i></font><font face="Tahoma" size="5">
</font>

<div id="moonmenu" class="halfmoon">
<ul>
<li><a rel="dropmenu1_e">Students</a></li>
<li><a href="http://www.dynamicdrive.com/style/" rel="dropmenu1_e">Financial Aid</a></li>

<li><a href="http://www.google.com/">Google</a></li>
</ul>
</div>

&nbsp;<div id="dropmenu1_e" class="dropmenudiv_e">
<a href="/scholartracker/newstudent.php" target=I1>Add a Student</a>
<a href="http://www.dynamicdrive.com/style/csslibrary/category/C2/">Update a Student</a>
<a href="/scholartracker/studentsearch.php" target=I1>Search for a Student</a>

</div>

<!--2nd drop down menu -->
<div id="dropmenu2_e" class="dropmenudiv_e" style="width: 150px;">
<a href="http://www.cssdrive.com">CSS Drive</a>
<a href="http://www.javascriptkit.com">JavaScript Kit</a>
<a href="http://www.codingforums.com">Coding Forums</a>
<a href="http://www.javascriptkit.com/jsref/">JavaScript Reference</a>
</div>

<script type="text/javascript">
//SYNTAX: tabdropdown.init("menu_id", [integer OR "auto"])
tabdropdown.init("moonmenu")
</script>

<iframe name="I1" src="globe.htm" width=100% frameborder=0 border=0 onload="if (window.parent && window.parent.sizeIFrame) {window.parent.sizeIFrame('I1');}" scrolling=no>
>
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>

</div>
</div>

</body>

</html>
<?php if (isset($_SESSION['user'])) { ?>
<p><b>User:</b>&nbsp<?php echo $_SESSION['user']; ?> ¦
<a href="logout.php">Logout</a> </p>
<?php } ?>

Student search page which I can't get to anymore (it keeps redirecting to the login page):
<?php

session_start();
if (!isset($_SESSION['user']))
{
header("Location: login.php");
}

?>

<html>

<head>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 04 Dec 1993 21:29:02 GMT">

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Add a New Student</title>
</head>

<body>

<p><b><font face="Century Schoolbook" size="5">Search for a Student</font></b></p>
<hr>

<form action=search.php>
<table border="0" width="100%" id="table1">
<tr>
<td width="64"><b><font face="Century Schoolbook">Search:</font></b></td>
<td>
<input type="text" name="search1" size="52" style="border-style: solid; border-width: 1px"></td>
</tr>
</table>

<table border="0" width="75%" id="table2">
<tr>
<td width="97"><font face="Century Schoolbook" size="2">First Name
<input type="radio" value="fname" name="option"></font></td>
<td width="92"><font face="Century Schoolbook" size="2">Last Name
<input type="radio" name="option" value="lname"></font></td>
<td width="46"><font face="Century Schoolbook" size="2">SS#<input type="radio" name="option" value="ss"></font></td>
<td width="45"><font face="Century Schoolbook" size="2">City<input type="radio" name="option" value="city"></font></td>
<td width="54"><font face="Century Schoolbook" size="2">State<input type="radio" name="option" value="state"></font></td>
<td width="39"><font face="Century Schoolbook" size="2">Zip<input type="radio" name="option" value="zip"></font></td>
<td width="58"><font face="Century Schoolbook" size="2">School<input type="radio" name="option" value="school"></font></td>
<td width="55"><font face="Century Schoolbook" size="2">Major<input type="radio" name="option" value="major"></font></td>
<td width="56"><font face="Century Schoolbook" size="2">Minor<input type="radio" name="option" value="minor"></font></td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<table border="0" width="10%" id="table3">
<tr>
<td>
<input type="submit" value="Search" name="button1" style="border-style: solid; border-width: 1px"></td>
<td>
<input type="submit" value="Refresh" name="button1" style="border-style: solid; border-width: 1px"></td>

</tr>
</table>

</form>
</body>

</html>