Get notified by email when people fill my form - php

Okey so basically I have a form so if people are interested in getting a website of me so they can fill it out and it was sent directly to my database via a php script. My question is can I do something so that I also get the message with all the information on my email? You can check out my currently script down below.
<?php
define('DB_NAME', 'database');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'server');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link){
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected){
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$value = $_POST['ID'];
$value2 = $_POST['name'];
$value3 = $_POST['email'];
$value4 = $_POST['message'];
$sql = "INSERT INTO table (ID, name, email, message) VALUES ('$value', '$value2', '$value3', '$value4')";
if (!mysql_query($sql)){
die('Something went wrong: ' . mysql_error());
}
header("Location: http://example.com");
mysql_close();
?>

Related

mysql api submite towice

I tried many times to submit the form when it submitted it repeated the submission twice on the data. I don't understand why,please help me. and when I put the header location it doesn't work ever
here is the code
<?php
$name= $_POST['form_name'];
$mrn= $_POST['form_mrn'];
$mobile= $_POST['form_mobile'];
$link = mysql_connect('server', 'user', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('dbname');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
mysql_set_charset('utf8',$link);
$query = "INSERT INTO pharmacy ( name , mrn , mobile ) VALUES ('$name', '$mrn', '$mobile')";
$result = mysql_query($query);
header('Location: form.html');
$link->close();
?>
<?php
$name= $_POST['form_name'];
$mrn= $_POST['form_mrn'];
$mobile= $_POST['form_mobile'];
$link = mysql_connect('server', 'user', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('dbname');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
mysql_set_charset('utf8',$link);
//Just Put this code before inserting
if($name !=""){
$query = "INSERT INTO pharmacy ( name , mrn , mobile ) VALUES ('$name','$mrn', '$mobile')";
$result = mysql_query($query);
header('Location: form.html');
}
$link->close();
?>
Just check condition before insert. Let me know if facing same issue.

I want to make my password to contain lowercase, uppercase, 8 characters and a character

I want to make my password to contain lowercase, uppercase, 8 characters and a character.
Here is my code:
<?php
define('DB_NAME', 'baza');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Your account has been created succesfully! Click here to login.';
$value = $_POST['name'];
$value2 = $_POST['surename'];
$value3 = $_POST['genre'];
$value4 = $_POST['numrikarteles'];
$value5 = $_POST['email'];
$value6 = $_POST['username'];
$value7 = $_POST['password'];
if (!preg_match('/[^A-Za-z0-9]+/', $value7) || strlen($value7) < 8) {
echo "Invalid password!";
} //- kushti per ta kontrollu passwordin
$sql = "INSERT INTO user (name, surename, genre, numrikarteles, email, username,password) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close();
?>
If you want to restrict user to enter minimum 8 character password which will contain upper and lower case letter and one special character you can use regular expression like
^((?=(?:.*[a-zA-Z]){7})(?=(?:.*[##$%^?])).{8})$

PHP Error: No database selected (Hostgator.com)

I have a problem with inserting data to MySQL with PHP.
When I run this code on my Hostgator hosting I get error like this:
No database selected
Here is my code:
$dbh= mysql_connect("localhost", $username, $password);
// or die ('I cannot connect to the database because: ' . mysql_error());
if(!$dbh)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("contafe_tipster", $dbh);
//$conn = mysqli_connect($servername, $username, $password, $dbname);
//Check connection
/*
if (!$conn) {
// Connection failed return 0
//die("Connection failed " . mysqli_connect_error());
echo "1";
}
*/
//Posted parameters
$pName = $_POST['name'];
$pCountry = $_POST['country'];
$pCity = $_POST['city'];
$pLocationX = $_POST['locationX'];
$pLocationY = $_POST['locationY'];
$pDescription = $_POST['description'];
$pMobileNumber = $_POST['mobile'];
$pOtherNumber = $_POST['phone'];
$pOpens = $_POST['opens'];
$pCloses = $_POST['closes'];
$add_DB = "INSERT INTO Places (Id, Name, Country, City, LocationX, LocationY, Description, Mobile, Phone, Opens, Closes)
VALUES(NULL, '$pName', '$pCountry', '$pCity', '$pLocationX', '$pLocationY', '$pDescription', '$pMobileNumber', '$pOtherNumber', '$pOpens', '$pCloses')";
if (mysql_query($add_DB, $dbh)) {
//if success return 1
echo "0";
}
else {
//if error return -1
//echo "2";
die('Error: ' . mysql_error());
}
mysql_close($dbh);
Are you sure that db name is correct?
Try this way of connection with db:
mysql_connect ($dbhost,$dblogin,$dbpass) or die ("Can't connect to database");
mysql_select_db($db) or die ('Wrong databse!');

INSERT statement not working mysql

When I process this data, the data is not being inserted into my database. This is my current database structure:
https://drive.google.com/file/d/0BzJ9StkJe55WaG1oaVhqcUJmSGc/edit?usp=sharing
I have no clue why it is not inserting. I am not getting an error message and I am seeing the successfully inserted data piece.
<head><title>Process Punch</title></head>
<?php
define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'host');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link){
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}else{
$userid_value = $_POST['userid'];
$punchtype_value = $_POST['punchtype'];
$group_value = $_POST['group'];
$dept_value = $_POST['dept'];
$notes_value = $_POST['notes'];
$table = "tc_".$userid_value;
$date_value = date("Y-m-d h:i:s");
echo $table;
$sql = "INSERT INTO $table (punchtype, groupname, dept, notes) VALUES ('$punchtype_value', '$group_value', '$dept_value', '$notes_value')";
echo "Successfully inserted data";
}
?>
Execute the query with mysql_query(), concatenate the query
$sql = "INSERT INTO `".$table."` (`punchtype`, `groupname`, `dept`, `notes`) VALUES ('".$punchtype_value."', '".$group_value."', '".$dept_value."', '".$notes_value."')";
$qry = mysql_query($sql ,$link);
echo "Successfully inserted data";

Connect to go daddy hosted Database using php connection

i keep getting a 500 internal server error when trying to submit my form. The Database is hosted in godaddy.com. I think i have hostname wrong. here is my code.
<?php
define('DB_NAME','Survey');
define('DB_USER','BC');
define('DB_PASSWORD','*********');
define('DB_HOST','50.62.209.72.secureserver.net');
$link = mysql_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD');
if(!$link) {
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected){
die('Can\'t use '. DB_name . ':' .mysql_error());
}
/*echo 'Connected Successfully';*/
$value = $_POST['last'];
$value2 = $_POST['first'];
$value3 = $_POST['phone'];
$value4 = $_POST['email'];
$value5 = $_POST['fax'];
$value6 = $_POST['company'];
$sql = "INSERT INTO crofton (last, first, Phone, Email, Fax, Company) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6')";
if (!mysql_query($sql)) {
die('Error: '. mysql_error());
}
mysql_close();
?>
yes your host name is wrong, Read Viewing Your Database's Details to know more about godaddy Database Details

Categories