Jump to content

php/mysql forum im making not working.


silverglade

Recommended Posts

i tried to load the first page of my forum that i put in the wwwroot directory of my hosted server, where the ******* are i put in my

phpadmin user and password, the page  gives me the error.

 

Fatal error: Call to undefined function mysql_connect() in D:\Inetpub\virtual\brendansite1\WWWROOT\main_forum.php on line 9

 

 

here is the code to the main page of my forum, any help greatly appreciated, thanks. i think it has to do with line nine. hehe.

 

<?php
$host="localhost"; // Host name 
$username="********"; // Mysql username 
$password="*********"; // Mysql password 
$db_name="brendansite1"; // Database name 
$tbl_name="forum_question"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// 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>

Link to comment
https://forums.phpfreaks.com/topic/118251-phpmysql-forum-im-making-not-working/
Share on other sites

let me guess, php5 on a windows machine?

 

the mysql libraries are not included with php5.  You need to manually install them. 

 

I was actually fighting this last night and couldn't find a resolution (although I didn't try that long) so hopefully someone will give a solution.

i altered the code a little on the top, and i get the following error  when trying to connect to the database with this page.

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'brendansite1@localhost' (Using password: YES) in D:\Inetpub\virtual\brendansite1\WWWROOT\main_forum.php on line 10

cannot connect

 

here is the code, any help greatly appreciated. thank you. derek i put ****** where my user and password is for this post.

 

<?php
dl("php_mysql.dll"); 
$host="localhost"; // Host name 
$username="*********"; // Mysql username 
$password="**********"; // Mysql password 
$db_name="brendansite1"; // Database name 
$tbl_name="forum_question"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// 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>

 

 

 

 

always check with your hosting provider for answers if you cant  get them in the forum. i got my PHP discussion forum up at the following link!!!! YES!!!

 

http://derekvanderven.com/main_forum.php

 

 

my hosting provider technical support answered my questions and i got my board up. sweet. thank you. derek

always check with your hosting provider for answers if you cant  get them in the forum. i got my PHP discussion forum up at the following link!!!! YES!!!

 

http://derekvanderven.com/main_forum.php

 

 

my hosting provider technical support answered my questions and i got my board up. sweet. thank you. derek

 

A little plain, but good for a first forum.

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.