Jump to content

Dynamically update on a page with forms?


hawk__0

Recommended Posts

Hey guys, I'm pretty new to PHP, and I did take C a year ago, but im a bit rusty.  What my goal here is, is to add something into an array (using a standard HTML form) and once i hit submit, its displayed on the screen.  Currently I only attempted to have it display one thing for testing purposes.  Anyway, heres my code:

 

<html>
<body>
<form method="post">
<table>
<tr>
        <td>Company:
        <td><input type="text" name="company">
</tr>
<tr>
        <td>Name:
        <td><input type="text" name="name">
</tr>
<tr>
        <td>Address:
        <td><input type="text" name="address">
</tr>
<tr>
        <td>City:
        <td><input type="text" name="city">
</tr>
<tr>
        <td>Postal Address:
        <td><input type="text" name="postal">
</tr>
<tr>
        <td>Telephone Number:
        <td><input type="text" name="tel">
</tr>
<tr>
        <td>Email Address:
        <td><input type="text" name="email">
</tr>
<tr>
        <td>Comments:
        <td><input type="text" name="comments">
</tr>
<tr>
        <td><input type="submit">
</tr>
</table>
<?php
$array = array("company","name","address","city","postal","tel","email","comments");
echo $array["company"];
?>
</body>
</html>

Link to comment
Share on other sites

so if im right? you want to display what they enter in the form on the page, try this

<?php
$array = array("company","name","address","city","postal","tel","email","comments");
// i've never used arrays so im not sure if this way works
if(isset($_POST['submit']))
{
echo $array["company"]; // add anything you want displayed
}
else
{
?>
<html>
<body>
<form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'>
<table>
<tr>
        <td>Company:
        <td><input type="text" name="company">
</tr>
<tr>
        <td>Name:
        <td><input type="text" name="name">
</tr>
<tr>
        <td>Address:
        <td><input type="text" name="address">
</tr>
<tr>
        <td>City:
        <td><input type="text" name="city">
</tr>
<tr>
        <td>Postal Address:
        <td><input type="text" name="postal">
</tr>
<tr>
        <td>Telephone Number:
        <td><input type="text" name="tel">
</tr>
<tr>
        <td>Email Address:
        <td><input type="text" name="email">
</tr>
<tr>
        <td>Comments:
        <td><input type="text" name="comments">
</tr>
<tr>
        <td><input type='submit' value='Submit' name='submit' />
</tr>
</table>
<?php
}
?>

Link to comment
Share on other sites

Hm, it still doesn't seem to be working.  Let me elaborate on exactly what I'm trying to do here:

I'm making a form, where the following information can be submitted and as soon as submit is clicked, it dynamically displays at the bottom of my page (the results).  I haven ow also added my next form which will be used for searching for a user through the array.

 

here is the current code now:

<html>
<body>
<u>Input a user</u>
<br />
<form method="post" action='<?php $_SERVER['PHP_SELF']; ?>'>
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
<td><input type="submit" value="Submit">
</tr>
</table>
<br />
<hr>
<br />
<u>Find a user</u>
<!----Get Info---->
<form method="get">
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
<td><input type="submit" value="Search!">
</tr>
</table>
<br />
<hr>
<u>Search Results:</u>
<br />
<br />
<?php
$array = array("company" => $company,"name","address","city","postal","tel","email","comments");
if(isset($_POST['submit']))
{
echo $array["company"];
}
else
{
}
?>
</body>
</html>

Link to comment
Share on other sites

ok, let me change the code a bit

<?php
$company = $_POST['company']
$name = $_POST['name']
$city = $_POST['address']
$postal = $_POST['postal]
$tel = $_POST['tel']
$email = $_POST['email']
$comments = $_POST['comments']

if(isset($_POST['submit']))
{
echo $company<br>$name<br>$city<br>$postal<br>$tel<br>$email<br>$comments; // add anything you want displayed
}
else
{
?>
<html>
<body>
<form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'>
<table>
<tr>
        <td>Company:
        <td><input type="text" name="company">
</tr>
<tr>
        <td>Name:
        <td><input type="text" name="name">
</tr>
<tr>
        <td>Address:
        <td><input type="text" name="address">
</tr>
<tr>
        <td>City:
        <td><input type="text" name="city">
</tr>
<tr>
        <td>Postal Address:
        <td><input type="text" name="postal">
</tr>
<tr>
        <td>Telephone Number:
        <td><input type="text" name="tel">
</tr>
<tr>
        <td>Email Address:
        <td><input type="text" name="email">
</tr>
<tr>
        <td>Comments:
        <td><input type="text" name="comments">
</tr>
<tr>
        <td><input type='submit' value='Submit' name='submit' />
</tr>
</table>
<?php
}
?>

Link to comment
Share on other sites

OK, still not working... Current code:

<html>
<body>
<?php
$company = $_POST['company'];
$name = $_POST['name'];
$city = $_POST['address'];
$postal = $_POST['postal'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if(isset($_POST['submit']))
{
echo "$company<br>$name<br>$city<br>$postal<br>$tel<br>$emaili<br>$comments"; // add anything you want displayed
}
else
{

?>
<u>Input a user</u>
<br />
<form method="post" action='<?php $_SERVER['PHP_SELF']; ?>'>
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
<td><input type="submit" value="Submit">
</tr>
</table>
<br />
<hr>
<br />
<u>Find a user</u>
<!----Get Info---->
<form method="get">
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
<td><input type="submit" value="Search!">
</tr>
</table>
<br />
<hr>
<u>Search Results:</u>
<br />
<br />
<?php
}
?>
</body>
</html>

 

and here's the page if you wanna try it to see what it does:

www.ninjasown.com/assig1.php

Link to comment
Share on other sites

are there any errors, and change the code to this.

<?php
$company = $_POST['company'];
$name = $_POST['name'];
$city = $_POST['address'];
$postal = $_POST['postal'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if(isset($_POST['submit']))
{
echo "$company<br>$name<br>$city<br>$postal<br>$tel<br>$emaili<br>$comments"; // add anything you want displayed
}
else
{

?>
<u>Input a user</u>
<br />
<form method="post" action='<?php $_SERVER['PHP_SELF']; ?>'>
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
<td><input type="submit" value="Submit">
</tr>
</table>
<?php
}
?>

 

first of all and once this bit works, work on the search.

 

Link to comment
Share on other sites

Time to lay down the law.  *Pulls out pistol*

Anyway, here:

<?php
if (isset($_POST['submit1'])) {
$company = $_POST['company'];
$name = $_POST['name'];
$city = $_POST['address'];
$postal = $_POST['postal'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$comments = $_POST['comments'];
}

?>
<u>Input a user</u>
<br />
<form method="post" action='<?php $_SERVER['PHP_SELF']; ?>'>
<table>
<tr>
<td>Company:
<td><input type="text" name="company">
</tr>
<tr>
<td>Name:
<td><input type="text" name="name">
</tr>
<tr>
<td>Address: 
<td><input type="text" name="address">
</tr>
<tr>
<td>City: 
<td><input type="text" name="city">
</tr>
<tr>
<td>Postal Address: 
<td><input type="text" name="postal">
</tr>
<tr>
<td>Telephone Number: 
<td><input type="text" name="tel">
</tr>
<tr>
<td>Email Address: 
<td><input type="text" name="email">
</tr>
<tr>
<td>Comments: 
<td><input type="text" name="comments">
</tr>
<tr>
       <input type="hidden" name="submit1" value="TRUE" />
<td><input type="submit" value="Submit">
</tr>
</table>
<?php
if(isset($_POST['submit1']))
{
echo "Company: $company<br>Name: $name<br>City: $city<br>Postal Address: $postal<br>Telephone Number: $tel<br>Email: $emaili<br>Comments: $comments"; 
}
?>

 

Try that. =)

 

EDIT: Missed a }. D:  Try it now.

Link to comment
Share on other sites

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.