I am trying to auto fill certain fields on a page based on the user that is logged in. I have the SESSION set but have a couple places that look at the SESSION in the page to display a form and welcome message. I want to have the $name and $lname that is in the database display in the form labeled Reviews. I cut some of the insignificant code to make it fit in this post. I have tried multiple things to make this work. If someone could look it over I would greatly appreciate it. I am very new to PHP so please explain in detail.
PHP Code:
<?php
session_start();
$_SESSION['name'] = "$name";
?>
<head>
<link href="stylesheets/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/charLeft.js"></script>
<!-- #EndEditable -->
<!--$begin pageHtmlBefore$-->
<link rel="shortcut icon" href="images/favicon.ico"/><!--$end pageHtmlBefore$-->
</head>
<!-- #BeginEditable "body" -->
<body id="starter">
<!-- DO NOT MOVE! The following AllWebMenus linking code section must always be placed right AFTER the BODY tag-->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR menu ******** -->
<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menu",awmBN="828";awmAltUrl="";</script><script charset="UTF-8" src="scripts/menu.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR menu ******** -->
<!-- #EndEditable -->
<div id="main-wrap"><div id="awmAnchor-menu"></div><div id="header">
<img alt="" height="229" src="images/layout/ame-layout-header-starter.jpg" width="990" />
</div>
<div id="clear2">
</div>
<div id="right-column">
<div id="right-header"><div class="right-content-head">
<div id="login">
<?php
if ($_SESSION['myusername']){
echo "Welcome, ".$_SESSION['myusername']." <a href='http://remotelystartedmn.com/logout.php'>Logout</a><br>";
}
else
{
echo "<h1 class='center'>";
echo "Please Login";
echo "</h1>";
echo "<form name=\"form1\" method=\"post\" action=\"http://remotelystartedmn.com/checklogin.php\">";
echo "<table>";
echo "<tr><td>";
echo "Username:";
echo "</td><td>";
echo "<input name=\"myusername\" type=\"text\" id=\"myusername\"/>";
echo "</td></tr>";
echo "<tr><td>";
echo "Password:";
echo "</td><td>";
echo "<input name=\"mypassword\" type=\"password\" id=\"mypassword\"/>";
echo "</td></tr>";
echo "<tr><td>";
echo "";
echo "</td><td>";
echo "<input name=\"Submit1\" type=\"image\" src=\"http://remotelystartedmn.com/images/submit-btn.png\" value=\"submit\"/>";
echo "</td></tr>";
echo "</table>";
echo "</form>";
echo "Not a member yet! <a href='http://remotelystartedmn.com/register.php'>Register</a>";
}
?>
</div><!-- #BeginEditable "right-column-head" -->
<h1>In most case<a name="iDatalink"></a>s extra parts are needed.</h1>
<p>With the advances in today's vehicles many times additional parts
are needed to install a remote starter or alarm. This may
sound like a problem but with the modules I use it has never been
easier and safer for your vehicle. I use the iDatalink brand
bypass modules to insure a clean, safe install.</p>
<p class="center">
<img alt="iDatalink Multi Series Module" height="134" src="images/idata-module.png" width="180" id="img2" /></p>
<h1>Benefits of iDatalink Modules:<br/></h1><ul id="idata"><li>Vehicle specific firmware</li>
<li>Updateable Online</li>
<li>No giving up a key for the installation</li>
<li>Safe DATA communication to vehicle</li>
<li>Less wire tapping into vehicle</li>
<li>Faster / Cleaner installations</li></ul>
<h1>To get a FREE quote
<a href="index.html#Quote">click>></a> to go back to our info form.</h1>
<!-- #EndEditable --></div></div>
<div class="right-content"><!-- #BeginEditable "right-column-content" -->
<!-- #EndEditable --><br /><h1>Connect with me!</h1>
<p>
<a href="http://www.facebook.com/?ref=home#!/pages/Remotely-Started-MN/125935220750872?ref=ts" target="_blank">
<img alt="" height="28" src="images/facebook-icon.png" width="25" /></a>
<a href="http://maps.google.com/maps/place?hl=en&georestrict=input_srcid%3Ab23969e1ae99ea26" target="_blank">
<img alt="" height="23" src="images/google-icon.png" width="24" /></a>
<a href="http://www.linkedin.com/companies/961137" target="_blank">
<img alt="" height="25" src="images/linkedin-icon.png" width="25" /></a>
<a href="http://local.yahoo.com/info-64520724-remotely-started-mn-burnsville;_ylt=Apo8dQFF3MX5xprXVa04p.qHNcIF;_ylv=3?csz=Burnsville%2C+MN+55337" target="_blank">
<img alt="" height="23" src="images/yahoo-icon.png" width="40" /></a>
<a href="http://www.yelp.com/biz/remotely-started-mn-burnsville" target="_blank">
<img alt="" height="24" src="images/yelp-icon.png" width="19" /></a></p>
</div>
</div>
<div id="left-column"><!-- #BeginEditable "left column" -->
<?php
mysql_connect("rsmnproducts.db.5881165.hostedresource.com", "rsmnproducts", "*******") or die(mysql_error());
mysql_select_db("rsmnproducts") or die(mysql_error());
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM reviews ORDER BY date DESC")
or die(mysql_error());
// keeps getting the next row until there are no more to get
// Print out the contents of each row into a table
echo '<div>';
while($row = mysql_fetch_array( $result )) {
echo '<h1 class=\'neg-marg3\'>';
echo $row['name'], ' ', $row['lname'], ' ', '<span class=\'norm-text\'>','Star Rating:', ' ', '</span>',$row['starrate'];
echo '</h1>', '<span class=\'norm-text\'>';
echo $row['date'];
echo '</span>', '<p class=\'norm-text neg-marg4\'>';
echo '"', $row['comments'], '"';
echo '</p>';
}
echo "</div>";
?>
<div id="leave-comment">
<?php
if ($_SESSION['myusername']){
echo "<form name=\"reviews\" action=\"database.php\" method=\"post\">";
echo "<table cellpadding=\"0\" cellspacing=\"6\" style=\"width: 100%; background-color:#1d1d1d\">";
echo "<tr><th colspan=\"2\">Leave Me A Review</th></tr>";
echo "<tr><td style=\"width: 50%\">First Name: *</td>";
echo "<td>Last Name: *</td></tr>";
echo "<tr><td>";
echo "<input name=\"name\" type=\"text\" value=\"$name\" style=\"width: 200px\" /></td>";
echo "<td><input name=\"lname\" type=\"text\" value=\"$lname\" style=\"width: 200px\" /></td></tr>";
echo "<tr><td colspan=\"2\">";
echo "Review: (700 characters max)*</td>";
echo "</tr><tr>";
echo "<td colspan=\"2\"><textarea name=\"comments\" onblur=\"InputLengthCheck();\"onkeyup=\"InputLengthCheck();\" style=\"width: 531px; height: 100px\" rows=\"1\"></textarea>";
echo "</td></tr>";
echo "<tr><td colspan=\"2\">";
echo "<input readonly=\"readonly\" type=\"text\" name=\"CharsTyped\" size=\"8\"/> characters typed</td>";
echo "</tr><tr>";
echo "<td colspan=\"2\">Star Rating:* <select name=\"starrate\">";
echo "<option></option>";
echo "<option value=\"1\">1</option>";
echo "<option value=\"2\">2</option>";
echo "<option value=\"3\">3</option>";
echo "<option value=\"4\">4</option>";
echo "<option value=\"5\">5</option>";
echo "</select></td>";
echo "</tr><tr>";
echo "<td colspan=\"2\">";
require_once('recaptchalib.php');
$publickey = "6LfnjroSAAAAAKjSZDZnnvB58IZd--47O9I-1WBF "; // you got this from the signup page
echo recaptcha_get_html($publickey);
echo "</td></tr>";
echo "<tr><td colspan=\"2\">";
echo " <input name=\"Submit1\" type=\"image\" src=\"images/submit-btn.png\" value=\"submit\"/>";
echo " <input name=\"Reset1\" type=\"image\" src=\"images/reset-btn.png\" value=\"reset\" />";
echo " * All Fields Required</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
else
{
echo "<h1 class=\"center\">";
echo "Please login to leave me a positive review.<br>If you are not a member yet <a href=\"register.php\">Register</a>";
echo "</h1>";
}
?>
</div>
<!-- #EndEditable -->
</div><div id="clear"></div>
<div id="footer-img">
<img alt="" height="69" src="images/layout/ame-layout-footer-main2.jpg" width="990" /><div id="footer-content">
<ul id="footer-menu">
<li><a href="index.php">Home</a></li>
<li><a href="store/index.php">Online Store</a></li>
<li><a href="contact.php">Contact</a></li>
<li>(612) 840-1039 </li>
</ul>
</div>
</div>
</div>
<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=5719037;
var sc_invisible=1;
var sc_partition=60;
var sc_click_stat=1;
var sc_security="929a447a";
</script>
<script type="text/javascript"
src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div
class="statcounter"><a title="myspace profile views counter"
class="statcounter"
href="http://www.statcounter.com/myspace/"><img
class="statcounter"
src="http://c.statcounter.com/5719037/0/929a447a/1/"
alt="myspace profile views counter" /></a></div></noscript>
<!-- End of StatCounter Code -->
</body>
<!-- #EndTemplate -->
</html>
Bookmarks