Jump to content

Recommended Posts

Hi,

 

I am writing a PHP code in which i am inserting a row in a table from users input. I am using the following code. Code runs successful and it prints the line 'Account Created', but nothing happens to the table. Records dont add there. When i write the same MYSQL code from phpmyAdmin, it runs successful and add the records on table. Kindly tell me the issue in the following code.

 

Thanks,

Taha

 

<?php

if(isset($_POST['name']) && isset($_POST['password']) && isset($_POST['email_address'])) {
$name= $_POST['name'];
$email_address= $_POST['password'];
$password= $_POST['email_address'];

if(!empty($name) && !empty($email_address) && !empty($password)) {


 echo $query= "INSERT INTO `a_database`.`email` (`id`, `name`, `email_address`, `password`) VALUES (' ', '$name', '$email_address', '$password')";

$query_run= mysql_query($query);

echo "Account Created";

Edited by tahakirmani
Link to comment
https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/
Share on other sites

mysql is neither giving any error message not inserting any row in the table. The following output appears.

 

That's probably because you aren't checking for those errors!

if(!isset($_POST['name']) || !isset($_POST['password']) || !isset($_POST['email_address']))
{
   echo "Error: Required fields are missing.";
}
else
{
   $name		  = mysql_real_escape_string(trim($_POST['name']));
   $email_address = mysql_real_escape_string(trim($_POST['email_address']));
   $password	  = mysql_real_escape_string(trim($_POST['password']));

   if(!empty($name) && !empty($email_address) && !empty($password))
   {
    $query= "INSERT INTO `a_database`.`email`
				 (`name`, `email_address`, `password`)
			 VALUES
				 ('$name', '$email_address', '$password')";
    $result = mysql_query($query);

    if($result)
    {
	    echo "Account Created";
    }
    else
    {
	    echo "Error running script<br><br>Query: {$query}<br>Error: " . mysql_error();
    }
   }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.