I have a simple application that I would like to read data from mysql. My index page include simple form to send data to server to process , especially to match data against database.
<form action="page.php" method="post">
</form>
In the page.php, I do the following
define('DATABASE','Users');
define('TABLE','poll');
define('HOST','localhost');
define('USER','root')
define('PASSWORD','');
$conn=mysql_connect(HOST,USER,PASSWORD) or die("Unable to connect to specified DB");
mysql_select_db(DATABASE); etc
But when I submit the form, I receive the 500.0 error message that claims the unmatched ISAPI setup module. I am thinking webmatrix offer all configuration by default, do you have any idea of how to fix this ? Please help.
$conn = mysql_connect("localhost", "username", "password");
if(!$conn)
{
die('Could not connect '.mysql_error());
}
mysql_select_db("dbname");
Related
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
Beginner question here. I am learning php and mysql. I have a website that I created using a local server. The database was linked to it fine on MAMP. I am now trying to upload it to a shared server using iPage. It will not connect.
Here is my code
<?php
$connect = mysqli_connect('host','user','password','db_name');
if (!$connect) {echo 'Could not connect';} ?>
I know the user, the password and the database name are correct. My only doubt is regarding the host. My website is in a subdomain. Should my code be:
<?php
$connect = mysqli_connect('subdomainName.domainName','user','password','db_name');
if (!$connect) {echo 'Could not connect';} ?>
or
<?php
$connect = mysqli_connect('domainName','user','password','db_name');
if (!$connect) {echo 'Could not connect';} ?>
or even
<?php
$connect = mysqli_connect('localhost','user','password','db_name');
if (!$connect) {echo 'Could not connect';} ?>
Do I need to do anything in my hosting page to link the database in any way. I have tried all options and nothing works. Thanks
Before implementing code you have to make new database in your website server,for this you have to log in to cpanel and make db in it, use that details and try the third one and use mysqli_connect_error() for getting the error details. like below.
Note: Better to use double quotes here because of string.
// Create connection
$conn = mysqli_connect("localhost", "username", "password");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if you are getting Connection failed: no such file or directory. then refer another question PHP - MySQL connection not working: 2002 No such file or directory
Better to contact your hosting provider if you are in shared hosting.
I want to create a login system of my website,so I read this page
http://www.codingcage.com/2015/01/user-registration-and-login-script-using-php-mysql.html
and also I create a MySql database
and I got this message:"oops database selection problem ! -->
Access denied for user 'a9891486_UsersID'#'10.1.1.31' to database 'dbtest'"
and I know it is some thing wrong in my dbconnect.php
dbconnect.php code:
<?
if(!mysql_connect("mysql9.000webhost.com","Username","Password","dbtest"))
}
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("dbtest"))
}
die('oops database selection problem ! --> '.mysql_error());
}
?>
and I know what is "Username" and "Password"
THANK A LOT!!!!!!!!!!!!!!!!!!!
Try this:
<?
$conn = mysql_connect("mysql9.000webhost.com", "username", "password") or die(mysql_error());
//to select the targeted database
mysql_select_db("dbtest", $conn) or die(mysql_error());
?>
Just a couple of points about the code
mysql_connect accepts only 3 parameters the dbname goes in the mysql_select_db()
your if statements have incorrect bracketting
its always safer to use <?php rather than <?
Suggested code changes
<?php
if(!mysql_connect("mysql9.000webhost.com", "Username", "Password"))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("dbtest"))
{
die('oops database selection problem ! --> '.mysql_error());
}
?>
But again I have to say
Please dont use the mysql_ database extensions, it is deprecated (gone for ever in PHP7)
Especially if you are just learning PHP, spend your energies learning the PDO or mysqli_ database extensions,
and here is some help to decide which to use
I am aware this is a stupid question, but to connect to a database that is on my local server, do i connect via this code:
mysql_connect("localhost","user","pass")
so using localhost connection. This seems to make sense, as it is sending a message to the host computer to connect to it's local database.
or do i use this piece of code:
mysql_connect("Ipaddress","user","pass")
This also makes sense to me somehow. Which one do i use for my website which i am hosting at home.
EDIT: obviously I want it so that people from all over the world enter information, and it is sent to a database. It isn't meant to be used by me.
A better way to do this is:
<?php
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
};
?>
This is what I personally use, there are other ways to do this.
You should use localhost:
You could something like this:
<?php
$mysql = mysql_connect("localhost", "user", "pass");
if(!mysql){
die('Could not connect: ' . mysql_error());
}
//code her
mysql_close(mysql) //stops the connection
?>
Your database will most likely be stored on the same server as your program, you should put localhost.
Anyway, take some time to learn about PDO. It's more secure, cleaner and actually easier to use.
I got to design a login and sign up form using yahoo webhosting.
I have designed the login page and the sign up page using html, but I have to write a .php module to save the entered fields in the "my database" table with table name "login".
I have created the "login" table with the fields in the signup form. But I am not able to connect to the data base thorugh phpMyAdmin. I have written the following code in .php file
<? php
$db_host = "localhost";
$db_username = "user123";
$db_pass = "password123";
$db_name = "my database";
#mysql_connect("db_host","$db_username","$db_pass") or die ("could not connect to my database");
#mysql_select_db("$db_name") or die("no database");
echo "Successful Connection";
?>
But I am getting 500 - Internal Server Error. Why?
I have to establish a connection and update the values entered in signup form by writing the php code for it.
You are using variables as parameters for your MySQL functions, and so you don't need (infact you shouldn't) double quotes there!
Change
#mysql_connect("db_host","$db_username","$db_pass") or die ("could not connect to my database");
#mysql_select_db("$db_name") or die("no database");
to
mysql_connect($db_host,$db_username,$db_pass) or die ("could not connect to my database");
mysql_select_db($db_name) or die("no database");