Page 1 of 1
Error trying to connect to DB
Posted: Mon Dec 04, 2006 1:38 am
by 4Boredom
Warning: main(/home/i4boredo/marlins/db.php): failed to open stream: No such file or directory in /home/i4boredo/public_html/marlins/processo.php on line 3
Fatal error: main(): Failed opening required '/home/i4boredo/marlins/db.php' (include_path='.:/usr/local/lib/php') in /home/i4boredo/public_html/marlins/processo.php on line 3
db.php
Code: Select all
I have vars up here with pws that are corrent but ive taken out for privacy reasons
#connection info
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>
Code: Select all
<?
ob_start();
require_once("/home/i4boredo/marlins/db.php");
$Name = $_POST['Name'];
$G = $_POST['G'];
$AB = $_POST['AB'];
$Runs = $_POST['Runs'];
$Hits = $_POST['Hits'];
$B2 = $_POST['2B'];
$B3 = $_POST['3B'];
$HR = $_POST['HR'];
$RBI = $_POST['RBI'];
$BB = $_POST['BB'];
$SO = $_POST['SO'];
$CS = $_POST['CS'];
$HBP = $_POST['HBP'];
$SAC = $_POST['SAC'];
$sql = mysql_query("UPDATE `offensive_stats` SET G='{$G}',AB='{$AB}',Runs='{$Runs}',Hits = '{$Hits}',2B = '{$B2}',3B = '{$B3}',HR = '{$HR}',RBI = '{$RBI}',BB = '{$BB}',SO = '{$SO}',CS = '{$CS}',HBP = '{$HBP}',SAC = '{$SAC}' WHERE Name = '{$Name}'");
if(!$sql){
$error.= 'There has been an error posting your comment. Please contact the webmaster.';
} else {
echo 'Stat Added!';
}
?>
Posted: Mon Dec 04, 2006 1:47 am
by RobertGonzalez
Check your filename spelling (and case) and make sure the file is actually in the specified path. That first error is what is killing your app. It is telling you that it cannot open the included file because the file, according to PHP, does not exist.
Re: Error trying to connect to DB
Posted: Mon Dec 04, 2006 3:27 am
by ok
4Boredom wrote:Warning: main(/home/i4boredo/marlins/db.php): failed to open stream: No such file or directory in /home/i4boredo/public_html/marlins/processo.php on line 3
Fatal error: main(): Failed opening required '/home/i4boredo/marlins/db.php' (include_path='.:/usr/local/lib/php') in /home/i4boredo/public_html/marlins/processo.php on line 3
Check file permissions if you work under linux. Make sure that PHP/your web server has access to the file.
4Boredom wrote:
db.php
Code: Select all
I have vars up here with pws that are corrent but ive taken out for privacy reasons
#connection info
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>
You don't need to put quotes on vars. And, if you open only one connection to the DB, you don't need $connection:
Code: Select all
#connection info
mysql_connect($dbhost, $dbusername, $dbpasswd) or die ("Couldn't connect to server.");
$db = mysql_select_db($database_name) or die("Couldn't select database.");
?>
You can write processo.php in an easy way:
Code: Select all
<?
ob_start();
require_once("/home/i4boredo/marlins/db.php");
extract($_POST);
$sql = mysql_query("UPDATE `offensive_stats` SET G='{$G}',AB='{$AB}',Runs='{$Runs}',Hits = '{$Hits}',2B = '{$B2}',3B = '{$B3}',HR = '{$HR}',RBI = '{$RBI}',BB = '{$BB}',SO = '{$SO}',CS = '{$CS}',HBP = '{$HBP}',SAC = '{$SAC}' WHERE Name = '{$Name}'");
if(!$sql){
$error = "There has been an error posting your comment. Please contact the webmaster.";
} else {
echo "Stat Added!";
}
?>
P.S
I'm not sure that you can add {} in a quoted string: $a = "My name is: {$name}".
Re: Error trying to connect to DB
Posted: Mon Dec 04, 2006 3:37 am
by volka
ok wrote:P.S
I'm not sure that you can add {} in a quoted string: $a = "My name is: {$name}".
You can
Code: Select all
<?php
$x = 1;
$y = 'abc';
$a = "{$x} ... {$y}";
echo $a, "<br />\n";
?>
But you don't need to in this simple case, see see
http://de2.php.net/language.types.strin ... ng.complex
While at it, please also read
http://de2.php.net/mysql_real_escape_string and
http://en.wikipedia.org/wiki/SQL_injection
Re: Error trying to connect to DB
Posted: Mon Dec 04, 2006 3:45 am
by ok
Cool

Posted: Tue Dec 05, 2006 3:44 pm
by 4Boredom
Yea my permissions were set wrong.. I had set teh forum permission right but not each file.
Not it locates the DB.... but it isnt processing like it should
http://4boredom.com/marlins/input.php.
offensive_stats does nothing
Whats the code to get it to relay output?
Posted: Tue Dec 05, 2006 3:50 pm
by a94060
a good idea would be to break the mysql_query and the actual query into diffrent variables. for example:
$sql = QUERY;
$query = mysql_query($sql);
Therefore you can use echo $sql to see if that is the info you want entered into the database.
Posted: Tue Dec 05, 2006 9:23 pm
by 4Boredom
This posts.... ($sql)Stat Added!
So is it doin anything? Shouldnt it say stat added twice?
Code: Select all
$sql = ("UPDATE `offensive_stats` SET G='{$G}',AB='{$AB}',Runs='{$Runs}',Hits = '{$Hits}',2B = '{$B2}',3B = '{$B3}',HR = '{$HR}',RBI = '{$RBI}',BB = '{$BB}',SO = '{$SO}',CS = '{$CS}',HBP = '{$HBP}',SAC = '{$SAC}' WHERE Name = '{$Name}'");
$query = mysql_query($sql);
echo '($sql)';
if(!$sql){
$error.= 'There has been an error posting your comment. Please contact the webmaster.';
} else {
echo 'Stat Added!';
}
Posted: Tue Dec 05, 2006 9:37 pm
by 4Boredom
I tried simplifying the top part of code... same feedback on output page...and no post in db
Code: Select all
$sql = ("UPDATE `offensive_stats`
(`G`, `AB`, `Runs`, `Hits`, `2B`, `3B`, `HR`, `RBI`, `BB`, `SO`, `CS`, `HBP`, `SAC`) VALUES
(`$G`, `$AB`, `$Runs`, `$Hits`, `$2B`, `$3B`, `$HR`, `$RBI`, `$BB`, `$SO`, `$CS`, `$HBP`, `$SAC`) WHERE Name = '($Name)'");
$query = mysql_query($sql);
echo '($sql)';
Posted: Tue Dec 05, 2006 10:28 pm
by volka
There's no need for parentheses arround string literals $a=("xyz"); -> $a="xyz"; It doesn't harm but it's just mambo jambo that clouds the important things.
There's no need for curly braces in double-quoted strings when you have plain/scalar variables and no speacial signs around it "... '{$xyz}' ..." -> "... $xyz ...". imho too many magic/control characters make code less readable and I'd leave them out in this case (in case of doubt put them in).
Variable substitution does not take place in single-quoted strings, echo '($sql)' will print
($sql), use double-quotes instead.
You don't want to check if there's still something in the string variable, you want to check the return value of mysql_query, if(!$sql) -> if(!$query)
=>
Code: Select all
$sql = "UPDATE `offensive_stats` SET G='$G',AB='$AB',Runs='$Runs',Hits = '$Hits',2B = '$B2',3B = '$B3',HR = '$HR',RBI = '$RBI',BB = '$BB',SO = '$SO',CS = '$CS',HBP = '$HBP',SAC = '$SAC' WHERE Name = '$Name'";
$query = mysql_query($sql);
echo "($sql)";
if(!$query)
$error.= 'There has been an error posting your comment. Please contact the webmaster.';
else
echo 'Stat Added!';
but try
Code: Select all
$sql = "UPDATE
`offensive_stats`
SET
G='$G', AB='$AB', Runs='$Runs', Hits='$Hits',
2B='$B2', 3B='$B3', HR='$HR', RBI='$RBI',
BB='$BB', SO='$SO', CS='$CS', HBP='$HBP',
SAC='$SAC'
WHERE
Name='$Name'";
echo '<div>Debug: ', htmlentities($sql), "</div>\n";;
$query = mysql_query($sql) or die(mysql_error());
I hope you already did