Darco Posted November 2, 2009 Share Posted November 2, 2009 Hello Guys, I just joined PHPFreaks.com and I am mainly here for some help. I work for a small biz and we need a form that updates a SQL Database....Here is my code below: The input.html (Form for the fields): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>GRCA Club House Control Panel</title> <style type="text/css"> <!-- .style1 {color: #006600} .style2 { color: #006600; font-style: italic; font-size: 18px; } --> </style> </head> <body> <table border="1"> <tr> <td align="center">GRCA Club House Check In</td> </tr> <tr> <td> <table> <form method="post" action="input.php"> <tr> <td>Name</td> <td><input type="text" name="name" size="50"></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address" size="50"></td> </tr> <tr> <td></td> <td align="right"><input type="submit" name="submit" value="Save"></td> </tr> </table></td> </tr> </table> <p class="style2"> Helpful Links:</p> <p class="style1"><a href="http://goldenridgecondos.org"><strong>Go to GRCA Website</strong></a></p> <p class="style1"><a href="#"><strong>Lookup Unit</strong></a></p> <p class="style1"><a href="#"><strong>Submit A Work Order</strong></a></p> <p> </p> </body> </html> And the post action PHP form is: <? //the example of inserting data with variable from HTML form //input.php mysql_connect("localhost","root","ascent");//database connection mysql_select_db("employees"); //inserting data order $order = "INSERT INTO data_employees (name, address) VALUES ('$name', '$address')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br>Data was successfully saved into DataBase."); } else{ echo("<br>Data was could not be saved into DataBase. Please check to make sure the DataBase is running or that you have entered the correct info. "); } ?> It submits a new row but, the row is empty. How do I fix this? I do not know alot about PHP that is why I came here for some help. Thanks, Darco Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/ Share on other sites More sharing options...
Jnerocorp Posted November 2, 2009 Share Posted November 2, 2009 it looks like your variables werent defined try this: <? if(isset($_POST['name'] && $_POST['address'])) { mysql_connect("localhost","root","ascent");//database connection mysql_select_db("employees"); $name = $_POST['name']; $address = $_POST['address']; //inserting data order $order = "INSERT INTO data_employees (name, address) VALUES ('$name', '$address')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br>Data was successfully saved into DataBase."); } else{ echo("<br>Data was could not be saved into DataBase. Please check to make sure the DataBase is running or that you have entered the correct info. "); } } else { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>GRCA Club House Control Panel</title> <style type="text/css"> <!-- .style1 {color: #006600} .style2 { color: #006600; font-style: italic; font-size: 18px; } --> </style> </head> <body> <table border="1"> <tr> <td align="center">GRCA Club House Check In</td> </tr> <form method="post" action=""> <tr> <td>Name</td> <td><input type="text" name="name" size="50"></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address" size="50"></td> </tr> <tr> <td align="right"><input type="submit" name="submit" value="Save"></td> </tr> <p class="style2"> Helpful Links:</p> <p class="style1"><a href="http://goldenridgecondos.org"><strong>Go to GRCA Website</strong></a></p> <p class="style1"><a href="#"><strong>Lookup Unit</strong></a></p> <p class="style1"><a href="#"><strong>Submit A Work Order</strong></a></p> <p> </p> <?php } ?> </body> </html> I added all the code into one page Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-949073 Share on other sites More sharing options...
Darco Posted November 3, 2009 Author Share Posted November 3, 2009 Hey I tryed your code and it gives me a error: Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\AC Web MaNGOS Hybrid\Server\htdocs\input.php on line 2 Please help... I appreciate you helping... Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-949907 Share on other sites More sharing options...
Jnerocorp Posted November 3, 2009 Share Posted November 3, 2009 here you go: <? if(isset($_POST['name']) && isset($_POST['address'])) { mysql_connect("localhost","root","ascent");//database connection mysql_select_db("employees"); $name = $_POST['name']; $address = $_POST['address']; //inserting data order $order = "INSERT INTO data_employees (name, address) VALUES ('$name', '$address')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br>Data was successfully saved into DataBase."); } else{ echo("<br>Data was could not be saved into DataBase. Please check to make sure the DataBase is running or that you have entered the correct info. "); } } else { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>GRCA Club House Control Panel</title> <style type="text/css"> <!-- .style1 {color: #006600} .style2 { color: #006600; font-style: italic; font-size: 18px; } --> </style> </head> <body> <table border="1"> <tr> <td align="center">GRCA Club House Check In</td> </tr> <form method="post" action=""> <tr> <td>Name</td> <td><input type="text" name="name" size="50"></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address" size="50"></td> </tr> <tr> <td align="right"><input type="submit" name="submit" value="Save"></td> </tr> <p class="style2"> Helpful Links:</p> <p class="style1"><a href="http://goldenridgecondos.org"><strong>Go to GRCA Website</strong></a></p> <p class="style1"><a href="#"><strong>Lookup Unit</strong></a></p> <p class="style1"><a href="#"><strong>Submit A Work Order</strong></a></p> <p> </p> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-949981 Share on other sites More sharing options...
Darco Posted November 5, 2009 Author Share Posted November 5, 2009 Awesome man! Thank You so much...You don't know how much you helped me... Is there anyway I can give you some rep....? Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-951409 Share on other sites More sharing options...
Darco Posted November 5, 2009 Author Share Posted November 5, 2009 Hey Jnerocorp... I tryed your code and it works! PERFECT but I don't need that specific thing... I'm going to tell you what do need... and that is.... An exact same thing but with more fields to it.... here what I need... I need just a basic php form that will update the MySQL database....The stuff in () is what I would like their fuctions to be... I need something with the following fields: (Automatic) Record # Name (Auto Populated) Date (Auto Populated) Check In Time (Manually Enter) Check Out time Bldg/Unit Resident Name Guests Comments Activity ( For "Activity" I would like somthing thats with 4 drop down menus so I can choose 4 or more activities at the same time) And the dropdown menues need to be all the same with these options: Wifi/Computers Billiards/Foosball Library TV Piano Tour Weight Room Swimming Pool Hot Tub Sauna Game Room Party Room Tennis Court Cardio Room I want 4 dropdowns so I if somone is going to use the weight room then the TV then I can select both...So if you can make 4 dropdowns..... Also I would like to say sorry if this is to harsh or meanful but If you can help me out with this then I would gladly want to help you anytime in need or even give you some rep on PHPFreaks.com if I can. Or help you with any IT problems... Thanks ask me Qs if u need to... Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-951467 Share on other sites More sharing options...
MadTechie Posted November 5, 2009 Share Posted November 5, 2009 If you want someone to write the code for you then we have a section for that.. its called the freelance section, Forum Rule #12 All request for code to be written for you should be posted under the freelance section. No exceptions. Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-951472 Share on other sites More sharing options...
waynew Posted November 5, 2009 Share Posted November 5, 2009 People here volunteer their time to help people with their scripts. They usually don't write your scripts for you. If you're really stuck in a rut, I suggest that you visit the freelance forum and tell everyone how much you're willing to pay. Quote Link to comment https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/#findComment-951475 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.