crazyphp Posted July 2, 2009 Share Posted July 2, 2009 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 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', 'web@bnf.com', '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. Quote Link to comment https://forums.phpfreaks.com/topic/164554-help-with-troubleshooting-php-and-mysql-codecreating-database/ Share on other sites More sharing options...
crazyphp Posted July 2, 2009 Author Share Posted July 2, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/164554-help-with-troubleshooting-php-and-mysql-codecreating-database/#findComment-867957 Share on other sites More sharing options...
fenway Posted July 4, 2009 Share Posted July 4, 2009 Why pconnect? Why no password? Quote Link to comment https://forums.phpfreaks.com/topic/164554-help-with-troubleshooting-php-and-mysql-codecreating-database/#findComment-868630 Share on other sites More sharing options...
crazyphp Posted July 6, 2009 Author Share Posted July 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/164554-help-with-troubleshooting-php-and-mysql-codecreating-database/#findComment-869844 Share on other sites More sharing options...
fenway Posted July 10, 2009 Share Posted July 10, 2009 Why is your query failing? Check mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/164554-help-with-troubleshooting-php-and-mysql-codecreating-database/#findComment-872503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.