Jump to content

problem with php code


sub7av

Recommended Posts

I want to grab my currently online members from my forum and put them on my homepage, I have done this and managed to get them to display in a testpage called  tttt.php

 

now when I go to my homepage I want to paste my sql call code which is about 7 lines.

I want to put this at the bottom of my homepage but it keeps giving me an error.

I can paste the code into the top and there they all, but I want to put them at the bottom inside my box.

 

my code I want to paste the users into looks like this:

 

<center><table width="100%" cellspacing="1" cellpadding="4" border="0" class="border">

<tr>

<td class="windowbg4"><center><b>Users Online<b> </b> <b></b></td>

</tr><tr>

<td class="windowbg3"><center><center><font size="1">We currently have the following users online</font></center>

<form action="index.php?action=login&sub=1" method="post">

<table width="100%" cellspacing="1" cellpadding="4" border="0">

 

<td class="windowbg" colspan="2"><br><font size="1" color="#428cd1">

 

 

                          <b><img src="ico/sub7.gif"> USERS MUST GO INTO HERE </title></b></font></a><Br>

 

 

 

 

 

 

 

 

 

<br></tr>

</table>

</form>

</td>

</tr>

 

 

the part where is says USER MUST GO HERE,  is where I want to insert my call from the sql.

Do I need to echo my page tttt.php into this?

 

can anyone help

 

 

My sql code I want to insert is:

 

 

 

<?php

 

$con = mysql_connect('localhost', 'myane', 'test');

mysql_select_db('theroman_pete',$con);

 

$t = time() - 3600;

$q = mysql_query("select username FROM user WHERE lastactivity > $t");

 

while ($u = mysql_fetch_array($q))

   echo $u['username']." ";

?>

Link to comment
Share on other sites

I'm not sure if it's a problem...but should you instead make the mysql_fetch_array call as follows:

 

<code>$u = mysql_fetch_array($q, MYSQL_ASSOC)</code>

 

As far as I'm aware, I think you need to send that value so it knows how to access the fields the way you are trying to...I could be wrong though.

Link to comment
Share on other sites

hey thanks for the help guys..

 

 

here is a screenshot of my code and when I put any code inbetween the red x I get error:  Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/theroman/public_html/home.php on line 150

 

the code I want inside there is the call from mysql, this works okay on another page called tttt.php so I dont know if I can paste the sql code thats calls into here but i get error or someone eco page tttt.php into there?

 

exdzs2.gif

Link to comment
Share on other sites

Sometimes it's a good idea to actually read what the error says...  You're getting an error because it looks like you are trying to add code inside your echo statement.  It's kind of unconventional to write code the way you have done so, with long echo statements outputting a bunch of HTML... I would recommend just breaking out of PHP while you don't need it, and then jump back into it where you need to put your code.  If you're persistent on doing it your way, just make two echo statements and put your code in between them.  Something like:

 

<?php

echo 'All of your HTML up to... <b><img src="ico/sub7.gif">';

// Your other code goes here

echo '</title>... through ...</table>';

?>

 

Theo

Link to comment
Share on other sites

the top of my code: 

 

<? 

echo '<title>'.$site_title.' - Home</title>

<table width="100%" cellspacing="1" cellpadding="4" border="0">
<tr valign="top">
	<td class="windowbg" wi

 

 

ect...

 

then I get to

<b><img src="ico/sub7.gif">  </title></b></font></a><Br>

 

how do I add your idea to get my code in this?

 

my code I want inside this is:

 

 <?php

$con = mysql_connect('localhost', 'testuser', 'testpass');
mysql_select_db('testuser_tr6',$con);

$t = time() - 3600;
$q = mysql_query("select username FROM user WHERE lastactivity > $t");

while ($u = mysql_fetch_array($q))
   echo $u['username']." ";
?> 

Link to comment
Share on other sites

One way would be to do the following:

 

<?php

$con = mysql_connect('localhost', 'testuser', 'testpass');
mysql_select_db('testuser_tr6',$con);

function displayOnline(){
    $t = time() - 3600;
    $q = mysql_query("select username FROM user WHERE lastactivity > $t");

    while ($u = mysql_fetch_array($q))
        echo $u['username']." ";
}

echo '<title>... <img src="ico/sub7.gif">' . displayOnline() . '</title>....';

?>

Theo

Link to comment
Share on other sites

my whole source code for page:

 

 <? 

echo '<title>'.$site_title.' - Home</title>

<table width="100%" cellspacing="1" cellpadding="4" border="0">
<tr valign="top">
	<td class="windowbg" width="70%"><br><img src="images/cart55small.gif" align="left" hspace="17" vspace="10"> 
	  <font size="3" class="title_text"><BR>What is cart55 - 



    
        
	';
	if($gs_user == 1){
		echo '<hr size="1" noshade="1">
		 <font size="3">Subscribe to cart56</font>';


		if(mysql_num_rows($subscriptions) > 0){
			echo 'You are currently subscribed to cart55.<a href="index.php?action=subscribe"><b>Click here to remove your subscription</b></a>.';
		} else {
			echo 'You can enable subscriptions to receive emails when a new video is added. <a href="index.php?action=subscribe"><b>Click here to enable subscriptions</b></a>.';
		}
	}
	echo '</td>
	<td class="windowbg" width="24%">';
	if($gs_user == 1){
		echo '<table width="100%" cellspacing="1" cellpadding="4" border="0" class="border2">
			<tr>
				<td class="windowbg4"><img src="ico/user.png"> <b>Welcome back, '.$gs_account['display_name'].'.</b></td>
			</tr><tr>
				<td class="windowbg3"><left><a href="index.php?action=view_profile&user='.$gs_account['username'].'"><img src="ico/user.png" border="0">View Profile</a> <a href="index.php?action=admin&sec=modify_profile"><img src="ico/user_edit.png" border="0"> Modify Profile</a></left></td>
			</tr>';

	} else {
		echo '<table width="100%" cellspacing="1" cellpadding="4" border="0" class="border2">
			<tr>
				<td class="windowbg4"> <b>Download All cart55 Versions</b></td>
			</tr><tr>	
				<td class="windowbg2">
				<form action="index.php?action=login&sub=1" method="post">
				<table width="100%" cellspacing="1" cellpadding="4" border="0">


		</table>';
	}
	echo '
	<table width="100%" cellspacing="1" cellpadding="4" border="0" class="border2">
		<tr>
			<td class="windowbg4"> <center><b>DOWNLOADS</b></td>
		</tr><tr>
			<td class="windowbg3"><form action="index.php?action=login&sub=1" method="post">
				<table width="100%" cellspacing="0" cellpadding="0" border="0">

				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.2.zip"><img src="ico/cart552.gif" border="0"></a></center></td>
                            
					</tr>
				</table>
				</form>
				</td>
			</tr><tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.5%20Legends.zip"><img src="ico/cart55leg.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.4%20Defcon8.zip"><img src="ico/cart55def.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.3%20Bonus.zip"><img src="ico/cart55bon.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.2%20Muie.zip"><img src="ico/cart55mu.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.1%20Gold.zip"><img src="ico/cart55gold.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.1.0.zip"><img src="ico/cart5521.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v2.0.zip"><img src="ico/cart5520.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.9.zip"><img src="ico/cart5519.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.8.zip"><img src="ico/cart5518.gif" border="0"></a></center></td>
			</tr>
</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.7.zip"><img src="ico/cart5517.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.6.zip"><img src="ico/cart5516.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.5.zip"><img src="ico/cart5515.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.4.zip"><img src="ico/cart5514.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.3.zip"><img src="ico/cart5513.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.2.zip"><img src="ico/cart5512.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.1.zip"><img src="ico/cart5511.gif" border="0"></a></center></td>
			</tr>
<tr>
				<td class="windowbg3"><center><a href="http://cart56.com/downloads/cart55%20v1.0.zip"><img src="ico/cart5510.gif" border="0"></a></center></td>
			</tr>
		</table>';




			echo '</td>
		</tr>
	</table>
	</td>
</tr>
</table>

<center><table width="100%" cellspacing="1" cellpadding="4" border="0" class="border">
			<tr>
				<td class="windowbg4"><center><b>Users Online<b> </b> <b></b></td>
			</tr><tr>	
				<td class="windowbg3"><center><center><font size="1">We currently have the following users online</font></center>
				<form action="index.php?action=login&sub=1" method="post">
				<table width="100%" cellspacing="1" cellpadding="4" border="0">

						<td class="windowbg" colspan="2"><br><font size="1" color="#428cd1">


                           ?><b><img src="ico/cart55.gif">  </title></b></font></a><Br>









					<br></tr>
				</table>
				</form>
				</td>
			</tr><tr>
				<td class="windowbg3"><center><center> <a href="index.php?action=home">www.cart56.com</a></td>
			</tr
		</table>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.