Error with mysql_select_db [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I use Linux Debian
Local Lamp Server
i tried to make connection between Database and php :
<?php
$tf_host = 'localhost' ;
$tf_dbname = 'tinyforum' ;
$tf_username = 'root';
$tf_password = '' ;
$tf_handle = mysql_connect($tf_host , $tf_username , $tf_password);
if (!$tf_handle)
die('connection problem ..');
$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)
{
mysql_close($tf_handle);
die('selection problem');
}
die('OK');
mysql_close($tf_handle);
?>
The result :
http://www.foxpic.com/V0HrSdgb.png
pic of phpmyadmin:
http://www.foxpic.com/V0AlRhi6.png
the place where i save the php file :
/var/www/html/

Unless you copied your code incorrectly, your check is not going to result in what you want.
$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)
your selection seems fine so either you should change your code to
if(!$tf_db_result) //note the !
or restructure your code
if($tf_db_result) {
//Do the stuff you want to do when you are connected
} else {
//Die connection
}

Related

can't connect to sql database in godaddy server [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I created a connect.php file in my website that I've hosted in godaddy, but when I include this file in my index.php page. All the content in the page went blank.
this is my connect.php file code
<?php
$host = 166.62.10.223;
$con = mysqli_connect("host","root","");
if(mysqli_connect_errno())
{
echo "error".mysqli_connect_errno();
}
?>
I really need some help
Change your code from
$host = 166.62.10.223;
$con = mysqli_connect("host","root","");
To
$host = 166.62.10.223;
$con = mysqli_connect($host,"root","");
And You need a password too if you are working on live server and username might not be root So replace them by actual values.
Example
$user = "liveserver_username"; //which is created in godaddy mysql wizard section
$password = "liverserver_password"; //which is created in godaddy mysql wizard section
$host = 166.62.10.223;
$con = mysqli_connect($host,"$user","$password");
more information on how to create DB,User and password.

site visit counter gives no output [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a website which logs the ip,time and date of every visit. I am trying to write a function that displays how many times a certain ip address has accessed the site. It will say something like you have visited this site .... times.
Here is the php:
<?php
function visitor_counter()
{
require_once 'php_scripts/log_in_script_2.php';
$conn = new mysqli($hn,$un,$pw,$db);
if ($conn->connect_error) die($conn->connect_error);
$ip_var = $_SERVER['REMOTE_ADDR'];
$query = "SELECT COUNT(ip) FROM visitors WHERE ip = '$ip_var'";
$result = $conn1->query($query);
if (!$result) die ($conn->error);
echo $result;
mysqli_close();
}
?>
it is included in the webpage with
<?php require_once "php_scripts/visit_counter.php"; ?>
and the function is called in the code with
You have visited my site: <?php visitor_counter(); ?> times.
It does not output anything, and the rest of the webpage doesn't load after this line. I know the query is correct, I've tested it in phpmyadmin, and I know the login for the function has the correct privilages. Any ideas?
I added the changes from the comments above, but a problem was still there. The problem was that I was trying to echo the query result directly. I changed the query to $query = "select count(ip) as total_visits from visitors where ip = '$ip_var'"; and changed the echo to echo $result->fetch_object()->total_visits;, and it works.

IBM Bluemix PostgreSQL and psql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I've created a PHP runtime enviroment in Bluemix and attached a postgresql server to it.
When trying to use psql from terminal, it doesn't seem to can reach the database?
Also, adding ./bp-config/options.json and:
{
"PHP_EXTENSIONS": ["mysqli"]
}
I'm not able to conncet via mysqli from my php scripts.
The extension mysqli for PHP is useful to connect to a MySQL database server.
As you described you bound to your application a PostgreSQL database, so this extension is completely useless.
To connect to a PostgreSQL you could use composer dependency manager (supported on Bluemix) with you PHP application and set your composer.json with the dependency. You can obviously add other dependencies to your composer.json.
"require": {
"ext-pgsql": "*"
}
Then you could connect to your PostgreSQL service using a code like the following one in order to get service credentials from VCAP_SERVICES variables available from CloudFoundry
if (getenv("VCAP_SERVICES")===false) {
$db = 'XXXX';
define("APP_DB_SCHEMA", $db);
define("APP_DB_HOST", 'xxxx');
define("APP_DB_PORT", "xxxx");
define("APP_DB_USERNAME", 'xxxx');
define("APP_DB_PASSWORD", "xxxx");
} else {
// getting VCAP configuration
$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services, true);
$pgsql_config = $services_json["postgresql-9.1"][0]["credentials"];
define("APP_DB_SCHEMA", $pgsql_config["name"]);
define("APP_DB_HOST", $pgsql_config["host"]);
define("APP_DB_PORT", $pgsql_config["port"]);
define("APP_DB_USERNAME", $pgsql_config["user"]);
define("APP_DB_PASSWORD", $pgsql_config["password"]);
}
and then establish the DB connection through:
$dbConnectionString = "host=" . APP_DB_HOST . " port=" . APP_DB_PORT . " dbname=" . APP_DB_SCHEMA . " user=" . APP_DB_USERNAME . " password=" . APP_DB_PASSWORD;
$dbConnection = pg_connect($dbConnectionString);

PHP Resend Verification Email [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to add a resend verification action to my login/register system using tampus login system. I am following this tutorial.
Okay I am not a fan of php frameworks so I will make this one for you with MySQL:
if(empty($_POST["user"]) || empty($_POST["pass"])){
echo "Missing values";
} else {
//You would need the mysql connection variable named $db_conn
$db_conn = mysqli_connect("localhost","user","pass","db_name");
$user = $_POST["user"];
$pass = md5($_POST["pass"]);//MD5 encrypt;
$sql = "SELECT id FROM users WHERE username='$user' AND password='$pass'"
$query = mysqli_query($db_conn,$sql);
if(mysql_num_rows($query) > 1){
//Do the login thingys like cookies and redirects
} else {
echo "Check your credentials";
}
}
I think I could not made it easier and better to understand

PDO: make $dbh available and maintain across all php files [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
seem that I can't make it right.
Basically, three PHP files are used: - login.php, testconnect.php and numrows.php
numrows.php is the main file that first start played.
login.php and testconnect.php are good.
numrows.php:-
<?php
global $dbh1;
require_once "testconnect.php";
try
{
$stmt = $dbh1->prepare("select count(distinct mfg_code) from test");
$stmt->execute();
}
catch(PDOException $err)
{
$alertmsg = $err->getMessage();
}
$num = $stmt->fetch("PDO::FETCH_ASSOC:");
$num = json_encode($num);
echo $num;
?>
The log error from apache showed ""GET /testnumcards.php HTTP/1.1" 500 -". Again the error I encountered while debugging is "NetworkError: 500 Internal Server Error".
What is the right way to do?
Your problem not in making $dbh available but in inconsistent code and wrong syntax.
At least make your file this way, without all the useless and wrong code
<?php
require_once "testconnect.php";
$stmt = $dbh1->prepare("select count(distinct mfg_code) from test");
$stmt->execute();
$num = $stmt->fetch(PDO::FETCH_ASSOC); // note the proper syntax
$num = json_encode($num);
echo $num;
then look into error_log for the details

Categories