Webmatrix showing blank page - php

I am new to php! And i have to create a site. So i wrote the code in HTML, downloaded webmatrix, created a MySql database and inserted the code for DB connection in the php file. But when i run the php page, it shows a blank page. It works fine if I remove the code for database connection.
Here is my connection code:
<?php
$conn=mysqli_connect(localhost;rjitdbUy5k1;******;rjitdb);
if(!$conn)
{
die('Could not connect:'.mysql_error());
}
echo
'Connected successfully';mysql_close($conn);
?>
The Request log displays an error:

Got the answer!
I missed out the
mysql_select_db(DBNAME)
string.

Related

Why is my PHP short-code printing text instead of performing function when trying to connect to MYSQL database on Wordpress?

I'm trying to display a table from my MYSQL database on a website I'm creating on Wordpress. I'm using the code shown in the code block. This code is within a PHP short-code snippet and added to a Wordpress widget. Once I get past the ">" of <your-MySQL-database-password>, the short-code seems to screw up, and starts to print the text of the code as opposed to actually making the connection. The text that prints is:
, ,'', 'Connect'); if (!$conn){ echo 'Connection error:
mysqli_connect_error(;}?>
When I delete the ">" at the end of <your-MySQL-database-password> all of the printed text disappears except for the `, , at the very beginning.
<?php
$conn = mysqli_connect(
<location-of-your-database>,
<your-MySQL-database-username>,
'<your-MySQL-database-password>',
'Connect');
if(!$conn){
echo 'Connection error: ' . mysqli_connect_error();
}
?>
I suspect if I had a better fundamental knowledge of PHP I could figure this one out pretty easily.
Writing the text into the short-code and skipping the snippet
Creating the snippet and entering the snippet identifier into the short-code block (same result as 1.)
Deleting characters to see what's effecting the rest of the code.
Looked up to see what issues people have with snippets/shortcode on Wordpress
This might helps
<?php
$con = mysqli_connect("localhost","your-db_username","your-db_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>

frequent lost of connection to mySQL server

I instal wamp server locally on my PC.I create a user registration form using php and mySQL database for pratice.I was able to connect to my mySQl data server and if i input data on the form and submit is work successfully.I normal experience at time when i access the user registration form it lost connection to my SQLdata server even though my wamp server is on.I will troubleshoot by changing some of the parameter by using mysqli_connect() to check if i will be prompted unsuccessful connection still nothing will show.When i check some other time it will work successfully.Please what may be causing this issue?
Run wampserver as administrator by right clicking wampserver.exe file. It may help.
Edit:
With the type of english you are using to produce the problem and giving no code is making it difficult to predict what the problem actually is. But I think there is something wrong with your mysqli connection file.
Add this code bit to the top of your registration.php file like this:
<?php
$connection = mysqli_connect('localhost','root','');
if(!$connection) {
die("Failed to connect" . mysqli_error($connection));
}
else {
echo "Connection Established";
}
$select_db = mysqli_select_db($connection, 'db2');
if(!$select_db) {
die("Database selection failed" . mysqli_error($connection));
}
else {
echo "Database selected";
}
?>
<?php
////rest of ur registration code goes here

php require_once ("database connection file") is not working when running a query from an other include_once file

on my main page I have my
//connection to database
require_once('inc/conn_db.in');
I also have a file that
// Device Search::
require_once('inc/ProductSearch.php');
queries made from the main page work fine.
The problem lies when I run queries from the second require_once file ('inc/ProductSearch.php')
I could be completely wrong but I would think that the database connection is open, and that I should be able to query while the main page is open.
the only way I am able to run the query is when I include the require_once('inc/conn_db.in');
in the second file.
Is this a normal behavior or am I doing something wrong
content of the conn_db.in::::
############################################################
// Create Script to Connection to the Database
$conn = mysql_connect("localhost", "$$$$$", "$$$$$$");
// Check if the connection to the database Server can be created
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
// Check if it can find the Database on the Database Server
if (!mysql_select_db("$$$$$$")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
#
any help or directions are appreciated

How to connect to remote database on Wordpress

Probably been covered but I keep getting "connecting to the Wordpress database" which isn't what I'm after. In a nutshell I have a perfectly fine Wordpress site, I also have a MySQL database on another server which has some data I'm after. The code works fine on phpfiddle (is this the standard?) but whenever I try to use it on the Wordpress site, either with shortcodes or in the header.php it keeps hanging, throwing errors and won't connect to the DB, any ideas why?
Edit: To make things clearer, it's a meteorological database I want to connect to in order to pull things like Temperature from. Nothing native or related to Wordpress.
<?php
// Create connection
$con=mysqli_connect("ip","user","pass","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($con);
?>
Gives me this
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on...
You should probably be looking at the WordPress WPDB class - https://codex.wordpress.org/Class_Reference/wpdb
For example:
<?php
$wpdb_dbconnect = new wpdb(user, pass, db_name, localhost);
$wpdb_dbconnect->show_errors();
$object = $wpdb_dbconnect->get_results("SELECT * FROM table_name");
foreach ($object as $person) {
echo $person->name . ', ';
}
?>
To connect to a second (and third, and forth...) database, I recommend HyperDB plugin.

Could anyone with MySQLi experience help me with this short SELECT code?

I have researched my question but there just isn't much help out there for MySQLI functions. I'm also new here so, please bear with me.
I have a test database named "website" and it contains a table called "users" which has data for all of the members of my website. In a separate file I have the php code that connects to my localhost and selects the database "website." I'm using the newest functions of MySQL so instead of the connection string containing mysql_connect it contains mysqli_connect. The registration process works great and I can find no error in any of the other code that uses the mysqli functions.
My include file (connect.php)
<?php
$link = mysqli_connect("localhost", "useracc", "useracc1", "website");
?>
I set up a test script for the login section.
<?php
include('connect.php');
$user = $_POST['user'];
$query = "SELECT birthday FROM users";
$result = mysqli_query($link, $query) or die ("RESULT ERROR");
echo "$user";
echo "$result";
?>
There is a password box on the previous page but for the test script I left that out and so far, only the $user is shown on the page. I get no error even when I replace "RESULT ERROR" with mysqli_error($link). I've tried interchanging ' for " in every part of the code that uses quotes but that didn't work. I've tried rewording the $query line but that also had no effect. I'm really new to MySQL and php so if you guys could tell me where I'm going wrong I'd really appreciate it.
Thanks for reading my question. Have a great day.
Add the following lines to the connect.php after you connect line
if (mysqli_connect_errno()) {
printf("Can't connect Errorcode: %s\n", mysqli_connect_error());
exit;
}
this will ensure the connection is made without any errors and return them if there are ...

Categories