please guys i need your help , i have got a database with the name of a2354076_db and i have created the table caller users with this code :

CREATE TABLE users
(
P_Id int,
username varchar(255),
pass varchar(255),
email varchar(255),
country varchar(255)
)

and then i wanted to conect my form to it but i did no know how to do it i have used this code :

<?php


if (isset($_REQUEST['name']))
$con = mysql_connect("$mysql_host","$mysql_user","$mysql_password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$mysql_database", $con);



INSERT INTO Persons (name, email, pass,country)
VALUES ($name, $email, $pass, $country)

echo "<form method='post' action='db.php'>
  name: <input name='email' type='text' /><br />
  password: <input name='pass' type='password' /><br />
  country:<input type="text" name="country" /><br />
  email :<input type="text" name="email" /><br />
  <input type='submit' />
  </form>";
  

$mysql_host = "mysql9.000webhost.com";
$mysql_database = "a2354076_db";
$mysql_user = "username";
$mysql_password = "*********";

$email = $_REQUEST['email'] ;
  $pass = $_REQUEST['pass'] ;
  $country = $_REQUEST['country'] ;
  $name = $_REQUEST['name'] ;
?>

but nothing is happening so please guys correct me and give me the correct full code
please give me the code , i am really tired from writing wrong php codes .

Your php code sequence is not correct.

<?php

$mysql_host = "mysql9.000webhost.com";
$mysql_database = "a2354076_db";
$mysql_user = "username";
$mysql_password = "*********";

$con = mysql_connect("$mysql_host","$mysql_user","$mysql_password");
if (!$con) {  die('Could not connect: ' . mysql_error());  }
mysql_select_db("$mysql_database", $con);


if (isset($_REQUEST['name']))
{
  $email = $_REQUEST['email'] ;
  $pass = $_REQUEST['pass'] ;
  $country = $_REQUEST['country'] ;
  $name = $_REQUEST['name'] ;
  
  $q= 'INSERT INTO users (username , pass , email ,country )VALUES ($name, $pass, $email, $country)';
  mysql_query($q);
  
  header("Location:success.php");
  exit;
}



echo "<form method='post' action='db.php'>
  name: <input name='email' type='text' /><br />
  password: <input name='pass' type='password' /><br />
  country:<input type="text" name="country" /><br />
  email :<input type="text" name="email" /><br />
  <input type='submit' />
  </form>";

?>

Check this.

Member Avatar for rajarajan2017

Sample code for database connection and communication.

<html> 
<head> 
<basefont face="Arial"> 
</head> 
<body> 

<?php 
if (!isset($_POST['submit'])) { 
?> 
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    Country: <input type="text" name="country"> 
    National animal: <input type="text" name="animal"> 
    <input type="submit" name="submit"> 
    </form> 
<?php 
} 
else { 
    $host = "localhost"; 
    $user = "root"; 
    $pass = ""; 
    $db = "testdb"; 
    $country = empty($_POST['country']) ? die ("ERROR: Enter a country") : mysql_escape_string($_POST['country']); 
    $animal = empty($_POST['animal']) ? die ("ERROR: Enter an animal") : mysql_escape_string($_POST['animal']); 

    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
    mysql_select_db($db) or die ("Unable to select database!"); 
     
    $query = "INSERT INTO symbols (country, animal) VALUES ('$country', '$animal')"; 
     
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
	     
    echo "New record inserted with ID ".mysql_insert_id(); 
     
    mysql_close($connection); 
} 
?> 

</body> 
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.