PHP - Using Php/html To Create A Form
I am trying to create a form that will be store in-house. This form needs to have a drop-down of keywords. These keywords will cause a snippet of code (pulled from the selection of the keyword) to be placed into a text document one after another.
Ex.: I click on "Header" in the list and click Insert Code. This causes Code: [Select] "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" to be placed into the text document. I then hit click on "Body" and it creates the Code: [Select] "<body></body" code to appear on the text document below the "Header" code above it. This is basically a text writer that just uses snippets of code as I click on buttons. Almost like this editor above is doing. Is this possible and is it easy/hard? -john Similar TutorialsHello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Hi, how can i create a form within a form with the click of a button? so that when i click add new item, it brings form fields under the current one. hope my explanation helps thanks Code: [Select] <form id="form1" name="form1" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="22%">Invoice Number </td> <td width="78%"> </td> </tr> <tr> <td>Date Issued </td> <td> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="10%">Quantity</td> <td width="70%">Description</td> <td width="9%">Taxable</td> <td width="11%">Amnount</td> </tr> <tr> <td valign="top"><input name="textfield" type="text" size="7" /></td> <td valign="top"><textarea name="textfield2" cols="80"></textarea></td> <td valign="top"><input type="checkbox" name="checkbox" value="checkbox" /></td> <td valign="top"><input name="textfield3" type="text" size="12" /></td> </tr> <tr> <td colspan="4"><input type="submit" name="Submit" value="Add New Item" /></td> </tr> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> When creating a PHP document we use echo ''; to wrap HTML into PHP, so why does it seem to me that people always say to create a form using PHP you must break it up by using HTML to show the form itself? Is there a way to create the form, and do all that is required using PHP and wrapping PHP around HTML to make it work? I can't imagine its impossible. I've been using something like this to send email messages to users on a site: $to = $email; $subject = "Message From Microsoft.com\r\n"; $headers = "From: support@Microsoft.com\r\n"; $headers .= "Return-Path: support@Microsoft.com\r\n"; $headers .= "Reply-To: support@Microsoft.com\r\n"; $message = "<html><body><img src='http://www.Microsoft.com/images/logo.png' /><br /><br />You have a message from Bill:<br /><br />"; $message .= '<img src="' . $image . '" /><br /><br />'; $message .= 'Isn't it pretty?.<br /><br />'; $message .= '<a href="http://www.Microsoft.com">Microsoft.com</a></body></html>'; mail($to,$subject,$message,$headers); This sends, literally, text like this: <html><body><img src='http://www.Microsoft.com/images/logo.png' /><br /><br />You have a message from Bill:<br /><br /><img src="http://www.Microsoft.com/images/billiam.jpg" /><br /><br />Isn't it pretty?.<br /><br /><a href="http://www.Microsoft.com">Microsoft.com</a></body></html> Obviously, I would like the email to hide the HTML, but use it to format the output. Also, I'd obviously like the image to show up, not a link to the image, and I would like the link to show up as a link, not as HTML. How do I do this? Cheers. guys i want to to create a html invoice to pdf file how can i do that ...by using which library...can any one help me out? Hi, I have a chunk of text I am pulling from a mysql db like below. Air conditioning in rooms 24 Hour Reception Smoking rooms available How can I write this into - <ul> <li>Air conditioning in rooms</li> <li>24 Hour Reception</li> <li>Smoking rooms available</li> </ul> Many thanks. Hey all, I am trying to put a login form on the front pages (index, contact us, about us) of my site. I want the members to put in username and pass, and when they click submit, it takes them to the /members/ area of the site. Right now this is how I have the form. Code: [Select] <form method="POST" action="login.php"> <input type="text" name="username"> <input type="password" name="password"> <input type="submit" value="Login"> </form> I have this, but the members area consist of several pages and not just on location. Code: [Select] if ($_SESSION['authorized'] != true) { header("Location: login_form.php"); exit; } Finally, I am going to create a login.php page that has this in it. Code: [Select] $select_user = mysql_query('select * from users where username = "' . $_POST['username'] . '" and password = "' . md5($_POST['password'] . '"')); if (mysql_num_rows($select_user) != 0) { session_start(); session_register('authorized'); $_SESSION['authorized'] = true; header("Location: protected_content.php"); exit; } else { header("Location: login_form.php"); exit; } So My questions are, How can I make it so they can access the entire /members/ area (directory) and what would I put in the database 'members' when I create it. All members are going to use the same username and pass. So there is only need for 1 query for username and 1 for password. I appreciate anyone help in advance. i don't know what this would fall under, but it sounds like php..........is there a way to make a form make a new page from a template........like I have a picture page and I can upload pictures from a form with a picture name....and that name turns into a /name.php file? does this make sense? Hi, I want to create a .html file dynamically on the server. Below is the code for that but i was not able to create the file. I have given all the read, write and execute permission on the folder. $filerand = rand(); $fileName = "test.html"; $filepath = $_SERVER['DOCUMENT_ROOT'] . "\\testfolder\\" . $fileName . ".html"; echo $filepath; $bodytxt = "Welcome to my webpage"; $ourFileHandle = fopen($filepath, 'w') or die("can't open file"); fwrite($ourFileHandle, $bodytxt); fclose($ourFileHandle); Thanks in advance how should i approach the following: a page with a products list+link to product page i want to build a crawler that loops through all the products in the list and goes to the product page and and parses the product page. need help with the loop Hi there, its possible to something like this. <?php $i=0; $MW_Services ="aaaa.php"; $fh_MW_Services = fopen($MW_Services, 'w') or die("can't open file"); $string_MW_Services = "<html><head> </script><span style='padding-left:5px'> MW Services </head> <body> <table> <tr> <td>Teste</td> <td BACKGROUND='images/da.JPG'></td> <td></td> <td><?php for($i;$i>2;$i++){print $i;} ?> </td> </tr> </table> </body>"; fwrite($fh_MW_Services, $string_MW_Services); fclose($fh_MW_Services); ?> my problem is that the code doesnt do the cicle for it only. Tanks I am currently looking to have two pages, one with a search form (textbox and button) and output the results (from database table) based on the strings input to another page. how do i achieve this? i just want something very simple nothing too complex and advanced please Hi, I have a page with a long list of names (c1000) each with an id. On that page I would like to have a form into which i put the id number, when the form is submitted it will take me to the anchor point for that id. The question I have is, how, when i press submit and reload the page, how can I then have that form input as a anchor in the url that will then take me to the place I want to go on the list when the page loads. I can do it manually no problem by adding the hash tag and id to the url myselft it takes me there but It's a pain to do this every time. I would like to use a form. Is this possible? any help appreciated. Thanks I am trying to create a very basic "forum"/comments section and I want to know how to have a page be automatically created once the form is submitted. I have found the code: Code: [Select] <?php function wwwcopy($link,$file) { $fp = @fopen($link,"r"); while(!feof($fp)) { $cont.= fread($fp,1024); } fclose($fp); $fp2 = @fopen($file,"w"); fwrite($fp2,$cont); fclose($fp2); } //Example on using this function //wwwcopy("http://www.domain.com/list.php?member=sample", "sample.html"); //Another example //wwwcopy("http://www.domain.com/list.php?member=sample2", "sample2.html"); ?> I am using post for my forum (not even sure how get would handle the comments section). How can I use this (or tweak it)? The variables I am passing are $User, $Email, $Title, $Comments, $Date. Would I still use it the same? ie: wwwcopy("http://www.domain.com/forum/new-post.php?User=$User&Email=$Email&Title=$Title&Comments=$Comments&Date=$Date", "X.php");? Also, the value for X is up in the air. I've considered using the auto increment id(index) number from the mySQL database this is saved in. So completely new here.
I've created a database that has 4 fields full_name, company, email and serial_no with 2 sample records.
I would like to create a form with those fields, so the data I enter into the form when I press submit it goes into the database. Config File: <?php $mysqli = new mysqli('localhost', 'username', 'pass', 'database_name'); if($mysqli->connect_error) { echo $mysqli->connect_error; } ?>
Index.php <html lang="en"> <head> <meta charset="UTF-8"> <title>Add Record Form</title> </head> <body> <form action="insert.php" method="post"> <p> <label for="Fullname">Fullname:</label> <input type="text" name="full_name" id="Fullname"> </p> <p> <label for="Company">Company:</label> <input type="text" name="Company" id="Company"> </p> <p> <label for="emailAddress">Email Address:</label> <input type="text" name="email" id="emailAddress"> </p> <p> <label for="Serial">Serial:</label> <input type="text" name="Serial" id="Serial"> </p> <input type="submit" value="Submit"> </form> </body> </html>
Insert.php <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "username", "pass", "database_name"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $full_name = mysqli_real_escape_string($link, $_REQUEST['full_name']); $company = mysqli_real_escape_string($link, $_REQUEST['company']); $email = mysqli_real_escape_string($link, $_REQUEST['email']); $serial_no = mysqli_real_escape_string($link, $_REQUEST['serial_no']); // Attempt insert query execution $sql = "INSERT INTO licjwe(full_name, company, email, serial_no) VALUES ('$full_name', '$company', '$email', '$serial_no')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?>
This is the error I am getting: ERROR: Could not able to execute INSERT INTO database_name(full_name, company, email, serial_no) VALUES ('test', '', 'email@home.com', ''). Table 'table_name' doesn't exist Not sure what I am doing.
Basically I want to have the form so I can enter the data, once its been entered, it lets me know its been successfully updated, then loads the page again.
Please help. Where have I gone wrong?
Hey everyone, I am looking to create an advanced contact form but need someone to point me in the right direction. I need to create a customer service form and would like it to contain the usual fields e.g. Name, Email etc. but also want to include a drop down field which has a couple of options e.g. Sales Enquiry, Order Status etc. Once one of those options has been selected e.g. Order Status, I then want a further section of the form to appear where the user can input data such as their order number, order date etc. Does anyone have any ideas on how to achieve this or know of any demos/scripts which they think might help. I do have a sql table named "module" and a parent module may have a sub module. Each parent module can have a maximum of 9 sub modules of three per <td>. This is how this "module" table looks like: +-----------+------------------+----------+------+--------+---------------------+ | module_id | name | page_url | icon | parent | created_date | +-----------+------------------+----------+------+--------+---------------------+ | 1 | User Modules | | NULL | NULL | 2021-07-21 11:46:16 | | 2 | Items | | NULL | 1 | 2021-07-21 11:46:16 | | 3 | Add New Item | | NULL | 2 | 2021-07-21 11:46:16 | | 4 | View Item | | NULL | 2 | 2021-07-21 11:46:16 | | 5 | Category | | NULL | 2 | 2021-07-21 11:46:16 | | 6 | Brand | | NULL | 2 | 2021-07-21 11:46:16 | | 7 | Unit | | NULL | 2 | 2021-07-21 11:46:16 | | 8 | Purchase | | NULL | 1 | 2021-07-21 11:46:16 | | 9 | Add New Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 10 | view Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 11 | Due Invoice | | NULL | 8 | 2021-07-21 11:46:16 | | 12 | Return | | NULL | 8 | 2021-07-21 11:46:16 | | 13 | Purchase Log | | NULL | 8 | 2021-07-21 11:46:16 | | 14 | Inventory | | NULL | 1 | 2021-07-21 11:46:16 | | 15 | Stock Transfer | | NULL | 14 | 2021-07-21 11:46:16 | | 16 | Stock Adjustment | | NULL | 14 | 2021-07-21 11:46:16 | | 17 | Batch Control | | NULL | 14 | 2021-07-21 11:46:16 | | 18 | Stock Take | | NULL | 14 | 2021-07-21 11:46:16 | +-----------+------------------+----------+------+--------+---------------------+ My desired HTML table layout looks somthing similar to this attach image.
I would like to know how we can do it in php, if is possible. Thank you. Edited July 23 by thara i have my form with 5 fields that are not required to be filled out. Code: [Select] <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> On my process page I want to remove all of the empty index's that did not have data entered. I am new to sending array data via POST do I need to do anything else other then what is below? Code: [Select] foreach($MAC as $key => $value) { if($value == "") { unset($MAC[$key]); } } $mac_addresses = array_values($MAC); if(empty($mac_addresses)){ $error = "You did not enter any MAC adresses."; $valid = "false"; } i have made a simple header page for a project.
now i want to create a dropdown menu for a single menu item in the menu bar.
how i will do that ..??
for ex-under COURSES MENU, THE SUBMENU ARE : DEGREE,DIPLOMA,HIGHSCHOOL.
Hello and looking for some help please.. I have already read this : http://www.phpfreaks.com/forums/index.php?topic=120619.0 What I am after to do, is to after a successful Paypal payment from paypal, generate a link in a wordpress site (or external even) that will expire after 3 days to a video. I hope that makes sense please? Thanks in advance, Jim |