~hoor~ Posted January 9, 2011 Share Posted January 9, 2011 Hello all, I hope you are doing great.I am using phpmyadmin for the first time.So I created a table called guestbook with 4 attributes: id,name,email,message..Then I created a php file with the following code (saved in htdoc in Xampp folder)and html form which would take the data from the user and insert into the database which could later be retrieved.So far I have just written the insertion code which successfully creates the form but when I click on submit button it opens the same php file with the code and no insertion is made in the database..here is my code..plz help me urgently..i have my project deadline very soon. php file called guest.php: <?php $user="root"; $password=""; $database="Guestbook"; $name=$_POST['name']; $email=$_POST['email']; $body=$_POST['body']; $connect("localhost",$user,$password); mysql($connect); @mysql_select_db($database)or die("unable to select db"); $query = mysql_query("INSERT INTO Guestbook(id,name,email,body) VALUES('','$name','$email','$body')"); if(!$query) { echo mysql_errno().':'.mysql_error(); } mysql_close(); ?> html file called new.html: <html> <head> <title>Guestbook</title> </head> <body> <form method="post" action="guest.php" > Name:<input type="text" name="name" size="30"/><br/> Email: <input type="text" name="email" size="30"/><br/> <p>Text:<br/> <textarea name="message" rows="15" cols="60"></textarea></p> <br/> <input type="submit" value="Submit"/> <input type="reset" value="Clear"/> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 you should see an error. apparently, you do not have error_reporting turned on. add this to the top of your code, before anything else. error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment Share on other sites More sharing options...
~hoor~ Posted January 9, 2011 Author Share Posted January 9, 2011 I have an error message code.. if(!$query) { echo mysql_errno().':'.mysql_error(); } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 you should see an error. apparently, you do not have error_reporting turned on. add this to the top of your code, before anything else. error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 I have an error message code.. if(!$query) { echo mysql_errno().':'.mysql_error(); } That part of your code will never be executed as the code is written. you should see an error. apparently, you do not have error_reporting turned on. add this to the top of your code, before anything else. error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment Share on other sites More sharing options...
~hoor~ Posted January 9, 2011 Author Share Posted January 9, 2011 this is what I did and the problem continues....why do I see the same php file when I click the submit button? what could be wrong? Quote Link to comment Share on other sites More sharing options...
~hoor~ Posted January 9, 2011 Author Share Posted January 9, 2011 <?php error_reporting(E_ALL); ini_set("display_errors", 1); mysql_close(); $user="root"; $password=""; $database="Guestbook"; $name=$_POST['name']; $email=$_POST['email']; $body=$_POST['body']; $connect("localhost",$user,$password); mysql($connect); @mysql_select_db($database)or die("unable to select db"); $query = mysql_query("INSERT INTO Guestbook(id,name,email,body) VALUES('','$name','$email','$body')"); if(!$query) { echo mysql_errno().':'.mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 You should be getting an error regarding this line: mysql($connect); mysql_connect Quote Link to comment Share on other sites More sharing options...
~hoor~ Posted January 9, 2011 Author Share Posted January 9, 2011 You mean like this? <?php $user="root"; $password=""; $database="Guestbook"; $name=$_POST['name']; $email=$_POST['email']; $body=$_POST['body']; $connect("localhost",$user,$password); mysql($connect); error_reporting(E_ALL); ini_set("display_errors", 1); mysql_close(); @mysql_select_db($database)or die("unable to select db"); $query = mysql_query("INSERT INTO Guestbook(id,name,email,body) VALUES('','$name','$email','$body')"); if(!$query) { echo mysql_errno().':'.mysql_error(); } ?> Quote Link to comment 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.