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");
Related
I have created the webpage frontend design for a login page and saved it as .php file.
I have even installed wampserver.
Give me some idea how to connect a mysql database wampserver and my login page.
Is it possible to use the database option given in wampserver inside the tools?
If it is possible, how we can connect to the login page? Please give some idea...
It is possible to create the database in wampserver in Phpmyadmin and can create the tables also.
The following is the code to connect to database
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("database1",$dbhandle) // "database1" is the database name
or die("Could not select database1");
//execute the SQL query and return records .. insert ur login info also
$result = mysql_query("SELECT uid FROM login"); // "login" is table
if(mysql_num_rows($result) != 0){
$result1 = INSERT INTO login (id, name, password) VALUES
('".$_POST['id']."','".$_POST['name']."','".$_POST['password']."'); // The values which
//you entered in the login form
} else {
echo "This login name already exists";
}
?>
This is the simple way to connect the database and insert the data into tables. But
dont forget to create database and tables in phpmyadmin before inserting the data
Basically, i'm having trouble connecting to a mysql database using a php web page.
I created the database in C-panel using the wizard
i'm connecting like this
$db_host = "localhost"; //your host Database address
$db_username = "xxxx"; //your account username
$db_pass = "xxxxx"; //your account password
$db_name = "xxxxx"; //your database name
#mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
#mysql_select_db("$db_name") or die ("no database");
But all my page seems to do is trigger the " could not connect to mysql"
my page does have wordpress installed at the minute but I'm planning to get rid of it as I'm creating my site myself. I'm just baffled why it can't connect, because in Phpmyadmin ( a feature on C-panel) it says the database is in localhost.
In C-panel you need to add database user and assign certain roles to it before you can connect to the database.
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");
I am EXTREMELY new to the html/php scene but I have been working at this for hours. I am stumped.
I am trying to connect to a sql database that will store username and password information. I use fortune city for hosting and I have already used their phpAdmin to setup up all of the necessary stuff (db, tables, etc..).
I am using Eclipse with Zend on the side. I am also running Sql Server and Apache 2.2.
I believe my issue is the following:
I have a db located at a certain ip address (remote fortunecity server) and I am testing my project on the local server. Fortune city offers two different host names, one for internal connections and one for external connections. I get different results from each one:
If I connect to the internal site it doesn't make any connection, I know this because of my die statement. If I connect to the external host it connects, but doesn't allow me to connect to the database. (see cases below code)
Currently my process is as follows. (PLEASSSSE TELL ME A BETTER WAY IF I'M DOING THINGS THE INEFFICIENTLY, I feel dirty every time I do it!!)
Create or edit my index.php, login.php, etc... in eclipse.
Copy the files that I edit into my Apache root.
Go back to eclipse and run the project in a browser "firefox."
repeat n to the n times.
Keep in mind my sql database is located on the net
Can this be done? Testing locally while accessing a db on the net?
Here is the code:
<?php
if (!isset($_POST['username']) || !isset($_POST['password'])) {
header( "Location: http://localhost/index.php" );
}
elseif (empty($_POST['username']) || empty($_POST['password'])) {
header( "Location: http://localhost/index.php" );
}
else{
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$dbHost = "mysql3341.dotsterhost.com";
$dbUser = "*********";
$dbPass = "******";
$dbDatabase = "**********";
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result=mysql_query("select * from userInfo where username='$user' AND password='$pass'", $db);
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
session_start();
session_register('username');
echo 'Success!';
header( "Location: checkLogin.php" );
}
}
else {
echo 'Incorrect login name or password. Please try again.';
}
}
?>
Again, I have never made it past
Case :1 $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
Case :2 mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
Thanks for reading my novel!
Can this be done? Testing locally while accessing a db on the net?
Yes you can, but be aware if you are storing anything sensitive in your database you probably wouldn't want to be sending that data unencrypted over the net. (Unless you are connecting over a VPN or another type of secure network connection.)
Usually you'd want to setup a development environment on your local box or you can edit your files locally in something like Aptana (http://www.aptana.com/) and have it automatically deploy your files to the server every time you save.
Also, as suggested in the comments, using a framework to develop on usually give you a powerful database library without the need to reinvent it on your own. (That is unless you feel like wrapping your own!)
I am trying to display a list of my vbulliten threads on a non-vbulliten portion of my site. However I can't select the vbulliten database:
<?php
$host = "localhost";
$user = "my username";
$pass = "my password";
$dbname = "tableprefix_forum";
mysql_connect($host, $user, $pass) or die ("Could not connect to database server.");
mysql_select_db($dbname) or die ("Could not select database.");
?>
I am substituting some things here in this example but all my credentials are correct including my db server username, password and forum db name. So what is the problem? Is it due to some internal security feature in vbulliten, does this system not allow you to connect to it's db if the page trying to connect to it is a non-vbulliten page?
Vbulletin has NO control over the permissions given by the server. But you do need to make sure that the user/pass you are using has been granted permission to access the database you are requesting.