Jump to content

[SOLVED] Super Long Forums Code Syntax


mattd8752

Recommended Posts

My index.php contains:

<?php
include "config.php";
include "./includes/all.php";
$fdisplay = $_GET['f'];

$sql="SELECT * FROM topic";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>

<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
<?php
include "footer.php";
?>

 

All.php contains:

<?php
include "ip.php";
include "dbconnect.php";
?>

 

Ok, now dbconnect.php contains:

<?php
include "config.php";
$link = mysql_connect('localhost', $mysqluser, $mysqlpass);
if (!$link) {
$url = $PHP_SELF;
$message = "The DBconnect page of " . $url . " could not properly be run.<br>";
$message .= "The error was:<br><b>";
$message .= mysql_error($link);
$message .= "</b><br><br>---This Message Was Sent By PHP---";
mail($email, 'MySQL Error', $message);

die("An error has occured.  An email has been sent to the site administrator.");
}
echo "test";
?>

 

Loading dbconnect.php gives the output:

 

test

 

And index.php gives:

test

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in G:\apps\ws\www\start\index.php on line 20

 

then an empty table.  I can run this on a real server if you need it, but atm it is just local host.  BTW config.php is in both directories because of include ""; errors.

Link to comment
https://forums.phpfreaks.com/topic/37860-solved-super-long-forums-code-syntax/
Share on other sites

$link = mysql_connect('localhost', $mysqluser, $mysqlpass);

if (!$link) {

$message .= mysql_error($link);

 

This doesn't make any sense, you say if !$link, then try to use $link again.

 

Do this:

$link = mysql_connect('localhost', $mysqluser, $mysqlpass) OR die(mysql_error());

Does that print a different error?

Is your server localhost, your username and password correct, etc?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in G:\apps\ws\www\start\index.php on line 20 is still the reply.

 

<?php

include "config.php";

$link = mysql_connect('localhost', $mysqluser, $mysqlpass) OR die(mysql_error());

if (!$link) {

}

echo "test";

?>

is the new code.  same problem.

Try putting this in the various places throughout your code.  You also forgot to select your database I think:

 

$server='localhost';

$mysqluser='username';

$mysqlpassword='password';

$mydtb='database name';

 

$connect=mysql_connect($server,$user,$password);

mysql_select_db($mydtb);

 

$query = "SELECT * FROM topic";

$result= mysql_query($query, $connect);

while ($row = mysql_fetch_array ($result))

{

Ok, I've got some issues with view.php, it should show the topic.  I click the link, and it displays the following:  and yes the topic does exist and the ID is correct.  I saw an empty table where the answer should be and I got this error above it:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in G:\apps\ws\www\start\view.php on line 10

 

and the same error 2x below it followed by the reply form.

 

Here is the code:

<?php
include "./includes/dbconnect.php";

// get value of id that sent from address bar
$id=$_GET['id'];

$sql="SELECT * FROM replies WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" 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><? echo $rows['topic']; ?></strong></td>
</tr>

<tr>
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td>
</tr>

<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td>
</tr>

<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
$tbl_name2="forum_answer"; // Switch to table "forum_answer"

$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2=mysql_query($sql2);

while($rows=mysql_fetch_array($result2)){
?>
<table width="400" 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 bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>

<?
}

$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);

$rows=mysql_fetch_array($result3);
$view=$rows['view'];

// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}

// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);

mysql_close();
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_answer.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45"></td>
</tr>
<tr>
<td valign="top"><strong>Answer</strong></td>
<td valign="top">:</td>
<td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</table> 
<?php
include "footer.php";
?>

 

Thanks -- Matt

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.