Jump to content

Help with Troubleshooting PHP and MySql Code...Creating Database


crazyphp

Recommended Posts

Hello everyone. Recently the hosting company that I was using moved to another server. When they did that, some of the database didn't transfer over so I have to create a new one on the new server. I don't have that much experience with programming in php or sql. If you guys can please help me out, I would greatly appreciate. I will try and explain it the best I can.

 

I have a site that someone goes into and upload files which create a table of 3 column. It has Date, Title, and Category.

 

The file to this page is called news.php

 

here is the code to that page:

 

<?php
include_once("../includes/config.php");
session_start();

$cn = db_connect();
// Authenticate user...
//	$cookieinfo = explode("-", $_COOKIE['elite']);
$auth = $_SESSION["auth"];
if ($auth != "y") {
	header("Location: login.php");
}

// Are we logging out?
$logout = $_GET['out'];
if ($logout == "") {
	$logout = $_POST['out'];
}
if ($logout == "y") {
//	session_destroy();
	header("Location: login.php");
}

// Retrieve the events info...

$query = "SELECT * FROM events ORDER BY eventdate DESC";

$rs = mysql_query($query);
$nRows = mysql_num_rows($rs);
$row = mysql_fetch_array($rs);
$i = 0;
if ($nRows != 0) {
	do {





		$eventid[$i] = $row["id"];
		$eventdate[$i] = $row["eventdate"];
		$eventdate[$i] = date('n/j/Y', $eventdate[$i]) ;
		$title[$i] = $row["title"];
		$category[$i] = $row["category"];
		$event_file[$i] = $row["event_file"];

		$i++;
		$row = mysql_fetch_array($rs);
	}
	while ($i != ($nRows));
}
   	mysql_close($cn);
?>

 

On the old server, it works and show me the following

 

pic1a.JPG

 

Here is the config.php code:

 

<?php
/*function db_connect()
{
$cn = mysql_pconnect('localhost', '', '') or die("Cannot connect to server!");
mysql_select_db("bnf");
return $cn;
}*/

function db_connect()
{
$cn = mysql_pconnect('localhost', '[email protected]', 'yes') or die("Cannot connect to server!");
mysql_select_db("bnf_com");
return $cn;
}
?>

 

Can someone please take a look at this and let me know what you think. Thank you very much.

 

 

 

in addition. here is what i get when i tried to go to news.php on the new server. I get the following error:

 

Warning: mysql_pconnect() expects parameter 4 to be long, string given in /home/benefita/public_html/nossl/includes/config.php on line 11

Cannot connect to server!

 

So I then changed line 11 in config.php. here is what i got:

 

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/benefita/public_html/nossl/includes/config.php on line 11

Cannot connect to server!

 

what do i have to do to correct this issue?

 

sorry I didn't include some of the vital information needed.

 

mysql client version 5.1.30

phpmyadmin version 2.11.9.5

 

 

I fixed the error I was getting. I have another issue if someone can help me out with.

 

The issue is as follow:

 

The SQL code in the php files are:

 

<?php
include_once("../includes/config.php");
session_start();

$cn = db_connect();
// Authenticate user...
//	$cookieinfo = explode("-", $_COOKIE['elite']);
$auth = $_SESSION["auth"];
if ($auth != "y") {
	header("Location: login.php");
}

// Are we logging out?
$logout = $_GET['out'];
if ($logout == "") {
	$logout = $_POST['out'];
}
if ($logout == "y") {
//	session_destroy();
	header("Location: login.php");
}

// Retrieve the events info...

$query = "SELECT * FROM events ORDER BY eventdate DESC";

$rs = mysql_query($query);
$nRows = mysql_num_rows($rs);
$row = mysql_fetch_array($rs);
$i = 0;
if ($nRows != 0) {
	do {





		$eventid[$i] = $row["id"];
		$eventdate[$i] = $row["eventdate"];
		$eventdate[$i] = date('n/j/Y', $eventdate[$i]) ;
		$title[$i] = $row["title"];
		$category[$i] = $row["category"];
		$event_file[$i] = $row["event_file"];

		$i++;
		$row = mysql_fetch_array($rs);
	}
	while ($i != ($nRows));
}
   	mysql_close($cn);

 

the error that I am getting is:

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/benefita/public_html/nossl/admin/news.php on line 28

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/benefita/public_html/nossl/admin/news.php on line 29

 

Line 28 and Line 29 is as follow:

 

	$nRows = mysql_num_rows($rs);
$row = mysql_fetch_array($rs);

 

looks like I have to create a colum for num row? can someone advise on what to do. Thank you so much.

 

 

 

 

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.