Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/179909-i-need-help-with-a-php-form/
Share on other sites

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

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>

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...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.