Jump to content


Photo

Linked Pages?!


  • Please log in to reply
19 replies to this topic

#1 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 October 2006 - 10:11 PM

I have been doing a lot of google searching and such but still havent be able to come up with anything to help me with what I need, and I finally found this site and decided I will post to see if anybody can help. I am currently trying to code my clan site (best viewed in IE, Firefox hates me), and I am trying to find a way to make information update itself on multiple pages by only changing it on one. I know this can be done, cause I have seen it mentioned, but never seen any code. I dont know php or how to make or code a database. So all the more help, the better I can understand to help someone else if needed.

Alright, my test site is www.nwn2world.com/Veneratio2

The information I want to update on all pages is the "Latest Demos", "Latest Matches" and "Veneratio Misc." Boxes. (Again, please view in IE for best results atm) Thank you.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 October 2006 - 10:25 PM

I don't know what you mean.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 October 2006 - 10:57 PM

What I wana do is make it so if I changed the "Latest Demos" section on the index.html it will automatically change the other .html pages like roster.html, sponsors.html and so forth. This way I dont have to manually edit each page by itself.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 October 2006 - 11:04 PM

Well, yes, that's going to require centralized content... usually in a DB, though there are all sorts of ways to cheat.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 October 2006 - 11:10 PM

okay, which is the easiest way, cause I aint the hotest with DBs and such. Which code would I insert into those cells.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 October 2006 - 07:19 PM

It's not so simple... if you want dynamic content that's MySQL / PHP driven, you're definitely on the correct website ;-)  But it's not just a cut-and-paste job.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 07:22 PM

well, I have created a database and a table within the db called demos.... trying to get this code to work in my .html page now... I tried this...


<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("nwn2wor_veneratio",$db);
$result = mysql_query("SELECT * FROM `demos` WHERE 1`demo1``demo2``demo3``demo4``demo5`",$db);
echo "<TABLE>";
while($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>";
echo $myrow["demo1"];
echo "<TR><TD>";
echo $myrow["demo2"];
echo "<TR><TD>";
echo $myrow["demo3"];
echo "<TR><TD>";
echo $myrow["demo4"];
echo "<TR><TD>";
echo $myrow["demo5"];
}
echo "</TABLE>";
?>

#8 JayBachatero

JayBachatero
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 05 October 2006 - 07:23 PM

You have to rename your .html page to .php for it to be parsed.
JayBachatero
SMF Developer && Converter Specialist

#9 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 07:36 PM

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/nwn2wor/public_html/Veneratio2/index.php on line 113

this is what I got back, but if I am going to have to put in my user and password... cant someone steal that?

#10 JayBachatero

JayBachatero
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 05 October 2006 - 07:47 PM

No that won't be shown to the browser.  The browser will see what ever is echoed to it.
JayBachatero
SMF Developer && Converter Specialist

#11 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 07:49 PM

alright... I am trying this but getting a parse error...
<?php 
$db = mysql_connect("localhost", "******", "********"); 
mysql_select_db("nwn2wor_veneratio",$db); 
$result = mysql_query("SELECT * FROM `demos`",$db);
or die("Query failed: $sql<br />".mysql_error()); 
if(!mysql_num_rows($result))
  {
  echo "No results returned by query $sql";
  }
else
  {
"<TABLE>"; 
while($myrow = mysql_fetch_array($result)) 
{ 
"<TR><TD>"; 
$myrow["demo1"];
"</TR></TD>"; 
"<TR><TD>"; 
$myrow["demo2"]; 
"</TR></TD>";
"<TR><TD>"; 
$myrow["demo3"]; 
"</TR></TD>";
"<TR><TD>"; 
$myrow["demo4"];
"</TR></TD>";
"<TR><TD>"; 
$myrow["demo5"];
"</TR></TD>";
} 
"</TABLE>"; 
?>

also... cant someone just view source and see the login/password?

mod edit  : security data removed and code tags added

#12 JayBachatero

JayBachatero
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 05 October 2006 - 07:52 PM

No not when php parses it.  You should remove the password from your post though.  What I meant was that when you put it on your site and PHP parses it won't be shown.
JayBachatero
SMF Developer && Converter Specialist

#13 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 07:57 PM

If someone tries to view a php page all they see is the generated HTML output.

However, you could/should put the security data in an include file located outside the web root directory tree for added security.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#14 JayBachatero

JayBachatero
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 05 October 2006 - 07:59 PM

Ok this should work for you.

<?php

$db = mysql_connect("localhost", "******", "******");
mysql_select_db("nwn2wor_veneratio",$db);
$result = mysql_query("SELECT * FROM `demos`",$db) or die("Query failed: $sql".mysql_error());

if(!mysql_num_rows($result))
	echo "No results returned by query $sql";
else
{
	echo '
		<TABLE>';

	while($myrow = mysql_fetch_assoc($result))
	{
		echo '
			<TR>
				<TD>', $myrow["demo1"], '</TD>
				<TD>', $myrow["demo2"], '</TD>
				<TD>', $myrow["demo3"], '</TD>
				<TD>', $myrow["demo4"], '</TD>
				<TD>', $myrow["demo5"], '</TD>
			</TR>';
	}

	echo '
		</TABLE>';
}
mysql_free_result($result);
?>

JayBachatero
SMF Developer && Converter Specialist

#15 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 08:00 PM

So much for reporting his post re password inclusion :/
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#16 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 08:02 PM

what u mean Barand?

#17 JayBachatero

JayBachatero
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 05 October 2006 - 08:04 PM

So much for reporting his post re password inclusion :/

I realized that I forgot to edit that after I posted.  I edited the post right away though.
JayBachatero
SMF Developer && Converter Specialist

#18 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 08:08 PM

ahhh, its all good, I delete that db user and created a new one with new password.

I got the code to work by tweaking the table to this..

{
echo '
<TR>
<TD>', $myrow["demo1"], '</TD></TR>
<TR>
<TD>', $myrow["demo2"], '</TD></TR>
<TR>
<TD>', $myrow["demo3"], '</TD></TR>
<TR>
<TD>', $myrow["demo4"], '</TD></TR>
<TR>
<TD>', $myrow["demo5"], '</TD></TR>
</TR>';
}


and now the it looks perfect on my site, thank you.

#19 Kylo

Kylo
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 October 2006 - 08:10 PM

just one last question.... if I wanted to link one of those demo1 or demo2 to a file to download, what would I do to edit the code?

#20 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 08:20 PM

Store

<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("nwn2wor_veneratio",$db);
?>


in a file called, say, "connect.inc.php" and store that on the server outside the web root directory tree.

In you scripts that need to acces the db

<?php
include 'connect.inc.php';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users