hawk__0 Posted April 23, 2008 Share Posted April 23, 2008 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> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 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 } ?> Quote Link to comment Share on other sites More sharing options...
hawk__0 Posted April 23, 2008 Author Share Posted April 23, 2008 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> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 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 } ?> Quote Link to comment Share on other sites More sharing options...
hawk__0 Posted April 23, 2008 Author Share Posted April 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 thanks , although mine wasn't far off Quote Link to comment Share on other sites More sharing options...
hawk__0 Posted April 23, 2008 Author Share Posted April 23, 2008 gah, darkwater you almost have it!! I noticed the missed }, but for some reason its not printing or storing the variable... ($postal, etc) www.ninjasown.com/assig1.php Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 erm, it doesn't make sense why it isn't. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Do you have the same names on the form fields (i.e: <input type="text" name"company" />) for BOTH forms? If so, change it to company1 and company 2, and then reflect that in the script. Tell me if you need help. =) Quote Link to comment Share on other sites More sharing options...
hawk__0 Posted April 23, 2008 Author Share Posted April 23, 2008 oh ok that was definitely the problem haha, thanks guys! step 1 complete :S I'll post back here if I have further troubles while doing the rest of this Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 If you ever need help, feel free to PM me. =) Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 good thinking darkwater, i didin't even look for that Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 First thing that came to my mind, actually. =P Quote Link to comment 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.