tahakirmani Posted November 30, 2012 Share Posted November 30, 2012 (edited) 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 November 30, 2012 by tahakirmani Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/ Share on other sites More sharing options...
Barand Posted November 30, 2012 Share Posted November 30, 2012 What is error message given by mysql_error() ? Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396411 Share on other sites More sharing options...
tahakirmani Posted November 30, 2012 Author Share Posted November 30, 2012 mysql is neither giving any error message not inserting any row in the table. The following output appears. Account Created Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396468 Share on other sites More sharing options...
NomadicJosh Posted November 30, 2012 Share Posted November 30, 2012 I think you have these backwards: $email_address= $_POST['password']; $password= $_POST['email_address']; It should be this: $email_address= $_POST['email_address']; $password= $_POST['password']; Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396528 Share on other sites More sharing options...
Psycho Posted November 30, 2012 Share Posted November 30, 2012 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(); } } } Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396531 Share on other sites More sharing options...
tahakirmani Posted December 1, 2012 Author Share Posted December 1, 2012 Thanks alot for your help and guidance..i am receiving following error message now. Error: INSERT command denied to user ''@'localhost' for table 'email' Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396617 Share on other sites More sharing options...
tahakirmani Posted December 1, 2012 Author Share Posted December 1, 2012 Its working perfectly fine now i was not connecting with the database Quote Link to comment https://forums.phpfreaks.com/topic/271396-insert-is-not-inserting-rows-in-table/#findComment-1396618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.