By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Error in connecting php mysql and html

P: 63
Hi,
Ive created a form in html and written code in hp tht takes data feom html and stores it in MySQL database. Bt wen i click on the submit button i get an error. Instead of storing it in database it asks to open the php file which has bees specified in the action attribute of the form tag. It is being created for windows platform.
Im pasting the code of both the html and php file that ive used and plz let me know how to fix that problem.
File name:form.html
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <HEAD>
  5. <TITLE>Form Handling with PHP</TITLE>
  6. </HEAD>
  7. <BODY BGCOLOR="#FFFFFF">
  8. <FORM METHOD=POST ACTION="add.php">
  9. <input type="hidden" name="id" value="NULL">
  10. <TABLE>
  11. <TR height="20">
  12. <TD colspan="2"><FONT SIZE="+0" face="verdana"> Below is a Sample Form for our PHP tutorial</TD>
  13. </TR>
  14. <TR height="50">
  15. <td></td>
  16. </TR>
  17. <TR>
  18. <TD align="left"><FONT SIZE="+0" face="verdana"> <b>Your Name <br>
  19. Your E-Mail Address</b></td>
  20. <td><INPUT TYPE="text" NAME="name">
  21. <br>
  22. <INPUT TYPE="text" NAME="email">
  23. </TD>
  24. </TR>
  25. <tr>
  26. <td colspan="2"><center>
  27. <SELECT NAME="opinion">
  28. <option value="is great">I like your site</option>
  29. <option value="is OK">Your Site is OK</option>
  30. <option value="is horrible">Your Site is horrible</option>
  31. </SELECT>
  32. <INPUT TYPE="submit" value="Tell us!">
  33. </td>
  34. </tr>
  35. </TABLE>
  36. </FORM>
  37. </BODY>
  38. </HTML> 
  39.  
Filename:add.php
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $DBhost = "localhost";
  3. $DBuser = "root";
  4. $DBpass = "database";
  5. $DBName = "test";
  6. $table = "information";
  7. mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
  8.  
  9. @mysql_select_db("$DBName") or die("Unable to select
  10. database $DBName");
  11.  
  12. $sqlquery = "INSERT INTO $table
  13. VALUES('$id','$name','$email','$opinion')";
  14.  
  15. $results = mysql_query($sqlquery);
  16.  
  17. mysql_close();
  18.  
  19. print "<HTML><TITLE> PHP and MySQL </TITLE><BODY
  20. BGCOLOR=\"#FFFFFF\"><center><table border=\"0\"
  21. width=\"500\"><tr><td>";
  22. print "<p><font face=\"verdana\" size=\"+0\"> <center>You
  23. Just Entered This Information Into the
  24. Database<p><blockquote>";
  25. print "Name : $name<p>E-Mail : $email<p>Opinion :
  26. $opinion</blockquote></td></tr></table>
  27. </center></BODY></HTML>";
  28. ?>
  29.  
Plz help me out as soon as possible.
Thanks
Feb 14 '08 #1
Share this Question
Share on Google+
18 Replies


ak1dnar
Expert 100+
P: 1,584
Are you executing these pages with a web server, then what is it?
Is php is configured to work with the web server?
Feb 14 '08 #2

ak1dnar
Expert 100+
P: 1,584
This is Not a Good thread title;
Error in connecting php mysql and html (Plz help urgently)
But this is
Error in connecting php mysql and html

So avoid using these words *please* *help* *urgent*
and make sure to use the CODE tags. refer to Posting guidelines first
Thanks
Feb 14 '08 #3

P: 63
Are you executing these pages with a web server, then what is it?
Is php is configured to work with the web server?

Im using xampp to run this web pages.php is configured in it. Ive created the database in MySQL using xampp. Plz let me know
Thanks
Feb 14 '08 #4

Markus
Expert 5K+
P: 6,050
Im using xampp to run this web pages.php is configured in it. Ive created the database in MySQL using xampp. Plz let me know
Thanks
Is xampp running (check apache)?
Ar you saving the files in the righte directory (htdocs)?
Feb 14 '08 #5

P: 63
Hey thanks my that problem has got solved. I saved in wrong folder. Can u plz tel me like when user fills form i had asked him to retype pssword to confirm. What is the way that we verify it. Plz let me know how to do this. Is there a function available or v hve to apply some logic
Feb 16 '08 #6

Markus
Expert 5K+
P: 6,050
Hey thanks my that problem has got solved. I saved in wrong folder. Can u plz tel me like when user fills form i had asked him to retype pssword to confirm. What is the way that we verify it. Plz let me know how to do this. Is there a function available or v hve to apply some logic
Well, you can either use javascript or php?
Javascript is client side, and therefore we can alert the user before the form is submitted.
ORRRRRRRRRRRRRRR!
Php, server side, this could be used in add.php and then notify the user that the passwords didnt match and provide a back button for him to return and try again!
Here's an example for javascript:
Expand|Select|Wrap|Line Numbers
  1. function validatePassword()
  2. {
  3.     var passWord = document.form_name.input_name.value;
  4.     var passWordS = document.form_name.input_name.value;
  5.     if(passWord == passWordS)
  6.     {
  7.         // the passwords matched ... submit form
  8.         document.form_name.submit();
  9.     }
  10.     else
  11.     {
  12.          // the passwords DIDNT match ... alert user
  13.          alert("Sorry, there was an error:\n\nPasswords didn't match");
  14.          document.form_name.input_name.focus();
  15.          return false;
  16.     }
  17. }
  18.  
Obviously, you'd have to adapt it to your form and use the correct form_name's and input_name's

And a php method:
[php]
$_passwordA = $_POST['passwordA'];
$_passwordB = $_POST['passwordB'];

if($_passwordA == $_passwordB)
{
// passwords matched
// execute the code.
}
else
{
// passes didnt match:
echo "The passwords you provided didn't match<br />";
echo "Please use <a href=\"javascript: history.back();\">this link</a> to return to the form!";
}
[/php]

Hope this helps you :)
Feb 16 '08 #7

P: 63
hi,
I tried using your php code but it didnt worked out. Ive attached my php file below without the pasword code.
Plz try n tel me if it works.
html filename is register.html and php filename is process.php
Plz let me know.
PHP file
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. # THIS CODE DEFINES THE DATABASE TO BE FILLED
  4. $hostname = "localhost";
  5. $db_user = "root";
  6. $db_password = "database";
  7. $db_name = "skills_portfolio";
  8. $db_table1 = "functionalarea";
  9. $db_table2 = "functionalrole";
  10. $db_table3 = "institute";
  11. $db_table4 = "qualification";
  12. $db_table5 = "specialization";
  13. $db_table6 = "tagmaster";
  14. $db_table7 = "userdetails";
  15. $db_table8 = "usermaster";
  16. $db_table9 = "usertags";
  17.  
  18. # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
  19. $dbi=mysql_connect($hostname, $db_user, $db_password);
  20. mysql_select_db($db_name,$dbi);
  21.  
  22. if (isset($_REQUEST['Submit']))
  23. {
  24. # THIS CODE INSERTS THE DATA FROM THE FORM INTO MYSQL TABLE
  25.  
  26. mysql_query( "INSERT INTO $db_table1(AreaName)values('$_POST[AreaName]')")
  27. or die(mysql_error());
  28.  
  29. mysql_query("INSERT INTO $db_table2(RoleName) values('$_POST[RoleName]')")
  30. or die(mysql_error());
  31.  
  32. mysql_query("INSERT INTO $db_table3(InstituteName)
  33. values('$_POST[InstituteName]')")
  34. or die(mysql_error());
  35.  
  36. mysql_query("INSERT INTO $db_table4(QualificationName) values ('$_POST[QualificationName]')")
  37. or die(mysql_error());
  38.  
  39. mysql_query("INSERT INTO $db_table5(SpecializationArea) values ('$_POST[SpecializationArea]')")
  40. or die(mysql_error());
  41.  
  42. mysql_query("INSERT INTO $db_table7(UserName,PhoneNo,MobileNo,YearsExp,
  43. MonthsExp,FunctionalArea,KeySkills,Qualification,Specialization,Institute,
  44. FunctionalRoles,CurrentEmployer,PreviousEmployers,ProfileTitle,ResumeFile) 
  45. values ('$_POST[UserName]','$_POST[PhoneNo]','$_POST[MobileNo]',
  46. '$_POST[YearsExp]','$_POST[MonthsExp]','$_POST[AreaName]',
  47. '$_POST[KeySkills]','$_POST[QualificationName]','$_POST[SpecializationArea]',
  48. '$_POST[Institute]','$_POST[RoleName]','$_POST[CurrentEmployer]',
  49. '$_POST[PreviousEmployers]','$_POST[ProfileTitle]','$_POST[ResumeFile]')") 
  50. or die(mysql_error());
  51.  
  52. mysql_query("INSERT INTO  $db_table8(UserName,UserPassword,FullName,EmailAddress) 
  53. values ('$_POST[UserName]','$_POST[UserPassword]','$_POST[FullName]',
  54. '$_POST[EmailAddress]')") or die(mysql_error()) ;
  55.  
  56. mysql_query( "INSERT INTO $db_table9(UserName)values('$_POST[UserName]')") 
  57. or die(mysql_error());
  58.  
  59. echo "Congrats, Your have been successfully registered on our portal";
  60.  
  61. }
  62.  
  63. ?> 
  64.  
Feb 16 '08 #8

P: 63
hi,
plz can anyone help me out
Feb 18 '08 #9

P: 1
you use software called EasyPhp which enables the php pages to be displayed on the windows environment.

it also runs Apache and Mysql Server.

copy all your pages in the Program Files -> EasyPhp -> www folder and run the IE as http://localhost/yourfile.php

you problem will be solved.
Feb 18 '08 #10

P: 63
Hi,
Thanx but i can view my pages thats not a problem.
I ve written the pages in html but i want to verify that the user during registration types the pasword and retype pasword same or not. i want the logic for this part.
Feb 18 '08 #11

Markus
Expert 5K+
P: 6,050
Hi,
Thanx but i can view my pages thats not a problem.
I ve written the pages in html but i want to verify that the user during registration types the pasword and retype pasword same or not. i want the logic for this part.
i gave you the logic...

[php]
if(password_a == password_b)
{
// run the mysql queries
}
else
{
// the passwords didnt match
}
[/php]
Feb 18 '08 #12

P: 63
Thanks alot. That logic worked but have a small problem in it. If the password doesnt match it than also stores the other info in all other tables. Also how should i send the user back to fill in the password. should i specify the html file path for it in href. I also wanted to know about making a compulsion for password strength.
Thanks again
Feb 21 '08 #13

P: 63
Hi,
It is working now my that peoblem also got solved. I want that if the paswords dont match than when the user returns the registration page then he should not be asked to type all the information again. It should appear on screen and should only be asked to enter the paswords again. My other problem of pasword strength is not solved yet. Plz let me know.
Feb 21 '08 #14

P: 63
Plz can anyone tel me how ro set minimum number of characters for pasword criteria in a form.
Feb 23 '08 #15

Markus
Expert 5K+
P: 6,050
Plz can anyone tel me how ro set minimum number of characters for pasword criteria in a form.
javascript:
Expand|Select|Wrap|Line Numbers
  1. function checkInput()
  2. {
  3.     var password = document.form_name.input_name;
  4.     if(password.value.length < 7) // if string is less than 7 chars
  5.     {
  6.         alert("Password must be longer than 7 chars");
  7.         return false;
  8.     }
  9.     else if
  10.     { 
  11.         // other checking ...
  12.     }
  13.     else
  14.     {
  15.         // submit form?
  16.     }
  17. }
  18.  
Php:
[php]
<?php
session_start(); //start up a session
$_password = $_POST['password'];
if(strlen($_password) < 6) // if length less than 6
{
$_SESSION['errors'] = "Password too short."; // give an explanation of error.
header("Location: some/directory/of/form/");
}
// other code..
[/php]
Feb 23 '08 #16

P: 63
hey can u plz let me know what is the header section in the above code of PHP dt u ve put. Wt exactly is supposed to come there. Thanks
Feb 25 '08 #17

Markus
Expert 5K+
P: 6,050
hey can u plz let me know what is the header section in the above code of PHP dt u ve put. Wt exactly is supposed to come there. Thanks
The header("Location: ... is a way of redirecting users through php.

So:
[php]
header("Location: http://somewebsite.com");
// would direct the user to somewebsite.com
header("Location: images/thumbs/img1.jpg");
// would redirect the user to the directory (on the wesbite/path this was used)
// e.g www.somesite.com/this-is-where-the-script-is/
// to www.somesite.com/this-is-where-the-script-is/images/thumbs/img1.jpg
[/php]
:)
Feb 25 '08 #18

ronverdonk
Expert 2.5K+
P: 4,258
SInce this discussion is now steering towards another subject, I have split this thread. You can find the new question in thread http://www.thescripts.com/forum/showthread.php?t=777875

moderator
Mar 3 '08 #19

This discussion thread is closed

Replies have been disabled for this discussion.