PHP - Is It Possible To Create A Form Using Only Php
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. 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> 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 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? 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. 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?
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 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 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. 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 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"; } Hello fellow PHP Freaks Is there a way to assign mysql access privileges using a php script? Maybe when your registering a user and assign them a role, depending on the role, they get certain privileges on the db... I need help. Thank you in advance. Hii i want to create an api of the short url site ( http://torrentz.0fees.net ). In the api page it is says that Code: [Select] API Our API allows you to provide short url functionality to any of your existing websites. Url Only To generate a url via the API, send a POST or GET request to the site in the following format: - http://torrentz.0fees.net/index.php?api=1&return_url_text=1&longUrl={URL} This site will then generate the short url and return it as plain text. i.e: - http://torrentz.0fees.net/a1 I have created an form but not able to use it. The form script is shown below. Code: [Select] <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> Whenever i'm putting the ( http://torrentz.0fees.net/index.php?api=1&return_url_text=1&longUrl={URL} ) it shows an error. I know that the input url must be used in the ( {URL} ) section but how can i do that using php Can anyone help me with code... HOw to create this header?
I give +. thx
http://i.snag.gy/15Ep4.jpg
hi, I'm currently trying to resize and create pictures and .jpg/jpeg & .gif works perfectly but .png just creates an empty 0bit image, why?! Code: [Select] $ = imagecreatefrompng(); imagecopyresampled(); imagepng(); I'm doing something like that and it - as said - works great with .jpg and gif but at png it just fucks up. :/ I have a table in my database for users. On the registration page I want to create another table with the id of the user as the table name. $sql = "CREATE TABLE IF NOT EXISTS `id_prod` ( ) how do i modify this line so that it takes the id from the user table and creates a new table with id as name followed by prod. Hello all That forum is my last desperate attemp to do what i want to do. Ok here is the story I want to create a simple rss feed in conjuction with php and mysql. I dont want admin areas ect , i just want when i insert a new listing to my database to be able shown up to my (future) rss subscribers. To be more technically specific i want to show to my surfers updates about 2 tables in my database not all the tables. The example i found so far were about only 1 table, plus i was encounting errors to my script. I would like some ideas, directions if someone is kind enough to help a sad developer Thanks in advance! HI all, I am building a php application and i am wanting to use notifications. At the moment i am just wanting to understand the methodology behind this. I dont necessarily have a use case for these notifications yet but i am going to base it off of the following: A user submits something to the database, another user gets a notifications that this has happened. I see the notifications being something appearing in the header bar (saying "you have a notification"...) I know that i will need to use ajax for this and JS/JQ but i am not really sure where to start with this. I have done some research and have come up a little blank. My main question at the moment is how does the submission of data to the database trigger the notification? As always and help here is appreciated. Kind Regards Adam I am using the following code: Code: [Select] <?php $target = "images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> I am using this to upload photos to the directory called 'images'. How could I change this code so that I can choose an existing directory to upload it to and also create a new directory to upload it to if I wanted? |