Jump to content

Newbie help please


sws

Recommended Posts

Hi,

I've found some source code to build a user authentication system for my site. I made the necessary changes and implemented them and they are working great.

Basically the script checks to see if the user is logged on and if they are displays the index page saying welcome "user".. and then displays the rest of the index.php page.

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ultimate Poolies - Compete against the world's ULTIMATE SPORTS POOLIES</title>
</head>
<body background="images/bg.gif">

<?php
include ("config.php");
# Include the config.php file here

error_reporting (E_ALL & ~ E_NOTICE);
# Don't show notices.

if (!empty($online['id'])){
# Check to see if they're logged in

echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850">
  <tr>
    <td bgcolor="#FFFFFF"><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>
Welcome <b>'.stripslashes($online['username']).'</b>- <a href="logout.php">Logout</a><br /></td>
  </tr>
  <tr>
    <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF"><marquee behavior="slide" height="22" direction="left">Welcome to ULTIMATE POOLIES.com We are pleased to announce that our HOCKEY Contests are now in progress!!!</marquee></font></td>
  </tr>
  <tr><td>
    <table border="1" cellpadding="2" cellspacing="0">
      <tr>
        <td width="262" bgcolor="#EEEEEE" align="center" valign="top">
<table bgcolor="#FFFFCC">
<tr>
  <td><br />Contest Leaders to go here!</td>
</tr>
</table>  
</td>

<td width="530" bgcolor="#FFFFFF"><br />
<table>
<tr>
<td valign="top"><h3>
Welcome to Ultimate Poolies.com</h3> Home to the fastest growing fantasy sports contest site on the web.<br />
<ul>
  <li>Pay $1, $2 or $5 to play our Fantasy Sports Contests</li>
  <li>Test your Skill to Win the Progressive Prizes.</li>
  <li>Guaranteed Winners Every Day!!</li>
  <br />or<br />
  <li>Play for bragging rights. All the same contests but free. </li>
</ul>
</td>
</tr>
<tr>
  <td><h3>Fantasy Sports Contests!</h3></td>
</tr>
<tr>
  <td><a href="hockey_contests.php">Hockey Contests</a></td>
</tr>
</table>

</td>
<td width="232" bgcolor="#EEEEEE" align="center"><iframe src="http://www.sportznetwork.com/ticker/ticker.php" name="ticker" scrolling="no" frameborder="no"  height = "275px" width = "180px">
</iframe></td>
      </tr>
    </table>
</td>
  </tr>
</table>';
} [/code]

Else if not logged in then it displays the exact same thing but instead of saying welcome "user" it has links to login or register.

[code]else {
# Else, they are not logged in.
echo  '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850">
  <tr>
    <td bgcolor="#FFFFFF"><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>
<a href="login.php">Login | </a><a href="register.php">Register</a><br /></td>
  </tr>
  <tr>
    <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF"><marquee behavior="slide" height="22" direction="left">Welcome to ULTIMATE POOLIES.com We are pleased to announce that our HOCKEY Contests are now in progress!!!</marquee></font></td>
  </tr>
  <tr><td>
    <table border="1" cellpadding="2" cellspacing="0">
      <tr>
        <td width="262" bgcolor="#EEEEEE" align="center" valign="top">
<table bgcolor="#FFFFCC">
<tr>
  <td><br />Contest Leaders to go here!</td>
</tr>
</table>  
</td>

<td width="530" bgcolor="#FFFFFF"><br />
<table>
<tr>
<td valign="top"><h3>
Welcome to Ultimate Poolies.com</h3> Home to the fastest growing fantasy sports contest site on the web.<br />
<ul>
  <li>Pay $1, $2 or $5 to play our Fantasy Sports Contests</li>
  <li>Test your Skill to Win the Progressive Prizes.</li>
  <li>Guaranteed Winners Every Day!!</li>
  <br />or<br />
  <li>Play for bragging rights. All the same contests but free. </li>
</ul>
</td>
</tr>
<tr>
  <td><h3>Fantasy Sports Contests!</h3></td>
</tr>
<tr>
  <td><a href="hockey_contests.php">Hockey Contests</a></td>
</tr>
</table>

</td>
<td width="232" bgcolor="#EEEEEE" align="center"><iframe src="http://www.sportznetwork.com/ticker/ticker.php" name="ticker" scrolling="no" frameborder="no"  height = "275px" width = "180px">
</iframe></td>
      </tr>
    </table>
</td>
  </tr>
</table>';
}

?>

</body>
</html>
[/code]

This is all fine.

My question is:
Does this all have to be within the php tags ?  I mean does all the html (i.e. my tables) have to be within the php tags ?

I think it's a little redundant repeating this code twice. And also, I have some sections within the table where I'd like to query my database and display the results. I can't figure out how to do this with all the code within the php tags as they are now.

Does anybody have any input that could get me on the right track ?

Much appreciated !
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/
Share on other sites

from what i understand you only want to say if the user is loged in, to say their name?

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ultimate Poolies - Compete against the world's ULTIMATE SPORTS POOLIES</title>
</head>
<body background="images/bg.gif">

<?php
include ("config.php");
# Include the config.php file here

error_reporting (E_ALL & ~ E_NOTICE);
# Don't show notices.

echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850">
  <tr>
    <td bgcolor="#FFFFFF"><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>';
if(!empty($online['id']))
{
  print'Welcome <b>'.stripslashes($online['username']).'</b>- <a href="logout.php">Logout</a><br />';
}
else
{
  print'<a href="login.php">Login | </a><a href="register.php">Register</a><br />';
}

//you dont really need to keep this all in a php tag, can just break out of it, and let rest be all html.. not in an echo or print
?>
  </td>
  </tr>
  <tr>
    <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF"><marquee behavior="slide" height="22" direction="left">Welcome to ULTIMATE POOLIES.com We are pleased to announce that our HOCKEY Contests are now in progress!!!</marquee></font></td>
  </tr>
  <tr><td>
    <table border="1" cellpadding="2" cellspacing="0">
      <tr>
        <td width="262" bgcolor="#EEEEEE" align="center" valign="top">
<table bgcolor="#FFFFCC">
<tr>
  <td><br />Contest Leaders to go here!</td>
</tr>
</table> 
</td>

<td width="530" bgcolor="#FFFFFF"><br />
<table>
<tr>
<td valign="top"><h3>
Welcome to Ultimate Poolies.com</h3> Home to the fastest growing fantasy sports contest site on the web.<br />
<ul>
  <li>Pay $1, $2 or $5 to play our Fantasy Sports Contests</li>
  <li>Test your Skill to Win the Progressive Prizes.</li>
  <li>Guaranteed Winners Every Day!!</li>
  <br />or<br />
  <li>Play for bragging rights. All the same contests but free. </li>
</ul>
</td>
</tr>
<tr>
  <td><h3>Fantasy Sports Contests!</h3></td>
</tr>
<tr>
  <td><a href="hockey_contests.php">Hockey Contests</a></td>
</tr>
</table>

</td>
<td width="232" bgcolor="#EEEEEE" align="center"><iframe src="http://www.sportznetwork.com/ticker/ticker.php" name="ticker" scrolling="no" frameborder="no"  height = "275px" width = "180px">
</iframe></td>
      </tr>
    </table>
</td>
  </tr>
</table>[/code]
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121318
Share on other sites

Whether they are logged in or not, I want to show the main content on the index page. The difference is, if they are logged in it will say welcome [user_name] beside the logo at the top of the page. If they aren't logged in, it will have a link to login or to register instead of saying welcome [user_name]

You can view the page I'm talking about at http://www.ultimatepoolies.com/index.php

Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121321
Share on other sites

[quote author=sws link=topic=114208.msg464634#msg464634 date=1162945550]
Whether they are logged in or not, I want to show the main content on the index page. The difference is, if they are logged in it will say welcome [user_name] beside the logo at the top of the page. If they aren't logged in, it will have a link to login or to register instead of saying welcome [user_name]

You can view the page I'm talking about at http://www.ultimatepoolies.com/index.php


[/quote]
yes i know... look for this bit, in my reply..

[code]if(!empty($online['id']))
{
  print'Welcome <b>'.stripslashes($online['username']).'</b>- <a href="logout.php">Logout</a><br />';
}
else
{
  print'<a href="login.php">Login | </a><a href="register.php">Register</a><br />';
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121325
Share on other sites

[quote author=sws link=topic=114208.msg464641#msg464641 date=1162946626]
Ahhhh, perfect. Thank you so much for your help.

Now with the code that way I can use php further down within some <td's> to generate queries and display data from the database. Correct ?
[/quote]
I dont fully understand....
but if your doing your pages mainly in html.. just add the <?php ?> tags when you need them.. like when your doing your query... because i find myself when its mainly html, i dont want it all enclosed inside a huge print" "; or echo " ";
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121332
Share on other sites

Yeah that's exactly what I didn't like: having that entire page within the echo statement.

Now further down in my html I have several table cells where i want to display data from my database.

For this I'll just use the <?php tags to create the sql query and display the data in that cell. Correct ?
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121334
Share on other sites

humm.. depending on what you are getting from the query.. normaly i have code that looks some thing like this...

[code]
<table>

<?
$dogs_sql = "SELECT * FROM dogs WHERE gender = 'm'";
$dogs_query = mysql_query($dogs_sql);

while(mysql_fetch_array($dogs_query) = $table_rows)
{
  ?>
  <tr>
    <td>
        <?=$table_row[name_of_dog]?>
    </td>
    <td>
        <?=$table_row[picture_of_dog]?>
    </td>
   
  </tr>
  <?
}

?>

</table>
[/code]

that basicly lists all the male dogs you have in your database.... but remember you dont know how many dogs there is.. so this keeps on going untill all the dogs have been listed (a row each)..

1 big thing if your going to do it like this.... dont (if you call all your mysql stuff, $sql and $query) call the sql query realated to your while loop $sql and $query (this make bug if you have another $sql and $query, inside the while)
Link to comment
https://forums.phpfreaks.com/topic/26517-newbie-help-please/#findComment-121339
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.