PHP - Php Mysql Forms - Only Allow Numbers In A Textfield
Hey again guys! I'm back already today. XD Okay, so... I'm building a script, right. I have a form that is a simple text field. I do NOT want to use javascript. I want to be able to use PHP to be able to do this. Here is the form exactly as it is now:
Code: [Select] <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="text" name="price"> How would I only allow a number, and up to 5 digits long, like, for example, a zip code. I know I can always limit the char space, but they might be able to "inject" it? On another note for forms, what would I have to do to get rid of people being able to run a script through a form; is it the strip_tags(); function? Thanks for your help in advance guys! Similar TutorialsMy employer asked if I could change an existing contact form on their website to allow clients to enter their Social Security Number along with the normal contact information if the client decide to do so, instead of going through the motion of physically send in the form via snail mail, fax, or in person (like it is currently handled). But since this piece of information is of such delicate nature, I wonder how I should approach this from both a legal standpoint and from a programming standpoint. The form currently sends the information entered by the user to an inbox with mail(), so my initial thought was to somehow encrypt the information, limiting the risk of someone getting a hold of this information once the use user clicks "Send". But is full blown SSL really necessary for this? Are there easier options? And what should I think about before enabling this? Hello, i'm trying to server-side validate input from POST to insert it into mysql if the requirements for the insert are met. i was using jquery before but this isn't reliable at all, i want the data to get inserted into mysql only if the length is 19 chars and only if it starts with 3227580 the next 12 digits can be any number. So basically: IF chars=19 and data=3227580* insert into mysql -- else show error Thank you for help. Say I do a query from a database that only asks for one field in return (which always has a number in it). How do you write the PHP to take the first number returned and add it to the next number returned (NOTE: There may be more than two numbers returned, but for now, I'm always dealing with two) For example, say I do a query that returns the number 27 first and then the number 10 second. FYI, these numbers will be available in the variable $diff['result']. So the code after the query would look something like this, but obviously i'm struggling with the part in comments... Code: [Select] if (!$numbers) { die("Database query failed: " . mysql_error()); } else { while ($diff = mysql_fetch_array($numbers)) { //this would bring back 27 first, in the variable $diff['result'] and then on the 2nd loop through, it would bring back 10 in the $diff['result'] variable //ultimately, i just want the difference between the numbers (which in the case would be 17). It's just a simple addition, so Im obviously an idiot because I can't figure out the syntax for adding the first returned number to the next returned number:) } } The Script:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="text" name="hashtags" /> <input type="submit" name="submit" /> </form> <?php include("connect.php"); ?> <?php if(isset($_POST['submit'])){ $hashtags = explode(", ", $_POST['hashtags']); for($i= 0; $i < count($hashtags); $i++){ $tqs = "SELECT `id` FROM `hashtags_two` WHERE `hashtags` = '" . $hashtags[$i] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } $fetch_array = array(); while($row = mysqli_fetch_array($tqr)){ $fetch_array[] = $row['id']; } }Hey, sorry for these fundamental array questions lately, I am not going to ask much more when it comes to this. The hashtags come from the submit form (separated by commas) and get stored inside an array with the "explode()" function. The script should select the ID numbers of the hashtags from the table. With the script above only the last row gets inserted into $fetch_array inside the while loop. When the $fetch_array variable is printed on screen then only one ID number can be seen inside the array: Array ( [0] => 24 )How can I have the other ID numbers too? I need help I am retrieving rows from MySQL table now what I want is that as rows retrieved with each row and edit button will insert but i don't know how to insert here is my code <?php require('connect.php'); session_start(); $query="SELECT * FROM project WHERE projectstatus='Open'"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0;$j=1; while ($i < $num) { $projectid=mysql_result($result,$i,"projectid"); $fkey=mysql_result($result,$i,"fkey"); $paying=mysql_result($result,$i,"paying"); $completionmonth=mysql_result($result,$i,"completionmonth"); $completiondate=mysql_result($result,$i,"completiondate"); $personspecify=mysql_result($result,$i,"personspecify"); $projecttitle=mysql_result($result,$i,"projecttitle"); $categories=mysql_result($result,$i,"categories"); $tools=mysql_result($result,$i,"tools"); $shortdescription=mysql_result($result,$i,"shortdescription"); $date=mysql_result($result,$i,"date"); $time=mysql_result($result,$i,"time"); $i++; echo "<br>".$j."<br>"; echo "<br>".$projectid."<br>"; echo "<br>".$fkey."<br>"; echo "<br>".$paying."<br>"; echo "<br>".$completionmonth.' month '.$completiondate.' days '."<br>"; echo "<br>".$personspecify."<br>"; echo "<br>".$projecttitle."<br>"; echo "<br>".$categories."<br>"; echo "<br>".$tools."<br>"; echo "<br>".$shortdescription."<br>"; echo "<br>".$date."<br>"; echo "<br>".$time."<br>"; echo "<br>"."<br>"."<br>"; // I want to insert edit button here but dont know how echo "------------------------------------------------------------------------"."<br>"; $j++; } ?> </body> </html> Edited by requinix, 11 June 2014 - 01:09 PM. please use [code] tags when posting code Hi, I am trying to write an input form for a table that the fields contains codes of records from other tables. Is there a way that after each field I can retrieve (validate) the value of the fields that contain a code from a table and display them on the screen when the use move to the next field? The table is a customers order and I want to validate and display the customer name after they key in the customer code and the same for the product's code. Thank! James Hi all I am trying to take the data from a form and add into a mySQL table. I have multiple forms on one page that uses a loop: Code: [Select] <?php $textqty = $showbasket['qty']; for ($i = 1; $i <= $textqty ; $i++) { ?> <form id="texts" name="texts" method="post" action=""> <input name="mainqty" type="hidden" value="<?php echo $textqty; ?>" /> <input name="productid" type="hidden" value="<?php echo $showbasket['productid']; ?>" /> <input name="productqtyid" type="hidden" value="<?php echo $i; ?>" /> <input name="productsize" type="hidden" value="<?php echo $showbasket['size']; ?>" /> Text: <input name="text_<?php echo $i; ?>" type="text" value="<?php echo $showtext['text']; ?>" size="35" maxlength="250" /> Colour: <select name="colour"> <?php $getcolours = mysql_query(" SELECT * FROM text_colours ORDER BY id ASC"); while($showcolours = mysql_fetch_array($getcolours)) { ?> <option value="<?php echo $showcolours['colour']; ?>"><?php echo $showcolours['colour']; ?></option> <?php } ?> </select> No. Characters: <br /> <?php } ?> <input name="update" type="submit" id="update" value="Update" /> </form> This data is then inserted into the mySQL: Code: [Select] <?php if(isset($_POST['update'])) { $mqty = $_POST['mainqty']; for ($i = 1; $i <= $mqty ; $i++) { $productid = $_POST['productid']; $productqtyid = $_POST['productqtyid']; $productsize = $_POST['productsize']; $colour = $_POST['colour']; $producttext = $_POST['text_$i']; mysql_query (" INSERT INTO emb_texts SET sessionid = '".$sessionid."', productid = '".$productid."', qtyid = '".$productqtyid."', size = '".$productsize."', colour = '".$colour."', text = '".$producttext."'") or die(mysql_error()); } } ?> This almost works but it adds the $productqtyid the same very time. I'm not sure if I am going about the the right way? Each form needs to add its own values into the mySQL. Many thanks for your help I have the following code, (I'm sorry it's so long an it does more that the question asks.) It's ment to edit, delete and make new links in a mysql database, by also using a link header to home all the links (Like a dropdown menu) And thig manages the links. However then the update, or when the new form is submitted it leaves then titlereg field blank. (The titlereg is the id of the main link, it's called reg in the title_reg database) I know this is complicated and i'm not too good at explaining the problem but any help would be great. I have commented on anything that could help. <?php include "../includes/mysql_connect.php"; include "../includes/info_files.php"; echo "<strong>Links</strong><br />"; echo "Currect links:<br /><br />"; if($_POST['submit']){ $name = mysql_real_escape_string($_POST['name']); $titlereg = mysql_real_escape_string($_POST['titlereg']); $url = mysql_real_escape_string($_POST['url']); $id = mysql_real_escape_string($_POST['id']); mysql_query("UPDATE nav_sub SET name='$name', SET titlereg='$titlereg', SET url='$url' WHERE reg='$id'"); ////////////////////////////////// Here will help, the update MY SQL thingie echo "Link Changed.<br /><br />"; } elseif($_POST['remove']){ $id = mysql_real_escape_string($_POST['id']); mysql_query("DELETE FROM nav_sub WHERE reg='$id'"); echo "Link deleted.<br /><br />"; } else{ $result = mysql_query("SELECT * FROM nav_sub"); while($row = mysql_fetch_array($result)) { echo '<strong>' . $row['name'] . '</strong>'; echo '<form action="" method="post">'; echo 'Name: <input type="text" name="name" value="' . $row['name'] . '" /><br />'; echo 'Link: <input type="text" name="text" value="' . $row['url'] . '" /><br />'; echo 'Navigation title: <select name="titlereg">'; $resultabc = mysql_query("SELECT * FROM nav_title"); while($rowabc = mysql_fetch_array($resultabc)) { echo '<option value="' . $rowabc['reg'] . '">' . $rowabc['name'] . '</option>'; ////////////////////////////////// Here is the option } echo '</select>'; echo '<input type="hidden" name="id" value="' . $row['reg'] . '" />'; echo '<input type="submit" name="submit" value="Change" /> <input type="submit" name="remove" value="Remove" /><br />'; echo '</form>'; } } echo "New link:<br /><br />"; if($_POST['new_submit']){ ////////////////////////////////// Here!!!!!!!!!!!!!!! $result = mysql_query("SELECT * FROM nav_sub"); $new_titlereg = $_POST['new_titlereg']; $new_name = mysql_real_escape_string($_POST['new_name']); $new_url = mysql_real_escape_string($_POST['new_url']); mysql_query("INSERT INTO `nav_sub` (`titlereg` ,`reg` ,`name` ,`url`)VALUES ('$new_titlereg', '', '$new_name', '$new_url')"); ////////////////////////////////// here is the MY SQL statement... echo "Link added.<br /><br />"; } echo '<form action="" method="post">'; echo 'Name: <input type="text" name="new_name" value="" /><br />'; echo 'Url: <input type="text" name="new_url" value="" /> \\\\ If your linking to a page you made, then the url is index.php?catt=(The categrory you put)&page=(The page you put)<br />'; echo 'Navigation title: <select name="new_titlereg">'; $resultab = mysql_query("SELECT * FROM nav_title"); while($rowab = mysql_fetch_array($resultab)) { echo '<option value="' . $rowab['reg'] . '">' . $rowab['name'] . '</option>'; ////////////////////////////////// Here isn't submitting the value in the option } echo '</select>'; echo '<input type="submit" name="new_submit" value="Insert" /><br />'; echo '</form>'; ?> By the way, explain simply as I'm only 13 I have two webpages, login_success.php and formentered.php login_success.php is a page where i am entering new information and enteredvalues.php is supposed to be a script to enter the information into mysql. So far I got the login_success page to redirect to enteredvalues.php when submit is clicked but the information in the fields isn't transferring to mysql and neither is the page redirecting back to login_success. Here are both my codes Login_success.php <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html><title>ChronoServe - Saving Time</title> <link href="style.css" rel="stylesheet" type="text/css"> <body> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="container"> <tr> <td><form name="form2" method="post" action="entervalues.php"> <table width="335px" height="50%" border="1" align="center" cellpadding="0" cellspacing="0" class="centered"> <tr> <td><table width="100%" border="0" align="center" cellpadding="3" cellspacing="10"> <tr> <td colspan="2"><div align="center" class="font2">Activation Information</div></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td width="40%" class="font3">First Name :</td> <td width="60%"> <div align="center"> <input name="firstname" type="text" class="font3" id="firstname" /> </div></td> </tr> <tr> <td class="font3">Last Name :</td> <td> <div align="center"> <input name="lastname" type="text" class="font3" id="lastname" /> </div></td> </tr> <tr> <td height="28" class="font3">Phone Number :</td> <td> <div align="center"> <input name="pnumber" type="text" class="font3" id="pnumber" /> </div></td> </tr> <tr> <td class="font3">Personnel Activated :</td> <td> <div align="center"> <input name="numbactivated" type="text" class="font3" id="numbactivated" /> </div></td> </tr> <tr> <td height="37" colspan="2"></td> </tr> <tr> <td colspan="2"><div align="center"> <input name="insert" type="submit" class="font3" value="Submit" /> </div></td> </tr> </table></td> </tr> </form> </table> </td> </tr> </table> </body> </html> Here is enteredvalues.php <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $pnumber=$_POST['pnumber']; $numberactivated=$_POST['numberactivated']; // To protect MySQL injection (more detail about MySQL injection) $firstname = stripslashes($firstname); $lastname = stripslashes($firstname); $firstname = mysql_real_escape_string($firstname); $lastname = mysql_real_escape_string($lastname); $pnumber = stripslashes($pnumber); $numberactivated = stripslashes($numberactivated); $pnumber = mysql_real_escape_string($pnumber); $numberactivated = mysql_real_escape_string($numberactivated); $sql="INSERT INTO $tbl_name (firstname, lastname, pnumber, numberactivated,) VALUES ('$firstname','$lastname','$pnumber','$numberactivated')")or die(mysql_error()); $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; header("location:login_success.php"); exit(); } ?> Hello everyone, I'm a newbie with PHP and mySQL and need some assistance with writing a php script that searches a mySQL database using a form. The form has five fields that I want to search from and one is a required field (State). I need to filter or narrow down the search by either two or more fields. The problem I am having is if I used multiple WHERE clauses using the AND condition I have to enter valid information in all five fields and if I use the OR condition then my search does not produce the desired outcome (too many results). I "think" I need to use the AND condition but I need to be able to leave some of the fields blank (except for the State field) and narrow my search with using anywhere from 2-5 search fields. Also, another requirement is to be able to enter partial information in the search field "without" having to enter a wildcard in the search field. Any assistance is very much appreciated and thanks in advance for your help. Form Fields: State SELECT FIELD Lease TEXT FIELD Operator Name TEXT FIELD County or Parish TEXT FIELD Well No TEXT FIELD I have a table called well_permits and it is structure is as follows: date DATE state TEXT county VARCHAR api VARCHAR permit_no VARCHAR operator VARCHAR phone VARCHAR contact VARCHAR lease VARCHAR well_no VARCHAR permit_for VARCHAR welltype VARCHAR wellspot VARCHAR lat FLOAT lon FLOAT depth VARCHAR This is what I have for the connecting to my database and selecting the fields: <?php require_once('../../../Connections/Wldatabase.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; //Variable to store Unique_ID aka API which will be passed to the well-search-results.php page $var_api_rs_search = $_Get['api']; $maxRows_rs_search = 20; $pageNum_rs_search = 0; if (isset($_GET['pageNum_rs_search'])) { $pageNum_rs_search = $_GET['pageNum_rs_search']; } $startRow_rs_search = $pageNum_rs_search * $maxRows_rs_search; $var_state_rs_search = "%"; if (isset($_GET['state'])) { $var_state_rs_search = $_GET['state']; } $var_lease_rs_search = "%"; if (isset($_GET['lease'])) { $var_lease_rs_search = $_GET['lease']; } $var_well_no_rs_search = "%"; if (isset($_GET['well_no'])) { $var_well_no_rs_search = $_GET['well_no']; } $var_operator_rs_search = "%"; if (isset($_GET['operator'])) { $var_operator_rs_search = $_GET['operator']; } $var_county_rs_search = "%"; if (isset($_GET['County'])) { $var_county_rs_search = $_GET['County']; } mysql_select_db($database_Wldatabase, $Wldatabase); $query_rs_search = sprintf("SELECT DISTINCT * FROM well_permits WHERE (well_permits.`state` LIKE %s AND well_permits.county LIKE %s) OR (well_permits.lease LIKE %s) OR (well_permits.operator LIKE %s) OR (well_permits.well_no LIKE %s) ORDER BY well_permits.county", GetSQLValueString($var_state_rs_search, "text"),GetSQLValueString($var_county_rs_search, "text"),GetSQLValueString($var_lease_rs_search, "text"),GetSQLValueString($var_operator_rs_search, "text"),GetSQLValueString($var_well_no_rs_search, "text")); $query_limit_rs_search = sprintf("%s LIMIT %d, %d", $query_rs_search, $startRow_rs_search, $maxRows_rs_search); $rs_search = mysql_query($query_limit_rs_search, $Wldatabase) or die(mysql_error()); $row_rs_search = mysql_fetch_assoc($rs_search); ?> This is my form: <form action="search.php" method="GET" name="frmsearch" target="_self"> <input name="api" type="hidden" value="" /> <div> <table width="900" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td colspan="6"> <p style="text-align:left">Select a State then enter at least one search criteria. State is a required field.</p> * Denotes a required field.<br> </td> </tr> <tr> <td align="right">* State: </td> <td> <select name="state" size="1" dir="ltr" lang="en"> <option value="AL">AL</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="MI">MI</option> <option value="MS">MS</option> <option value="MT">MT</option> <option value="ND">ND</option> <option value="NE">NE</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OS">OS</option> <option value="PA">PA</option> <option value="SD">SD</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="WV">WV</option> <option value="WY">WY</option> </select> </td> <td align="right">County or Parish: </td> <td align="left"><input name="County" type="text" value="" size="35" maxlength="40" /></td> </tr> <tr> <td width="63" align="right">Lease: </td> <td width="239"><input name="lease" type="text" value="" /></td> <td align="right">Well No: </td> <td><input name="well_no" type="text" value="" /></td> </tr> <tr> <td width="111" align="right">Operator Name: </td> <td width="261"><input name="operator" type="text" value="" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td align="left"><input name="search" type="submit" value="Search" /></td> </tr> </table> </form> My Repeat Region starts here <table width="100%" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td align="right"> </td> <th align="center">Operator</th> <th align="center">Lease</th> <th align="center">Well Number</th> <th align="center">County</th> <th align="center">State</th> </tr> <tr> <?php do { ?> <td align="center"><a href="results.php?recordID=<?php echo $row_rs_search['api']; ?>">Select</a></td> <td align="left"><?php echo $row_rs_search['operator']; ?></td> <td align="left"><?php echo $row_rs_search['lease']; ?></td> <td align="center"><?php echo $row_rs_search['well_no']; ?></td> <td align="center"><?php echo $row_rs_search['county']; ?></td> <td align="center"><?php echo $row_rs_search['state']; ?></td> </tr> <?php } while ($row_rs_search = mysql_fetch_assoc($rs_search)); ?> </table> <p align="center">Number of Wells Located: <?php echo ($startRow_rs_search + 1) ?> to <?php echo min($startRow_rs_search + $maxRows_rs_search, $totalRows_rs_search) ?> of <?php echo $totalRows_rs_search ?></p> <table border="0" align="center"> <tr> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, 0, $queryString_rs_search); ?>">First</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, max(0, $pageNum_rs_search - 1), $queryString_rs_search); ?>">Previous</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, min($totalPages_rs_search, $pageNum_rs_search + 1), $queryString_rs_search); ?>">Next</a> <?php } // Show if not last page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, $totalPages_rs_search, $queryString_rs_search); ?>">Last</a> <?php } // Show if not last page ?></td> </tr> </table> Guys, quick one. Im writing a script for a form to post info into a MySql table. Now rather than just having a single row for input I'd like to have lets say 10 rows, so I can add 10 records to the database. What I'm pondering is 2 things: 1: can i just repeat Code: [Select] <input type="text" name="opponent" size="27" /> over and over, or is it going to need its own name each time for example; Code: [Select] <input type="text" name="opponent2" size="27" /> <input type="text" name="opponent3" size="27" /> 2: when it comes to the processing script is it more economical to have the forms input field named the same over and over (if it IS possible) and if not whats the most econimcal way to code my Code: [Select] $opp= $_POST['opponent']; $query="INSERT INTO fixtures (match_date, season, opponent) VALUES ('$date', '$season', '$opp',)"; Your help and comments are appreciated as always guys Tom Hi, I know this has to be possible but I have been unable to get this to work properly. I have a page with two forms. The first form is a list of sources associated with a subject, with checkboxes, so that it is possible to remove these associations, like so: Code: [Select] $qs = "SELECT s.source_id, s.source_name from source s, source_subject ss, subject sb where s.source_id = ss.source_id and sb.subject_id = ss.subject_id and sb.subject_id = $subject_id order by source_name"; $rs = mysqli_query($dbc, $qs) or die ('Error querying database'); while($row = mysqli_fetch_array($rs)) { echo '<input type="checkbox" value="' . $row['source_id'] . '" name="markdelete[]">' . $row['source_name'] . '<br />' ; } The second form is a list of sources that are not associated with this subject, with checkboxes enabling the addition of more sources to this subject, like so: Code: [Select] $r = "SELECT source_id, source_name FROM source WHERE source_id NOT IN (select s.source_id from source s, source_subject ss where s.source_id = ss.source_id and ss.subject_id = '$subject_id')"; $r1 = mysqli_query($dbc, $r) or die ('Update Error: '.mysqli_error($dbc)); while ($row = mysqli_fetch_array($r1)) { echo '<input type="checkbox" id="source_id" name="source_id[]" ' ; echo 'value="'. $row['source_id'] .'"'; echo '> ' . $row['source_name'] . '<br />'; } The first form works fine... when the "remove" submit button is clicked, it successfully removes any selected sources and then shows the remaining sources still associated, and then automatically populates this source in the below list (form 2) as one that is not selected. On the second form, when adding a new source to the subject, it successfully enters the data into the database, and removes this source from the list of unselected sources, but it does not seem to re-populate in the first form. The data is correct on the tables, but the page needs to reload the first query... how do I get it to do this? I'd like to be able to make this page editable, and re-editable (in case someone makes a mistake) without having to go back and reload the entire page. Note, both forms call the page itself; not sure if this is part of it. Using this: Code: [Select] <form method="POST" action="<?php echo $_SERVER['PHP_SELF'].'?subject_id='.$subject_id ; ?>"> Does anyone have any ideas? Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim Hello everyone, We have written a code to make a translator of the Caesarcode. But we don't know how we put the code working on the textfield. We tried by ourselves but it doesn't work. So we are asking where and which code we have to put in to the html textfield. This is our code: <?php class CaesarCode { private static $alfabetUpper; private static $alfabetLower; private $steps; private function _getNewPosition($originalPosition) { return ($originalPosition + $this->steps) % 26; } private function _getCharFromArray($char, $fromArray) { if (($charKey = array_search($char, $fromArray)) !== false) { return $fromArray[$this->_getNewPosition($charKey)]; } return false; } private function _translateChar($char) { $translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetUpper()); if ($translatedChar === false) { $translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetLower()); } return $translatedChar; } private function _getAlfabetUpper() { if (empty(self::$alfabetUpper)) { self::$alfabetUpper = range('A', 'Z'); } return self::$alfabetUpper; } private function _getAlfabetLower() { if (empty(self::$alfabetLower)) { self::$alfabetLower = range('a', 'z'); } return self::$alfabetLower; } public function __construct($steps) { $this->steps = $steps; } public function translate($string) { $encr = ''; foreach (str_split($string) as $key => $char) { if (($newChar = $this->_translateChar($char)) !== false) $char = $newChar; $encr .= $char; } return $encr; } } ?> And this is the html code: <?php // de class CaesarCode beschikbaar maken in dit bestand include 'caesarcodephp.php'; $caesarCode = new CaesarCode( 1 ); // de uitkomst opslaan in de variabele $result $result = $caesarCode->translate( 'ABC' ); ?> <!doctype html> <html> <head> <title>oefen</title> </head> <body> <table border="1"> <tr> <tr><td>Rotation:</td> <td> <select> <option value ="1"><?php $caesarCode= new CaesarCode( 1 ); ?> 1 </option> <option value ="2"><?php $caesarCode= new CaesarCode( 2 ); ?>2 </option> <option value ="3"><?php $caesarCode= new CaesarCode( 3 ); ?>3</option> <option value ="4"><?php $caesarCode= new CaesarCode( 4 ); ?>4</option> <option value ="5">5</option> <option value ="6">6</option> <option value ="7">7</option> <option value ="8">8</option> <option value ="9">9</option> <option value ="10">10</option> </select> </tr> <tr> <textarea rows="10" cols="20" style="overflow:hidden;"> <?php echo $caesarCode->translate( 'XYZ' ); ?> INPUT TEXT?? </textarea> <p style="font-size:10px;"></p> <textarea rows="10" cols="20" style="overflow:hidden;"> Output text</textarea> <p style="font-size:10px;"></p> </tr> <tr> <td>Result</td> <td><?php echo $result ?></td> </tr> </table> </body> </html> Thank you very much! I am looking for some info on creating a textfield /dropdown menu that works just like a standard browser: when you type in something in the textfield/dropdown it should show results (this is needed to quickly find a member) eg. I type "use" and dropdown should contain members(results) starting with "use" (user1, user2 ...) Anyone know where I can find info on this? how do i limit this textfield to three strings? Code: [Select] <input type='text' size='40' name='search' style='font-size:16px; font-family:Arial;font-weight:bold;' /> is this php or javascript? i want only three strings to be allowed entered. I hope this is a fairly quick one, I've got a form I'm building where i may well have some special characters being inserted (accents mostly) now normally i would just pop in an HTML editor (TinyMCE) and let that deal with it. But i am looking to export this data as a CSV for use in excel, which means i can't afford to have HTML tags within the output. I am sure someone will have come across this before any suggestions? many thanks Matt I have a problem with the following code but i really don't see it: I try to populate the city textfield by the zipcode entered on the zipcode textfield function fillcitystate(controlname) { var zipstring = ""; xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "postcode.php?postcode=" + controlname.value, true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { var zipstring = xmlhttp.responseText; if (zipstring!="Error") { var ziparray = zipstring.split("|"); document.getElementById("test").innerHTML = ziparray[1]; } } } xmlhttp.send(null); } In postcode.php $returnval = "Error"; $postcode = $_GET['postcode']; $query = "SELECT * FROM city WHERE code='$postcode'"; $resultval = mysql_query($query); $rowcount = mysql_num_rows($resultval); if ($rowcount==1) { $row = mysql_fetch_array($resultval); $returnval = $row['code']."|".ucwords(strtolower($row['name']))."|".$row['province']; } else { } echo $returnval; When entering a zipcode, nothing happened so i decided to just echo the name of the city using the innerHTML. Still nothing happened, so i commented out all the php in my postcode.php and decided to just do: $postcode = $_GET['postcode']; echo $postcode; then it printed out: 'undefined' Can somebody point me out? Hello, I want to create an order form where people can order shirts with sizes and quantities. So in 1 form you have a column where people can check the size and after that the quantities. (see below the form) As result i want after pressing submit and selecting for example 3 shirts Large and 1 small: S=1, M=0, L=3, XL=0, XXL=0 Code: [Select] echo "<form method=\"post\" action=".$PHP_SELF."> <label>aantal <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"S\">S<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"m\">m<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"l\">l<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XL\">XL<br /> <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\"> <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XXL\">XXL<br /> </label> <input type=submit value=Select></form>"; i hope you can help me with it. thanks in regard! Hello, I'm writing a PHP program in which textfields are printed (in a loop) into an HTML table. On a button click, another column is added to the table, and another textfield added. The problem is that when a new textfield is printed, it is slightly above the height of the other textfields (see attached picture if unclear). The code for this is below: Code: [Select] <table border = '1' cellspacing = '4' style = "color: white"> <?php include "connectToDatabase.php"; //Initial script call to generate table from database ?> </table> //Code in connectToDatabase.php... $query = mysql_query("SELECT * FROM colin_table"); while($row = mysql_fetch_array($query)){ //$row represents each row in an array for($i = 0; $i < $limit; $i++){ //Print every element in the array if($row[$i] == null) echo "<td align = 'center'><input type = 'text' style = 'text-align: center; vertical-align: middle' align = 'center'>"; else echo "<td align = 'center'>" . $row[$i]; } echo "<td align = 'center'>"; echo "<tr align = 'center'>"; //Then move to the next row } //Loop that prints text boxes for every column in the HTML table $textBoxQuery = mysql_query("SELECT * FROM allColumnFields"); while($row = mysql_fetch_array($textBoxQuery)){ echo <<<END <td align = 'center'> <input type = 'text' style="margin-left:auto; text-align:center; vertical-align: middle; margin-right:auto;" name = "rowField"/> END; //THIS IS THE PART THAT NEEDS WORK. FOR SOME REASON NEW TEXTBOX IS HIGHER THAN THE OTHER BOXES } It's more of an aesthetic problem, but it's nonetheless something I'd like to get fixed. Any ideas? Jake |