Jump to content

[SOLVED] Some Script Help


Shaun13

Recommended Posts

Here is a script I have created.

 

<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);

// database info
$host="localhost"; // Host name 
$username="=P"; // Mysql username 
$password="=P"; // Mysql password 
$db_name="=P"; // Database name 
// end database info

// connect to database
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
// end connect to database

// table info
$tablemembers="members";
$tableposts="posts";
$tablereplies="replies";
// end table info

// etc. variables
$myusername=$_SESSION['myusername'];
// end etc. variables

// actions
$viewtopic=$_REQUEST['viewtopic'];
$action=$_REQUEST['action'];
// end actions

// mysql queries
$sql="SELECT * FROM $tableposts ORDER BY id DESC";
$result=mysql_query($sql);


$sql1="SELECT * FROM $tableposts WHERE id='$id'";
$result1=mysql_query($sql1);
$rows1=mysql_fetch_array($result1);


$dnsql="SELECT displayname FROM $tablemembers WHERE username = '$myusername'";
$dnresult=mysql_query($dnsql);


$sql2="SELECT * FROM $tablereplies WHERE questionid='$id'";
$result2=mysql_query($sql2);


$sql3="SELECT views FROM $tableposts WHERE id='$id'";
$result3=mysql_query($sql3);
$rows3=mysql_fetch_array($result3);
$views3=$rows3['views'];


$sql4="INSERT INTO $tableposts(views) VALUES('$views3') WHERE id='$id'";


$sql5="update $tableposts set views='$addview' WHERE id='$id'";

$sql6="SELECT * FROM $tbl_name WHERE id='$id'";
$result6=mysql_query($sql6);
// end mysql queries

?>
<center>
<?php
// start header code
if (mysql_num_rows($dnresult)>0) 
{
while ($dn = mysql_fetch_assoc($dnresult)) 
{
	extract($dn);
	if(isset($myusername))
	{
	echo "Welcome , $displayname | <a href='logout.php'>Logout</a>";
	}
}
}
elseif (!isset($myusername)) {
   echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>";
}

echo "<br>Your Location: <a href='index.php'>ShaunsBoards</a>";

if(isset($viewtopic))
{
echo " > <a href='index.php?viewtopic=".$rowspost1['id']."'>".$rowspost1['title']."<br><br>";
}

else
{
echo "<a href='index.php'></a>";
}
// end header code

// begin viewtopic action
$rowsstuff=mysql_fetch_array($result6);

if (isset($viewtopic))
{
$id=$viewtopic;
echo "<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td><table width='100%' border='0' cellpadding='3' cellspacing='1' bordercolor='1' bgcolor='#FFFFFF'>
<tr>
<td bgcolor='#F8F7F1'><strong>".$rowsstuff['title']."</strong></td>
</tr>

<tr>
<td bgcolor='#F8F7F1'>".$rowsstuff['content']."</td>
</tr>

<tr>
<td bgcolor='#F8F7F1'><strong>By :</strong>".$rowsstuff['authordisplay']."</td>
</tr>

<tr>
<td bgcolor='#F8F7F1'><strong>Date/time : </strong>".$rowsstuff['datetime']."</td>
</tr>
</table></td>
</tr>
</table>
<BR>";

echo "<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td><table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
<tr>
<td width='18%' bgcolor='#F8F7F1'><strong>By</strong></td>
<td width='5%' bgcolor='#F8F7F1'>:</td>
<td width='77%' bgcolor='#F8F7F1'>".$rowsstuff['authordisplay']."</td>
</tr>
<tr>
<td bgcolor='#F8F7F1'><strong>Post</strong></td>
<td bgcolor='#F8F7F1'>:</td>
<td bgcolor='#F8F7F1'>".$rowsstuff['content']."</td>
</tr>
<tr>
<td bgcolor='#F8F7F1'><strong>Date/Time</strong></td>
<td bgcolor='#F8F7F1'>:</td>
<td bgcolor='#F8F7F1'>".$rowsstuff['datetime']."</td>
</tr>
</table></td>
</tr>
</table><br>";


if(session_is_registered(myusername))
	{
	echo "<table width='400' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
	<tr>
	<form name='form1' method='post' action='index.php?action=reply'>
	<td>
	<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
	<tr>
	<td valign='top'><strong>Post</strong></td>
	<td valign='top'>:</td>
	<td><textarea name='content' cols='45' rows='3' id='content'></textarea></td>
	</tr>
	<tr>
	<td> </td>
	<td><input name='id' type='hidden' value='".$id."'></td>
	<td><input type='submit' name='Submit' value='Submit'> <input type='reset' name='Submit2' value='Reset'></td>
	</tr>
	</table>
	</td>
	</form>";
	}
else
	{
	echo "<a href='login.php'>Login</a> to reply to topics!";
	}

if(empty($views3))
	{
	$views3=1;
	$result4=mysql_query($sql4);
	}

$addview=$views3+1;
$result5=mysql_query($sql5);
exit;
}



echo "</center>
<br /><br />
<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td width='40%' align='center' bgcolor='#CCDDCC'><strong>Topic</strong></td>
<td width='20%' align='center' bgcolor='#CCDDCC'><strong>Author</strong></td>
<td width='15%' align='center' bgcolor='#CCDDCC'><strong>Views</strong></td>
<td width='13%' align='center' bgcolor='#CCDDCC'><strong>Replies</strong></td>
<td width='13%' align='center' bgcolor='#CCDDCC'><strong>Date/Time</strong></td>
</tr>";

while($rowstopics=mysql_fetch_array($result)){ // Start looping table row 

echo "<tr>
<td bgcolor='#FFFFFF'><a href='index.php?viewtopic=".$rowstopics['id']."'>".$rowstopics['title']."</a><BR></td>
<td align='center' bgcolor='#FFFFFF'>".$rowstopics['authordisplay']."</td>
<td align='center' bgcolor='#FFFFFF'>".$rowstopics['views']."</td>
<td align='center' bgcolor='#FFFFFF'>".$rowstopics['posts']."</td>
<td align='center' bgcolor='#FFFFFF'>".$rowstopics['datetime']."</td>
</tr>";
}
echo "<tr>
<td colspan='5' align='right' bgcolor='#CCDDCC'>";

if(isset($_SESSION['myusername']))
{
echo "<a href='create_topic.php'><strong>Create New Topic</strong></a><br>";
}
else
{
echo "<a href='login.php'>Login</a> to start topics!";
}
?>
</center>

 

Now, on the page I get the error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/shaunsnetwork/shaunsboards/index.php on line 98

 

Can anyone help me out?

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.