473,320 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error in connecting php mysql and html

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
18 1884
ak1dnar
1,584 Expert 1GB
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
1,584 Expert 1GB
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
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
6,050 Expert 4TB
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
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
6,050 Expert 4TB
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
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
hi,
plz can anyone help me out
Feb 18 '08 #9
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
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
6,050 Expert 4TB
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
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
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
Plz can anyone tel me how ro set minimum number of characters for pasword criteria in a form.
Feb 23 '08 #15
Markus
6,050 Expert 4TB
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
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
6,050 Expert 4TB
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
4,258 Expert 4TB
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
0
by: ngiven | last post by:
Hello All, I'm running mysql 4.0.21 on an HP-UNIX machine and I am getting the following error: Got error 12 from Table Handler After looking up this error in the MySQL manual,...
3
by: kamilla | last post by:
I have a mysql 3.5 server installed on a suse linux 8.1, with address 10.0.0.100. Now I want to access that db from a W2K pc, address 10.0.0.200. I am able to ping 10.0.0.100, but I cannot connect...
4
by: 21novembre | last post by:
Hi all, I got a quite strange problem when I tried to setup a database backup shell. I put it this way: "bin/mysqldump --opt --user=xxx --password=xxx DB > DB.bak" However, error 1045 came to...
3
by: dstewart | last post by:
Situation: One common MySQL database server on SuSE 9.1 with all updates. Uses 'rinetd'. Has entries for the appropriate IP addresses of all servers. NOTE: If the appropirate entries are NOT in...
6
by: Erik H. | last post by:
Trying to connect to MySQL db on localhost, and populate datagrid from a dataset using code inline method. Getting the following compile error: Error Message: "CS0246: The type or namespace...
3
by: Jeremy Dillinger | last post by:
I am trying to design a program that will use data from a MySQL database. Currently all the data is being used with PHP scripts from a website. I am also trying to build a software solution that...
4
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always...
2
by: arsisthesis | last post by:
Hi all, I have a curious problem with the ERROR 1044 and 1045: -system: OS X 10.4.3 (bash shell) -bash schell prompt: /~ kssun$ -I have set passwd to 'kssun' -I set path:...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.