Jump to content

Include + SQL


prudens

Recommended Posts

Error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'smtp'@'localhost' (using password: NO) in ./functions.php on line 10

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in ./functions.php on line 11

Warning: mysql_query() [function.mysql-query]: Access denied for user 'smtp'@'localhost' (using password: NO) in ./functions.php on line 13

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in ./functions.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ./functions.php on line 14

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in ./functions.php on line 15

 

functions.php


<?
require_once "header.php"; //Facebook API and Login session

function getAuthors ($id)
{

//$id refers to the legislation id
//connect to sql
$conn = mysql_connect ($sql_host,$sql_user,$sql_pass);
$select = mysql_select_db ($sql_db,$conn);
$query = "SELECT * FROM " . $sql_table_legislation . " WHERE id = $id";
$results = mysql_query ($query);
$row = mysql_fetch_array($results);
mysql_close($conn);
//
//$row should be LIKE "0219209,2923989,585783,..."
$out = explode(',', $row['authors']);

for ($i=0; $i<count($out); $i++)
{
	echo " $out[$i]";
}
}

?>

 

view.php

<?
require_once "header.php";
include_once("functions.php");

$type = $_GET['type'];
$id   = $_GET['id'];

if ($type == 'bookies')
{
$conn = mysql_connect ($sql_host,$sql_user,$sql_pass);
$select = mysql_select_db ($sql_db,$conn);
$query = "SELECT * FROM ". $sql_table_legislation ." WHERE id = $id";
$results = mysql_query ($query);
$row = mysql_fetch_array ($results);
mysql_close($conn);

//FORMAT
echo $row['title'] . "<br><br>";
echo "Author(s): " . getAuthors($id) . "<br>";
echo "Sponsor(s): " .$row['sponsors'] . "<br>";
echo "Date Submitted:" . $row['date'] . "<br>";
echo "Last Updated:" . $row['lastupdated'] . "<br>"; 
echo "<br><div align='center'><font size=4>{$row['title']}</font></div><br>";
echo $row['body'] . "<br>";
echo "<a href=" . 'index.php' . ">Return</a>";
}
elseif ($type == 'ddd')
{
echo "none";
}
?>

 

header.php

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<?

$sql_host = "localhost:3306";
$sql_user = "username";
$sql_pass = "password";
$sql_db   = "stuff";
$sql_table_students = "reading";
$sql_table_legislation = "hi";
?>

</html>

 

 

 

Someone pls help! ??? My main problem is in view.php where I attempted to include functions.php; I am trying to call getAuthors() function of functions.php from view.php; but it generates errors...

Link to comment
https://forums.phpfreaks.com/topic/106256-include-sql/
Share on other sites

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.