I'm developing a phonegap app and currently trying to implement a registration form for users to sign up, then add their username, email and password into MySQL phpadmin database. However, after many trials, user data didn't add into sql database and I'm not so sure where the problem is.
I have one connect.php file: `
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('test');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>
`
and another signup.php file: `
require('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST['signup-username']) && isset($_POST['signup-email']) && isset($_POST['signup-password'])){
$signup-username = $_POST['signup-username'];
$signup-email = $_POST['signup-email'];
$signup-password = $_POST['signup-password'];
$query = "INSERT INTO `signup` (Username, E-mail, Password) VALUES ('$signup-username', '$signup-email', '$signup-password')";
$result = mysql_query($query);
if($result){
$msg = "User Created Successfully.";
}
}
?>
`
I would try using the Mysql Improved extension, http://php.net/manual/en/book.mysqli.php
Related
Hello anyone who can help (or having the same issue).
I have a form on my website I need to store the data in a database.
I have no problems when using any other database service but when using an Amazon RDS Database I have no luck.
This php file is used to send the data to the database.
<?php
$dbhost = "xxxx.xxxx.ap-southeast-2.rds.amazonaws.com";
$dbuser = "username";
$dbpass = "pasword";
$userid = $_GET['UniqueID'];
$username = $_GET['name'];
$useremail = $_GET['email'];
$userphone = $_GET['phone'];
$userref = $_GET['refid'];
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "INSERT INTO landing_post (`useid`, `name`, `email`, `phone`, `refid`) VALUES ('$userid', '$username', '$useremail', '$userphone', '$userref')";
mysql_select_db('bunker');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
After the form is submitted to the original post action, it opens the below url.
https://example.com.au/test/post.php?&UniqueID=10020&name=burger&email=test%40mvmedia.com&phone=1800+000+000&refid=28383
The $_GET functions fill out the data using the variables in the url.
When running the php from a cpanel based server I get this error.
Could not connect: Can't connect to MySQL server on 'xxxxx.xxxxxxx.ap-southeast-2.rds.amazonaws.com' (111)
When running the php from a AWS EC2 instance I don't even get a error readout.
Any assistance or insight would be greatly appreciated.
Cheers,
Andy
Shout out to JeanPaul98 who put me on the right path. After trial and many errors, i found the below code solved the issue.
<?php
$userid = $_GET['UniqueID'];
$username = $_GET['name'];
$useremail = $_GET['email'];
$userphone = $_GET['phone'];
$userref = $_GET['refid'];
$link = mysqli_connect('xxxxx.xxxxxx.ap-southeast-2.rds.amazonaws.com', 'User', 'password','database');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Check if server is alive
if (mysqli_ping($link))
{
echo "Connection is ok!";
}
else
{
echo "Error: ". mysqli_error($link);
}
mysqli_query($link,"INSERT INTO table (`useid`, `name`, `email`, `phone`, `refid`) VALUES ('$userid', '$username', '$useremail', '$userphone', '$userref')")
or die(mysqli_error($link));
echo "Entered data successfully\n";
mysqli_close($link);
?>
The main change was I stopped using mysql and rather used mysqli. There are also some structural changes to make the code to work with mysqli. For others having a similar issues here are a few things to check.
You have opened a inbound port for the IP in the security group of the RDS Database.
The Database is publicly accessible.
That your php version has PDO_MYSQL installed, or compatible driver (more details here
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.rds.html)
When I was trying to make website for school project then I make a registration page so I make a html page and a php and a database.
But when I tried to enter anything in form then the result after submitting the information is blank page. When I opened php file in browser then a blank page opened. There should be either connected to the database or failed to connect to database. My coding of php file is given below:
Please help me as less time is remaining for last date of submission.
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'practice');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db = mysql_select_db(DB_NAME, $con) or die("Failed to connect to MySQL: " . mysql_error());
function NewUser()
{
$fullname = $_POST['name'];
$userName = $_POST['user'];
$email = $_POST['email'];
$password = $_POST['pass'];
$query = "INSERT INTO websiteusers(fullname,userName,email,pass) VALUES ('$fullname','$userName','$email','$password')";
$data = mysql_query($query) or die(mysql_error());
if ($data) {
echo "YOUR REGISTRATION IS COMPLETED...";
}
}
function SignUp()
{
if (!empty($_POST['user'])) //checking the 'user' name which is from Sign-Up.html, is it empty or have some text
{
$query = mysql_query("SELECT * FROM websiteusers WHERE userName='$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());
if (!$row = mysql_fetch_array($query) or die(mysql_error())) {
newuser();
} else {
echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
}
}
}
if (isset($_POST['submit'])) {
SignUp();
}
?>
MySQL is depreciated. Use MySQli instead
Connect to your database this way
$connect = mysqli_query(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
then check this way
if($connect){
echo "Connected";
}else{
echo "Not connected";
}
and any query you run should be in this format
$query = mysqli_query($connect,$Sql);
I tried many source codes from google but I am unsuccessful everytime. Everytime I clicked on submit button it shows a blank page. Please provide me help I want to create a signup page and in this I want to connect html coding to mysql database I have knowledge about html. So please provide an easy way to interconnect the database and html.
I also came to know about the php so I tried to copy source code from google but everytime I failed as php preview in browser is blank page.
I have been trying to connect my hosted sql database with mitinventor2 in a registeration form and I am getting an error that says something about
URL. error 1109
This is my php code :
<?php
DEFINE ('DBUSER', '******');
DEFINE ('DBPW', '*****');
DEFINE ('DBHOST', 's******');
DEFINE ('DBNAME', '*******');
$dbc = mysqli_connect(DBHOST,DBUSER,DBPW);
if (!$dbc) {
die("Database connection failed: " . mysqli_error($dbc));
exit();
}
$dbs = mysqli_select_db($dbc, DBNAME);
if (!$dbs) {
die("Database selection failed: " . mysqli_error($dbc));
exit();
}
$clientusername = mysqli_real_escape_string($dbc, $_GET['clientusername']);
$clientemail = mysqli_real_escape_string($dbc,$_GET['clientemail']);
$clientpno = mysqli_real_escape_string($dbc,$_GET['clientpno']);
$clientpass = mysqli_real_escape_string($dbc,$_GET['clientpass']);
$query = "INSERT INTO ssudb(clientusername, clientemail, clientpno, clientpass) VALUES ('$clientusername', '$clientemail', '$clientpno', '$clientpass')";
$result = mysqli_query($dbc, $query) or trigger_error("Query MySQL Error: " . mysqli_error($dbc));
mysqli_close($dbc);
?>
I am sure about the database info yet I hide them for security reasons. My database is well structured with phpmyadmin.
The link to the php file is right with no errors, and here is my mit inventor block:
I hope I didn't validate any rule.
Thanks in advance!
note:
when open phpmyadmin somtimes i see the table is having new attributes with no values in it but the increment ID.
$clientlocation is missing in the VALUES
I'm trying to make a registration form that validates the account by sending a validation code to the email. Once the user receive the code in his email he must click the link to validate his account(I simulated this using the localhost). BTW, I have 2 database for the registered members and for the temporary members(these are the members that are waiting for validation).
When the validation code is processed and matched, the data from the temporary table will be copied to the registered members table, after the copying is done the user data from temporary table will deleted.
when I checked my updated database(registered members table) the ID column had incremented but the username, password and email field has no data. what is the problem here?
here is the website I'm following for the tutorial but I did some little tweaks
http://phpeasystep.com/phptu/24.html
localhost/validated_email.php?passkey=639900974e5fc25626af1a6ce5da8b01
<html>
<body>
<?php
ob_start();
//define a function for temporary database (temporary_members)
function temporary_members_db(){
$host="localhost";
$db_username="root";
$db_password="";
$db="forum_members";
$db_table="temporary_members";
//=======================connect to database
mysql_connect("$host","$db_username","$db_password") or die("Could not connect to the database!");
mysql_select_db("$db") or die("database not found!");
}
function members_db() {
$host="localhost";
$db_username="root";
$db_password="";
$db="forum_members";
$db_table="members";
//=======================connect to database
mysql_connect("$host","$db_username","$db_password") or die("Could not connect to the database!");
mysql_select_db("$db") or die("database not found!");
}
//connect to the temporary_member table
temporary_members_db();
$code = $_GET['passkey'];
//execute mysql query to check the validation code
$check_code = "SELECT `validation_code` FROM `temporary_members`";
$execute_code = mysql_query($check_code);
$result_code = mysql_num_rows($execute_code);
if ($result_code==1) {
$rows=mysql_fetch_array($execute_code);
$username = $rows['username'];
$password = $rows['password'];
$email = $rows['email'];
$table_members = "members";
members_db();
$copy_values = "INSERT INTO $table_members(username, password, email) VALUES ('$username', '$password', '$email')";
$execute_copy = mysql_query($copy_values);
}
else {
echo "Wrong validation code";
}
if ($execute_copy) {
echo "Your account has been activated!";
//delete data from the temporary_members
$table_temporary_members = "temporary_members";
$delete_data = "DELETE FROM $table_temporary_members WHERE validation_code = '$code'";
$execute_delete = mysql_query($delete_data);
}
ob_end_flush();
?>
</body>
</html>
I'm trying to connect to a mysql database with php and myadmin. I've tried a lot of codes I could find online, but I just can't put this thing to work...
Can anyone please tell me what I might be doing wrong?
this is the php script I am using:
<?php
$useremail = $_POST["useremail"];
$password = $_POST["password"];
if($useremail && $password){
// open database
$connect = mysql_connect("localhost", "carlos", "nenem");
if(!$connect){
die ("Not able to connected to the database: " .mysql_error());
}
// select database
$select_db = mysql_select_db("vergilioDB", $connect);
if(!$connect_db){
die("Not able to connect to the database: " .mysql_error());
}
mysql_close($connect);
} else {
die("Please enter useremail and password, or REGISTER if you are a new user!");
}
?>
Carefull, $select_db != $connect_db
The variable names are different, rewrite to:
$select_db = mysql_select_db("vergilioDB", $connect);
if(!$select_db){
die("Not able to connect to the database: " .mysql_error());
}
note that you are closing your MySQL connection regardless of anything else before you ever use it for anything..
mysql_close($connect);
You likely want to separate your connection logic from your login logic. You likely need the DB connection to validate the password no matter what and your DB connection should be the first thing you do to make sure you can even DO anything with a given page...