PHP - Forms Help
I am attempting to create a login page, but my script is giving errors in relation to the forms.
Involved PHP: Code: [Select] $username = mysql_real_escape_string($_POST['username']); if ($_POST['submit']=='Login') { $md5pass = md5($_POST['password']); $sql = "SELECT id,username FROM members WHERE username = '$username' AND password = '$md5pass'"; //etc etc... Involved HTML: Code: [Select] <form id="f6" action="" method="post" onsubmit="return weCheckForm(this)"> <fieldset id="e6" class="cc32"> <label id="e5" class="cc33" for="e4"> Username </label> <input id="e4" class="cc34" type="text" name="username" title="username" size="23"><br> <label id="e3" class="cc33" for="e2"> Password </label> <input id="e2" class="cc34" type="password" name="password" title="password" size="23"><br> <input id="e1" class="cc35" type="submit" title="submit" value="Login"> </fieldset> </form> Errors received: Notice: Undefined index: username in C:\(etc etc...) on line 4 Notice: Undefined index: submit in C:\(etc etc...) on line 6 Now I know that the problem is username and submit are undefined. However, I do not know how to define them in relation to the forms. Similar TutorialsI need someone that is really good with php forms, looking for major help. ok i have a questions i making a form so when users sign up to my website they we have an account page and in the account page the will have some more fields they need to filll in which i would use INSERT to put the things inside my db but what if they want to update there account should i use UPDATE Hello, I just assembly a form and for styling it I am using CSS in an external file. Problem is that IE8 and I don't know about 7 (in IE9 is ok) it doesn't show the styling inside the form... My structure is something like this: (in any other situation my css styling is displayed normally) Code: [Select] <form> <span class="myclass"> </span> </form>Is there any fix for it? Thank you We have this form that customers can make their own contact forms, and then it gets inserted to the database. We can show the forms with no problems, the problem lies when someone hits submit, how do I echo out the values of the form when I'm not sure what the input name or id is going to be? This sample form generated this code Code: [Select] <div class="element"> <label id="label-element-3" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Email</span> <span class="required">*</span></label> <div class="errormessage" id="errormessage-element-3"></div> <div class="option-container"> <input class="af-inputtext af-email af-formvalue " type="text" name="element-3" id="element-3" value="" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:260px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;"></div> </div> <div class="element"> <label id="label-element-4" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Textarea</span></label> <div class="errormessage" id="errormessage-element-4"></div> <div class="option-container"> <textarea class="af-textarea af-formvalue " name="element-4" id="element-4" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:300px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;" rows="6"></textarea></div> </div> <div class="element"> </div> If you notice, each input type is named "element-" with a number afterwards. So each input could be like "element-4", "element-21", and so forth. How would I post those values of the input fields when they are automatically named? Thanks in advance Hi there, I'm new to php/MySQL. Just wondering how to create a multipage form with a back, save and submit button. Also, how do you stored the form data into the datebase and how do you display a list of submitted forms by the user to the user. I am starting to build out a class to handle forms. I want to be able to add and edit data in some cases and just add data in other cases. Also want to do some ajax stuff to prevent from having to reload the pages in certain cases. I would like to view how some other form classes work so I can model mine to what I like about others but suit my needs. I was wondering if anyone has worked with any preexisting form classes that they could recommend. I know libraries like zend and so on have these built in and wasnt sure if anyone liked any one specifically and why. i need a form that is hidden until the user clicks a button on a calendar only Then the form will be visible and have a field for the day that way pressed on submit the form would go back to being invisible.
not sure how to implement this can anyone help
print("<form name='form1' method='post' action='create-b.php' enctype='application/x-www-form-urlencoded' style='margin:0px'> <input type='hidden' name='time' value='werwRG/443gooa22a04c0c2d46c802cc7e3b262398852$glg/WE?F'> <input name='name' value='Anonymous' type='text' MAXLENGTH='15' style='position:absolute;width:650px;left:67px;top:142px;z-index:11'> <input name='subject' value='(No subject)' MAXLENGTH='15' type='text' style='position:absolute;width:650px;left:67px;top:166px;z-index:11'> <textarea name='body' MAXLENGTH='255' type='text' style='position:absolute;left:67px;top:191px;width:650px;height:98px;z-index:11'></textarea> <input name='submit' type='submit' value='Create thread' style='position:absolute;left:614px;top:291px;z-index:11'> <div id='captcha' style='position:absolute; overflow:hidden; left:10px; top:296px; z-index:10'> require_once('captc/recaptchalib.php'); $publickey = '*******************************************'; echo recaptcha_get_html($publickey); </form> </div>"); How can I make the highlighted text be read as PHP and not just text? It has to be in the form tags... before you reply saying you forgot the php tags, no i didn't. I can't use php tags inside php tags... hi, I have a form in which some information is required but the username is optional however if it is left blank it says that username is taken please choose another one. how can I make it accept it if a username isn't entered? Code: [Select] <?php if (!isset($_SESSION)){ session_start(); } $fname=""; $lname=""; $username=""; $password=""; $reenterPassword=""; $address=""; $state=""; $city=""; $zip=""; $phone=""; $fax=""; $email =""; $re_enter_email =""; $payment = ""; $paypal_username=""; $ship_first_name=""; $ship_last_name=""; $ship_address=""; $ship_city=""; $ship_state=""; $ship_zip=""; $ship_email=""; $ship_re_email=""; $pet_name=""; $age=1; $breed=""; $pet_name2=""; $age2=1; $breed2=""; // Logout if(isset($_POST['logout'])){ unset($_SESSION['user']); } // Loading captcha file require_once('recaptchalib.php'); $privatekey = "6LdxwsoSAAAAAO4CWYDjkrGQsf5GXuIopJcC6SkE"; $publickey = "6LdxwsoSAAAAAFrZTLjBoDvLLjk9_NR_ubncL-24"; require_once("functions.php"); DatabaseConnection(); $state = $_POST['state']; $payment = $_POST['payment_Method']; $breed = $_POST['breed']; $ship_state=$_POST['Shipstate']; if((isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="Log in") || $_SESSION['user']){ if(!$_SESSION['user']){ $login_username = isset($_REQUEST["username"])?$_REQUEST["username"]:""; $login_password = isset($_REQUEST["password"])?$_REQUEST["password"]:""; $msg = array(); if ($login_username == "") $login_msg['username_empty'] = "Please enter your name"; if ($login_password == "") $login_msg['password_empty'] = "Please enter your password"; $query = "SELECT * FROM customers WHERE username = '$login_username' AND password = '".$login_password."'"; }else{ $customer_id = $_SESSION['user']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; } if (!$login_msg){ $login_process = true; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $row = mysql_fetch_object($result); $customer_id = $row->customer_id; $_SESSION['user'] = $customer_id; $fname = $row->fname; $lname = $row->lname; $username=$row->username; $address=$row->address; $state=$row->state; $city=$row->city; $zip=$row->zip; $phone=$row->phone; $fax=$row->fax; $email =$row->email; $payment = $row->payment_method; $paypal_username=$row->paypal_username; $ship_first_name=$row->ship_first_name; $ship_last_name=$row->ship_last_name; $ship_address=$row->ship_address; $ship_city=$row->ship_city; $ship_state=$row->ship_state; $ship_zip=$row->ship_zip; $ship_email=$row->ship_email; $pet_name=$row->pet_name; $age=$row->age; $age_month=$row->age_month; $breed=$row->breed; $pet_name2=$row->pet_name2; $age2=$row->age2; $age_month2=$row->age_month2; $breed2=$row->breed2; }else{ $login_msg['login_fail'] = "Username, password combination is not valid."; } } } if(isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="submit"){ $msg=array(); $fname=isset($_REQUEST["fname"])?$_REQUEST["fname"]:""; $lname=isset($_REQUEST["lname"])?$_REQUEST["lname"]:""; $username=isset($_REQUEST["lname"])?$_REQUEST["username"]:""; $password=isset($_REQUEST["lname"])?$_REQUEST["password"]:""; $reenterPassword=isset($_REQUEST["lname"])?$_REQUEST["reenterPassword"]:""; $address=isset($_REQUEST["address"])?$_REQUEST["address"]:""; $state=isset($_REQUEST["state"])?$_REQUEST["state"]:""; $city=isset($_REQUEST["city"])?$_REQUEST["city"]:""; $zip=isset($_REQUEST["zipcode"])?$_REQUEST["zipcode"]:""; $phone=isset($_REQUEST["phone"])?$_REQUEST["phone"]:""; $fax=isset($_REQUEST["fax"])?$_REQUEST["fax"]:""; $email =isset($_REQUEST["email"])?$_REQUEST["email"]:""; $re_enter_email =isset($_REQUEST["re_email"])?$_REQUEST["re_email"]:""; $re_enter_email= $email; $payment = isset($_POST['payment_Method'])?$_POST['payment_Method']:""; $paypal_username=isset($_REQUEST["PayPal_username"])?$_REQUEST["PayPal_username"]:""; $ship_first_name=isset($_REQUEST["Shipfname"])?$_REQUEST["Shipfname"]:""; $ship_last_name=isset($_REQUEST["Shiplname"])?$_REQUEST["Shiplname"]:""; $ship_address=isset($_REQUEST["Shipaddress"])?$_REQUEST["Shipaddress"]:""; $ship_city=isset($_REQUEST["Shipcity"])?$_REQUEST["Shipcity"]:""; $ship_state=isset($_REQUEST["Shipstate"])?$_REQUEST["Shipstate"]:""; $ship_zip=isset($_REQUEST["Shipzipcode"])?$_REQUEST["Shipzipcode"]:""; $ship_email=isset($_REQUEST["Shipemail"])?$_REQUEST["Shipemail"]:""; $ship_re_email=$ship_email; $pet_name=isset($_REQUEST["petName"])?$_REQUEST["petName"]:""; $age=isset($_REQUEST["age"])?$_REQUEST["age"]:''; $age=isset($_REQUEST["age_month"])?$_REQUEST["age_month"]:1; $breed=isset($_REQUEST["breed"])?$_REQUEST["breed"]:""; $nutritional_needs=isset($_REQUEST["nutritionalNeeds"])?$_REQUEST["nutritionalNeeds"]:""; $special_instructions=isset($_REQUEST["specialInstructions"])?$_REQUEST["specialInstructions"]:""; $pet_name2=isset($_REQUEST["petName2"])?$_REQUEST["petName2"]:""; $age2=isset($_REQUEST["age2"])?$_REQUEST["age2"]:""; $age2=isset($_REQUEST["age_month2"])?$_REQUEST["age_month2"]:1; $breed2=isset($_REQUEST["breed2"])?$_REQUEST["breed2"]:""; $nutritional_needs2=isset($_REQUEST["nutritionalNeeds2"])?$_REQUEST["nutritionalNeeds2"]:""; $special_instructions2=isset($_REQUEST["specialInstructions2"])?$_REQUEST["specialInstructions2"]:""; // Products information $product_name=isset($_REQUEST["productname"])?$_REQUEST["productname"]:""; $quantity=isset($_REQUEST["quantity"])?$_REQUEST["quantity"]:0; $price=isset($_REQUEST["price"])?$_REQUEST["price"]:0; $quantity_diff=isset($_REQUEST["quantity_diff"])?$_REQUEST["quantity_diff"]:0; $price_diff=isset($_REQUEST["price_diff"])?$_REQUEST["price_diff"]:0; $sales_tax=isset($_REQUEST["salestax"])?$_REQUEST["salestax"]:0; $subtotal=isset($_REQUEST["subtotal"])?$_REQUEST["subtotal"]:0; $shipping_cost=isset($_REQUEST["shippingcost"])?$_REQUEST["shippingcost"]:0; $total=isset($_REQUEST["total"])?$_REQUEST["total"]:0; // check for login if(isset($_POST['customer_id'])){ $customer_id = $_POST['customer_id']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $login_process = true; $_SESSION['user'] = $customer_id; $row = mysql_fetch_object($result); $fname = $row->fname; $lname = $row->lname; $username=$row->username; } } // Is username taken ? if(!$login_process){ $query = "SELECT * FROM customers WHERE username = '$username'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ array_push($msg,"This username is already taken, please choose another one."); } } if($fname==""){ array_push($msg,"Please Enter First Name."); } if($lname==""){ array_push($msg,"Please Enter Last Name."); } /* if($username==""){ array_push($msg,"Please Enter User Name."); } if(!$login_process){ if($password==""){ array_push($msg,"Please Enter Password."); } if($reenterPassword==""){ array_push($msg,"Please Enter Re-Enter Password."); } if($reenterPassword!=$password){ array_push($msg,"Both passwords does not match."); } }*/ if($address==""){ array_push($msg,"Please Enter Address."); } if($city==""){ array_push($msg,"Please Enter City."); } if($state=="Please choose a state"){ array_push($msg,"Please Select State."); } if($zip==""){ array_push($msg,"Please Enter Zip."); } else { if(!is_numeric($zip)){ array_push($msg,"Please Enter Digits In Zip."); } } if($phone==""){ array_push($msg,"Please Enter Phone."); } else { if(!is_numeric($phone)){ array_push($msg,"Please Enter Digits In Phone."); } } if($email==""){ array_push($msg,"Please Enter Email."); } if($payment==""){ //array_push($msg,"Please Select Payment Method."); } if($paypal_username==""){ // array_push($msg,"Please Enter Paypal User Name."); } if($ship_first_name==""){ array_push($msg,"Please Enter Shipping First Name."); } if($ship_last_name==""){ array_push($msg,"Please Enter Shipping Last Name."); } if($ship_address==""){ array_push($msg,"Please Enter Shipping Address."); } if($ship_city==""){ array_push($msg,"Please Enter Shipping City."); } if($ship_state==""){ array_push($msg,"Please Select Shipping State."); } if($ship_zip==""){ array_push($msg,"Please Enter Shipping Zip."); } else { if(!is_numeric($ship_zip)){ array_push($msg,"Please Enter Digits In Shipping Zip."); } } if($ship_email==""){ // array_push($msg,"Please Enter Shipping Email."); } // Check Captcha $resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); if (!$resp->is_valid) { array_push($msg,"Wrong Captcha, please try again."); } // Insert customer if($login_process){ $sql0 = "UPDATE customers SET address='$address',city='$city', state='$state', zip='$zip', phone='$phone', fax='$fax', email='$email', re_enter_email='$re_enter_email', ship_first_name='$ship_first_name', ship_last_name='$ship_last_name', ship_address='$ship_address', ship_city='$ship_city', ship_state='$ship_state', ship_zip='$ship_zip', ship_email='$ship_email', ship_re_enter_email='$ship_re_email', pet_name='$pet_name', age='$age', breed='$breed', pet_name2='$pet_name2', age2='$age2', breed2='$breed2', age_month='$age_month', age_month2='$age_month2' WHERE customer_id='$customer_id'"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = $customer_id; } }else{ $sql0="INSERT INTO customers (fname, lname,username,password, address, city, state, zip, phone, fax, email, re_enter_email, ship_first_name, ship_last_name, ship_address, ship_city, ship_state, ship_zip, ship_email, ship_re_enter_email , pet_name, age, breed, pet_name2, age2, breed2, age_month, age_month2) VALUES ('$fname', '$lname','$username','$password', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$pet_name2', '$age2', '$breed2', '$age_month', '$age_month2')"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = mysql_insert_id(); } } // Insert Order $sql1="INSERT INTO orders (product_name, customer, quantity, price, sales_tax, subtotal, shipping_cost, total, nutritional_needs, special_instructions, nutritional_needs2, special_instructions2) VALUES ('$product_name', '$customer', '$quantity_diff', '$price_diff', '$sales_tax', '$subtotal', '$shipping_cost', '$total', '$nutritional_needs', '$special_instructions', '$nutritional_needs2', '$special_instructions2')"; if(count($msg) == 0){ $m= mysql_query($sql1) or die("Query Error : " . mysql_error()); } } ?> Hi, I have found myself in a bit of a cul-de-sac. Hope you can help as it is driving me crazy. The scenario: I have an html form (_post) which I would like to write the contents of to a one XML file using php. The problem is: The html page has three/four forms in it. Form a = (submit a writes/updates only to section a) Form b = (submit b writes/updates only to section b) Form c = (submit c writes/updates only to section c) Form d= (submit a, b, c writes/updates all sections) The XML page has three sections a, b & c To conclude, I want to be able to update the XML file in sections or update them all as a whole. How can I go about achieving this? Thanks Hi everyone, I need a little help on making forms that automatically update as you select stuff, For example if you was to select something from a drop down menu, The page will update, And show a new drop down box that will list products compatible with the fiirst product, I could easily add these to arrays, Then the script could just pull from each array. Also I don't know if this will need any javascript... I am no good at that so please warn me if it does! Any kind of help would be highly appreciated, Thanks, Gergy. Hi, I have an HTML form created using Dreamweaver and now I need a script to handle the form processing. Basically what I need is for the form data received from the webpage to be organized in an email and then sent to me. I would also like to display a thank you message in the browser so the user knows it was received. I was planning to do this using CGI but a colleague suggested that CGI is old school and nowadays a developer would use PHP for this task. Is PHP the right solution for this project? The examples I have found so far always include the HTML for the form and the script needed to handle it in one file. In my case, I have an HTML form already in place and need it to work with a script to perform the email function. I know I need to set "Action=" on my webpage to point to the PHP script but what would the code look like if no HTML is needed? I hope this makes sense... Thanks for your help! Rob Creating my own little MVC framework to understand it better. Question - When a view outputs a page with a form in it, how is the form handled? ie, what is the action of the form? Where does the IF statement that checks if the submit button was pressed, go? I was told inside a method in the Model...but I don't understand how a method can check if a form has been submitted or not. Any help greatly appreciated. Good morning, I'm creating a content management system for my game. It's RPG style, so it contains many tasks, however, adding them is a bit complicated process and the system isn't simple. Therefore, simple web form is needed, but there are fields that depend on others. For instance, if quest type is k (which means killing task), a field asking how many different kinds of monsters need to be killed, then there should appear x fields with more specific information. To sum up, i need an example, advice or sth that would help me to create this type of html where new fields appear automatically depending on the chosen ones. Thanks in advance, Karolis Okay, so I'm a relative newbie to PHP. I've been learning for a few months now, and while I get some bits and can fix most of my errors (with a little help from google occasionally), this one's something I can't explain. Basically, I've been building an admin panel so I can edit various content on a website, as you'd gather. It was all going pretty well, until something I did meant that my forms now do nothing. When I press update on the edit forms or add on the...well..add forms, they go back to the prefilled in content. Here is my add form: <?php include('/home/charioti/public_html/andalasia/admin/skin/header.php'); //form not yet submitted //display initial form if (!$_POST['submit']) { ?> <h1>Add Content</h1><div class="cont"> <table align="center"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>Title:</td><td><input type="text" name="title" id="title"></td></tr> <tr><td>Content:</td><td><textarea name="content">text here</textarea></td></tr> <tr><td></td><td><input type="submit" name="submit" value="add"></td></tr></table></form> <?php } else { include('/home/charioti/public_html/andalasia/admin/conf.php'); //set up error list array $errorList = array(); $title = $_POST['title']; $content = $_POST['content']; //validation if(trim($_POST['title']) == '') { $errorList[] = 'Invalid entry: activity name'; } if(trim($_POST['content']) == '') { $errorList[] = 'Invalid entry: answer'; } //check for errors if(sizeof($errorList) == 0) { //db connect $connection = mysql_connect($host, $user, $pass) or die('Unable to connect!'); //db select mysql_select_db($db) or die('Unable to select database!'); //generate and execute query $query = "INSERT INTO info(title, content, date) VALUES('$title', '$content', NOW())"; $result = mysql_query($query) or die("Error in query: $query . " . mysql_error()); // print result echo 'content added! <a href=/admin/index1.php>home</a>'; //close database connection mysql_close($connection); } else { //errors found // print as list echo ' The following errors were encountered:'; echo '<br>'; echo '<ul>'; for($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul>'; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> My header file, incase I've messed something the <? session_start(); if(!session_is_registered(username)){ header("location:/admin/index.php"); } ?> <HTML> <HEAD> <TITLE>Andalasia ~ admin: <?php echo basename($_SERVER["PHP_SELF"]); ?></TITLE> <LINK REL="STYLESHEET" HREF="/admin/skin/style.css" TYPE="TEXT/CSS"> </HEAD> <BODY> <TABLE CLASS="CON"> <TR> <TD> <IMG SRC="/admin/skin/adpo.png" style="border-top:0px solid #A10543"> </TD> </TR> <TR> <TD> <TABLE style="font:8pt arial"> <TR> <TD CLASS="nav" style="width:200px"> <DIV CLASS="navi"> <p class="header">navigation</p> <a href="" target="__blank">Guild HQ</a> <a href="/" target="__blank">Web HQ</a> <a href="/admin/index1.php">Admin HQ</a> <a href="/admin/logout.php">logout</a></DIV> <DIV CLASS="navi"> <p class="header">points</p> <?php include('/home/charioti/public_html/andalasia/admin/points.php')?> </DIV> <DIV CLASS="navi"> <P CLASS="header">update posts</p> <?php include('/home/charioti/public_html/andalasia/admin/news/list.php')?> <a href="/admin/news/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">information posts</p> <?php include('/home/charioti/public_html/andalasia/admin/info/list.php')?> <a href="/admin/info/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">activities</p> <a href="/admin/activities/onsite.php">Onsite activities</a> <a href="/admin/activities/offsite.php">Web-hosted activities</a> <a href="/admin/activities/creative.php">Creative web activities</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">Graphics</p> <h2>Guild layouts</h2> <?php include('/home/charioti/public_html/andalasia/admin/layouts/layl.php')?> <a href="/admin/layouts/add.php">Add layout</a> <h2>Userlookups</h2> <?php include('/home/charioti/public_html/andalasia/admin/lookups/list.php')?> <a href="/admin/lookups/add.php">Add lookup</a> <h2>Banners</h2> <a href="/admin/banners/banners.php">Banners</a> <h2>Fonts</h2> <?php include('/home/charioti/public_html/andalasia/admin/fonts/list.php')?> <a href="/admin/fonts/add.php">Add font</a></DIV> <DIV CLASS="navi"> <P CLASS="header">Members</p> <?php include('/home/charioti/public_html/andalasia/admin/users/list.php')?> <a href="/admin/users/add.php">Add user</a> </DIV> <DIV CLASS="navi"> <!-- BEGIN CBOX - www.cbox.ws - v001 --> <div id="cboxdiv" style="text-align: center; line-height: 0"> <div><iframe frameborder="0" width="200" height="305" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=main" marginheight="2" marginwidth="2" scrolling="auto" allowtransparency="yes" name="cboxmain" style="border:#11011A 1px solid;" id="cboxmain"></iframe></div> <div><iframe frameborder="0" width="200" height="75" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=form" marginheight="2" marginwidth="2" scrolling="no" allowtransparency="yes" name="cboxform" style="border:#11011A 1px solid;border-top:0px" id="cboxform"></iframe></div> </div> <!-- END CBOX --> </DIV> </TD> <TD CLASS="c" VALIGN="TOP" style="width:600px"> And my edit file: <? // edit.php - edit a layout ?> <!-- page header - snip --> <? // includes include("/home/charioti/public_html/andalasia/admin/skin/header.php"); include("/home/charioti/public_html/andalasia/admin/conf.php"); // form not yet submitted // display initial form with values pre-filled if (!isset($_POST['submit'])) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $id = mysql_escape_string($_GET['id']); $query = "SELECT title, content, id FROM info WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); // print form with values pre-filled ?> <h1>Update post - ID <? echo $id; ?></h1> <div class=cont> <table class=view align=center> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<? echo $id; ?>"> <tr> <td valign="top"><b>Title</b></td> <td><input size="50" maxlength="250" type="text" name="title" value="<? echo $row->title; ?>"></td> </tr> <tr> <td valign="top"><b>Content:</b></td> <td><textarea name=content><? echo $row->content; ?></textarea></td> </tr> <tr> <td colspan=2><input type="Submit" name="submit" value="Update"></td> </tr> </form> </table> </div> <? } // no result returned // print graceful error message else { echo "<h1>Error!</h1><div class=cont>That post could not be located in our database.</div>"; } } else { // form submitted // start processing it // set up error list array $errorList = array(); $count = 0; // validate text input fields $title = mysql_escape_string($_POST['title']); $content = mysql_escape_string($_POST['content']); $id = mysql_escape_string($_POST['id']); if (!$title) { $errorList[$count] = "Invalid entry: title"; $count++; } if (!$content) { $errorList[$count] = "Invalid entry: content"; $count++; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $query = "UPDATE info SET title = '$title', content = '$content' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // print result echo "<h1>Success!</h1><div class=cont>Update successful. <a href=/admin/index1.php>Go back to the main menu</a>.</font></div>"; // close database connection mysql_close($connection); } else { // errors occurred // print as list echo "<h1>Errors:</h1><div class=cont><font size=-1>The following errors were encountered: <br>"; echo "<ul>"; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo "</ul></font></div>"; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> I started off working with templates from my book and from various sources, so I've tried reseting my pages to those and reworking them, and I've deduced that it's probably something to do with my header file, I just can't work out what or whereabouts the problem is. Any help you can offer would be greatly appreciated. (: I am quite new to this and am working on a site of my own. I am wanting to input data into a database based on the values of two textboxes. I have the general engine set up but there are some problems. For example when I do the INSERT with values such as: mysql_query("INSERT INTO PageTable (uniqueid, ImageLink, ImageLink2, IP) VALUES ('3434343', 'http://www.example.com/1.jpg', 'http://www.example.com/1.jpg', '94.123.123.9')"); This will go into the database perfectly. However if I do this: mysql_query("INSERT INTO PageTable (uniqueid, ImageLink, ImageLink2, IP) VALUES ($random2, $img1, $img2, $ip)"); Where random2 is rand() and img1 and img2 are the values of the text boes and ip is the ip of the user. When I do this there is no insert into the database. Another thing I noticed was that if I put in '111111111111111111' into the textbox the value in the database is something like 111111111111111.0904039 or something like that, however if I put '111111111111111111' into the INSERT statement it goes into the database perfectly. Also if I put '1' into the textbox it goes in fine but putting 'a' into the textbox and it doesn't! I am sure I am missing something very very basic but I just can't get my head round this! Any help would be much appreciated. So I made the code as simple as possible to avoid any confusing crap: scripttest.php: Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); $idcol=7; $j=0; $b=1; mysql_select_db($dbname); $queryj = "SELECT name FROM IMPrints"; $resultj = mysql_query($queryj); $num=mysql_num_rows($resultj); while($j<$num){ $Column = mysql_result($resultj, $j); echo $Column; $queryb = "SELECT * FROM IMBuilt WHERE idcol=$idcol"; $resultb = mysql_query($queryb); $built = mysql_fetch_row($resultb); include("mysqltest.php"); $j++; $b++; } ?> mysqltest.php: Code: [Select] <?php if($_POST) { $povar = $built[$b]+$_POST["built"][$j]; $queryi="UPDATE IMBuilt SET $Column = $povar WHERE idcol = $idcol"; mysql_query($queryi); } echo $povar; ?> <form class="bd" method="post" action="scripttest.php"><input type="text" name="built[]"><input type="submit" value="Build"></form> Everything mostly looks fine except one thing: If I set name="built" than no matter what form i enter the value to be added in, it affects all the values. If I set name="built[]" then no matter what form i enter the value to be added in, it only affects the first value. Currently in the table there are 4 columns. Each form is supposed to edit the column value where idcol=6. So the first one edits column Basic in the row where idcol is 6. A value input in the second for should be added to the current value for Column Advanced where idcol=6. But I can't get the forms, which are produced by the loop, to edit the column they are paired with. In the display in the broswer it lists the column value correctly over each form and also the current value in the table. next to the column. But it doesn't change the right columns. Hi, I am fairly new to php and I wanted to know whether you could validate a "input type = text ". I have made a class where i've made functions to validate test fields but i dont know how to call them with the html form. Any suggestions or tips .... Thanks in advance. Ok here are two of my form codes: Basically I like to use if/elseif, can someone please explain to me how these two form here can combine together so it will only have one form but do two different function (create and modify form). Then after these form being edit or create - it will go to another different page which is the confirmation page using sessions. modify form code <?php require 'includes/application.php'; //Define $name = ""; $surname = ""; $add = ""; $dept= ""; $mobile = ""; if (!isset($_POST['goSubmit'])) { $q = "SELECT * FROM persons WHERE ID = $_GET[id]"; $result = mysql_query($q) or die (mysql_error()); $row = mysql_fetch_array($result); $name = $row['name']; $surname = $row['surname']; $address = $row['address']; $dept = $row['dept_id']; $mobile = $row['mobile']; } $errormsg = ""; if($name == "") $errormsg = $errormsg. "Name<br/ >"; if ($surname == "") $errormsg = $errormsg. "Surname Please <br/ >"; if ($mobile != "" && !is_numeric ($mobile)) $errormsg = $errormsg. "Mobile No? <br/ >"; if ($errormsg != "") echo "Please fill the blank info: <br/ > $errormsg"; else { $input_field = ""; foreach ($_POST as $key => $val) { if ($key != 'goSubmit') { $_SESSION[$key] = $val; } } header("Location: confirmPage.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Modify Document</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="center"> <table width="300" border="1"> <h1> Modifying A User </h1> <tr> <th scope="row">Name</th> <td><input type="text" name="name" value="<?php echo $name;?>" /></td> </tr> <tr> <th scope="row">Surname</th> <td> <input type="text" name="surname" value="<?php echo $surname; ?>" /></td> </tr> <tr> <th scope="row">Address</th> <td><input type="text" name="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <th scope="row">Department</th> <td> <select name="dept"> <option value="">Select..</option> <?php $data = mysql_query ("SELECT * FROM dept ORDER BY `id` DESC") or die (mysql_error()); echo $data; while($row_dept = mysql_fetch_array( $data )) { ?> <option value="<?php echo $row_dept['id'] ;?>" <?php if($row_dept['id']==$dept){echo ' selected="selected"';}?>> <?php echo $row_dept['dept_name'] ;?> </option> <?php } ?> </select> </td> </tr> <tr> <th scope="row">Mobile</th> <td><input type="text" name="mobile" value="<?php echo $mobile; ?>" /></td> </tr> </table> <br/> <a href="indexPage.php"> <input type="button" name="back" value="Back" /></a> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"> <input type="submit" name="goSubmit" value="Modify"/> </div> </form> </body> </html> create form page <?php require 'includes/application.php'; //Define $name = ""; $surname = ""; $address = ""; $dept= ""; $mobile = ""; // isset determine if a varaible is set if (isset($_POST['goSubmit'])) { $name = $_POST['name']; $surname = $_POST['surname']; $address = $_POST['address']; $dept = $_POST['dept']; $mobile = $_POST['mobile']; print_r($_POST); $errormsg = ""; if($name == "") $errormsg = $errormsg. "Name<br/ >"; if ($surname == "") $errormsg = $errormsg. "Surname Please <br/ >"; if ($mobile != "" && !is_numeric ($mobile)) $errormsg = $errormsg. "Mobile No? <br/ >"; if ($errormsg != "") echo "Please fill the blank info: <br/ > $errormsg"; else { $input_field = ""; foreach ($_POST as $key => $val) { if ($key != 'goSubmit') { $_SESSION[$key] = $val; } } header("Location: confirmPage.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Modify Document</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="center"> <table width="300" border="1"> <h1> Modifying A User </h1> <tr> <th scope="row">Name</th> <td><input type="text" name="name" value="<?php echo $name;?>" /></td> </tr> <tr> <th scope="row">Surname</th> <td> <input type="text" name="surname" value="<?php echo $surname; ?>" /></td> </tr> <tr> <th scope="row">Address</th> <td><input type="text" name="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <th scope="row">Department</th> <td> <select name="dept"> <option value="">Select..</option> <?php $data = mysql_query ("SELECT * FROM dept ORDER BY `id` DESC") or die (mysql_error()); echo $data; while($row_dept = mysql_fetch_array( $data )) { ?> <option value="<?php echo $row_dept['id'] ;?>" <?php if($row_dept['id']==$dept){echo ' selected="selected"';}?>> <?php echo $row_dept['dept_name'] ;?> </option> <?php } ?> </select> </td> </tr> <tr> <th scope="row">Mobile</th> <td><input type="text" name="mobile" value="<?php echo $mobile; ?>" /></td> </tr> </table> <br/> <a href="indexPage.php"> <input type="button" name="back" value="Back" /></a> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"> <input type="submit" name="goSubmit" value="Modify"/> </div> </form> </body> </html> I was thinking something like these condition to do the forms but I am not exactly sure... - But after this page another confirmation page will appear once the button submitted is click. if (isset($_GET['id']) == $id) { //do the modify query //display the modify form } else if (isset ($_GET ['id'] == NULL) { //display the form where user can fill up the form } OR, can I do like this instead: if (isset ($_GET['id'])) { $_SESSION ['page'] = 'modify'; //perform the modify form } else if (isset($_GET['id'])) { $_SESSION ['page'] = 'create'; //perform the create form } Any inputs would be appreciated... Info: When Customer clicks the "Add More Stuff" button on "/merchandise.php" to add more stuff, modify quantities, etc., the page submits to itself. Desired: I want a "FINISHED" button on the bottom of the page. When clicked on, Customer lands on a Thank You, "/FINISHED.php" page. Problem: The <form action="FINISHED.php"....> does not have access to the variables in the first form <form action="$_SERVER['PHP_SELF']">. Question: Using Sessions, javascript, or fancy PHP, is there a way the 2nd form can capture all the data from the first form, so when Customer clicks the FINISHED button, all the variables are sent to the FINISHED.php page?
Like: Reasons: There are too many PHP and Javascript variables created in the first form, many of which I don't understand, it would take me the rest of year 2019 to go line by line and rewrite all of the code. Requisite whining: Some code is beyond my skill level. For example, when the customer increases a quantity from "1" to "2" javascript will instantly change the displayed dollar-amount from $1.00 to $2.00 without actually "submitting/refreshing" the entire page. Though the displayed amount changes visually, the PHP $variable remains what it was until the page submits to itself. That means I cannot use $_SESSION to capture the newly-displayed amount until the page resubmits to itself. I've tried everything I can think of.... the closest solution I've found is the new HTML5 "formaction" tag, but I'm looking for a more universal solution (doesn't work in all browsers). Thank you!!
Edited February 28, 2019 by StevenOliver |