R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

HTML Form Creator

This script is called html-form-creator.php

The HTML Form Creator script is one of a group of PHP scripts that handle both the administrative and end-user aspects of a general purpose HTML Form Creator that allows not just input boxes but multiple selection enabled select/option lists as well. In addition to the expectable editing scripts for both administrative and end-user functions, there's also a Search and Match script so that users can use the scripts to find other users with various individual or group commonalities, including proximity searches, i.e., find all the users within various distances. There are even private messaging scripts.

First, we start up a session and include the config.php script to ensure that our connection to our database is made correctly. This file has the codes below in it:

$theemailaddress = "yoursite@yoursite.com"; //EDIT ME
$roothostname = "localhost";
$theusername = "yourusername"; //EDIT ME
$thepassword = "yourpassword"; //EDIT ME
$thedatabasename = "yourdb"; //EDIT ME
mysql_connect("".$roothostname."","".$theusername."","".$thepassword."") or die(mysql_error());
mysql_select_db("".$thedatabasename."") or die(mysql_error());

Next we do browser sniffing to deal with display quirks. Then we have several JavaScript calculation functions that are part of the algorithm for dealing with fixed positioning. Much as we'd like to claim credit for it, in truth it's actually JDenny who is the CSS and JavaScript genius who came up with this brilliant CSS and JavaScript fixed positioning code and put it on the Web to help those of us that were stumped trying to figure out good fixed positioning codes. Thanks a million JDenny! This has to be the most ingenious DHTML using CSS and JavaScript we've ever seen! (Note: The b.gif URL should be left as is, but you do NOT need a b.gif file: it is a dummy name just to keep the code working.) The CSS for BODY, the mytable id, and the menu id in the CSS styling section are part of this algorithm for fixed positioning as well. The BODY tag's CSS that uses t.gif for the background is using a real file. Make it yourself: it's simply an invisible 1-pixel gif, and this goes a long way to prevent any shimmering of the fixed-position side menu. If you are feeling lazy type in http://www.css-resources.com/t.gif and do Save As from the browser's File menu, since right clicking is dumb—right click WHAT?

In the JavaScript section, there is a u() function which contains var url="html-form-creator.php?f="+f+"&w="+qq;window.location.href=url. It gets called by the menu item links such as the onClick="u('edit')" link used by the Edit function. The u() function sends both the selected menu item and the selected table row to the page, via a URL query string as the page reloads. The PHP GET superglobal variable grabs the URL query string data as $f and $w.

Then there is the addem() function, which contains document.myform.box.focus(), and this merely takes the cursor to the form question input box. This gets used when the administrator uses the Edit function.

Next, there is the check() function for validation of the administrator input. It runs off the onchange event which is echoed into place in the PHP function theoptions(). The check() function replaces single quotes with middot ("·") characters, and it uses a regular expression pattern and the JavaScript search() method to check out one input box value at a time and an illegal value (or less than 1 or more than 50 characters) will cause an alert message outlining legal characters, after which the function will return false. This latter causes the cursor to stay on the current input box. The check() function also checks the value in "box2" in which the administrator needs to have typed a number from 1 to 50. If not, the function returns false after telling him "Please enter a number from 1 to 50."

The function check2() is to check the table name prefix (which will be followed by "_database") to make sure the administrator uses only allowed characters. The function fix() deals with quirks about how various browsers handle fixed positioning.

The functions startmouse() and getCoords() get the cursor coordinates of the mouse and run a small triangular red indicator arrow that runs vertically along the side of the displayed table data. Its purpose is to allow the administrator to select one of the input questions displayed in a vertical column on the screen. This is done so that one of the menu items like edit or delete can be used on that selected question. The getCoords() function has algorithms in it that deal with ensuring that the indicator stays within the boundaries of the side of the column of the input questions displayed. The function yyyy() is run by the BODY tag's onload event. It figures out how tall the browser window is and uses this to inform the getCoords() function of this height via the ad variable. The browser sniffer and these conditionals also help nail down the height from which the indicator range can be figured: if(Netscape){ii=26;p=119;} if(is_opera){ii=25;p=99;} if(wsafari){ii=26;p=99;} if(is_ie){ii=25;p=104;} if(is_chrome){ii=26;p=99;} if(msafari){ii=21;p=90;} The getElementById() method is used on the id of the indicator to figure out the top property it should have, and DHTML is done to move the indicator according to the current cursor position of the mouse.

Next comes the CSS. We already looked at the fact there is some weird stuff in BODY, the mytable id and the menu id styling. These too help browsers handle fixed positioning.

PHP comes next. The function underscore() takes the table of form questions the administrator is inputting and processes them into values that can and will be used as MySQL table field names, allowing only alphanumerics and underscores in the new array $i[]. So what is the $i[] array? It is a filtered version of the form questions. The form questions being entered contain the raw question data like "How many men, in your group, make over $50,000 a year (!) and a % goes to charity?" Allowed are ' ! ? $ % ( ) _ - , . and spaces, letters and numbers, even though the ' will get converted to middot ("·"). But the $i[] array will contain only the filtered version of each form question, like:
"How_many_men__in_your_group__make_over__50_000_a_year_____and_a___
goes_to_charity_", which is okay as a field name, a tag's name attribute, a JavaScript array element value, or a PHP array element value. The array is created to put into the $aa table, which has the db name input by the administrator plus "_database". (Note: JavaScript allows $ in variable names but PHP doesn't, letting it only be a "this is PHP" token at the start of variables. So we disallowed it.)

To clarify: $a=$db."_inputs", $aa=$db."_database", $aaa=$db."_options". All these are the db name plus a suffix. The input table is the main one the script on this page deals with. It holds the raw form questions the administrator is inputting into this script and the input table also holds the administrator-entered "allowed input length of the data". This data will get entered (in the HTML Form Creator—Enter Record in Form page) by the user for the field corresponding to form questions which have been filtered and put into the $i[] array and then the database table.

The user inputs form data into the database table ($aa), while only the administrator inputs anything in the inputs table ($a) or options table ($aaa). The script on this page, html-form-creator.php, creates all three tables in the db. The inputs table is created once the administrator inputs a table prefix name. The other two tables require the administrator to click the "Save table" menu item. The options table is created empty except for field names. This table gets data only if the administrator changes any of the form input boxes to select boxes with options by selecting the "Add options" menu item when using the Edit Options in HTML Form Creator Form option. To get to this, you have to select the "Edit options" option in the script on this page, html-form-creator.php first.

The database table is created when the administrator clicks the "Save table" menu item. Obviously he adds a few form questions with the "Add" option before doing this. The options table will get created only if it does not exist and the same is true for the database table. The latter gets the filtered field names (that start out as raw form questions) and data input sizes the administrator is inputting into this script via a for loop that uses the MySQL query "ALTER TABLE $aa ADD $i[$h] VARCHAR($s[$h])" to append the database table with new field names one array element value at a time. Then the page reloads.

We've already started a session at the start of the whole script. Now let's use it. It turns out that session variables are a much easier way to deal with values that need to survive refresh/restart and submissions than sticking hidden fields, POSTs, and GETs everywhere full of flags or values. The first thing the administrator does on this form questions entry page is to enter the table prefix name for this form and it is POSTed to $d. If the POST has reasonable content, it will be used as the table prefix (since the prefix will be used before _database, _options, and _input tables in relating to MySQL tables). The db query SHOW TABLES LIKE '$aa' will not be used to check whether the table prefix exists and therefore the tables exist, because this script is where new tables are created as well as existing tables are updated. The $_SESSION['db']=$db command establishes a session variable.

The very next command is that session variable being checked, and the result will be found to be okay since the JavaScript function check2() was called from the table prefix entry form, which forced it to be alphanumeric or underscore. Bad input gets an alert and a refocusing of the cursor in the input box. Good input lets the administrator into the rest of the script, as you can see by the PHP "if" conditional.

Now we create the inputs table. Then we use the PHP POST superglobal variable to get 3 POSTs. The $b and $b2 variables will get the contents of the input boxes at the bottom of the page. The $edit2 flag will be used to tell the editing functions which row (of inputted questions) was selected. If the administrator forgot to add an input size number for acceptable inputs, the script restarts once an alert has displayed and gotten acknowleged. The administrator's questions will get filtered now, and the middot character (·) will be allowed but the single quote will not. The JavaScript function check() will have dumped double quotes and changed single quotes into middots, so if the user of this script is a hacker, not the administrator, and he has JavaScript off, all attempted single quote exploits will be replaced with an empty string due to the pattern4 variable used in the PHP preg_replace() function. The strip_tags() and mysql_real_escape_string() functions are also called, to tighten security even more.

Next the MySQL INSERT INTO statement puts the inputted data into the table if the $edit2 flag is 0 and the inputs were okay and the data, when looked for in the table produced 0 rows of results. (Note the NULL, which convinces the id field to auto-increment.) This is the Add function. On the other hand, if the Edit function is detected because the $edit2 flag is not 0, the UPDATE SET statement is used to update the MySQL question being edited.

Next, we define some arrays and table name suffixes. Also, we GET both 'f' and 'w', the latter being which question row on the screen is selected, and the former being which menu item is selected. The values come in via a URL query string when the selection of a menu item reloads the page.

You can see the "savetable" option at work, saving a couple of tables, as already discussed. The options table is empty—but of course it only gets saved if the table does not exist. Then we do a query to grab all the items (questions) and inputsizes from the db table $db."_inputs" and we stick the former in the $i[] array and the latter in the $s[] array, using a php while() statement and array_push() function. Now the underscore() function is run. Then the database table gets saved if it does not exist, and the filtered question list and the input sizes get saved in the database table. Then the page reloads.

The MySQL DELETE FROM statement is used if the "delete" option is being utilized. The N field is just a bunch of numbers that get sorted from 1 to the number of records so that we'll get consistency, not chaos, when we use mouse-controlled red indicator and the table's N field to reference the question rows by the selected $w variable. Then the page reloads.

If the function chosen was "edit", then the question and input size row selected by N will have its data stuck into the two variables $the_item and $inputsize. These will get sent to JavaScript with the help of JavaScript Object Notation, also known as JSON. Then they will get snuck into the question and input size input boxes so the administrator will find the current values from the MySQL table row waiting for him, to enhance the editing experience.

If the selection was "moveu", the row selected will get moved up (to lower N numbers) higher on the screen by switching places with the row higher than the selected row. Of course, the script makes sure you haven't selected the top row on the page—which nullifies the selection.

If the selection was "moved", the row selected will get moved down (to higher N numbers) lower on the screen by switching places with the row lower than the selected row. The statement SELECT max(N) FROM is used to make sure the selected row is not the last row on the screen—which nullifies the selection.

In both moving a row down and moving a row up, the SELECT FROM statement is used to get the rows' current data. Then the UPDATE statement is used with the WHERE clause to update only those records switching rows. The page reloads after this record switch.

Now we use the MySQL query "SELECT * FROM $a ORDER BY id" to get the administrator's input table's data into a result set sorted from earliest to latest because that's how auto-incrementing id fields work. In this table are the question items and input sizes the administrator allowed. Then we UPDATE the N field, putting digits from 1 to the number of rows in the table. Next we use the MySQL query "SELECT * FROM $a ORDER BY N" to get the administrator's input table's data again only sorted by N, so row selections with the red indicator will always relate to a record that can be accessed by its N field easily, since they're in order in both the db table and on the page. We use the MySQL query mysql_fetch_array() from this last result set to get the table's data, which we display in order in an HTML table. The onsubmit event runs the JavaScript check() function.

Next, we get the PHP data sent to JavaScript with the help of JavaScript Object Notation, also known as JSON. We will be needing the w (which row has the red indicator next to it), item (what question, so the edit function has pre-loaded input boxes), inputsize (what input size, so the edit function has pre-loaded input boxes) and menu_item variables, so we get those now, and if Edit is chosen, the data found in the MySQL table regarding the selected table row on the screen will be stuck into the input boxes. Recall that PHP is a server language so its values are in place, so therefore this JavaScript block, coming after the PHP block, will find its PHP values as needed. Next, we display the DIV called menu which has the page's menu, and it also gives instructions: "Select row. Move left. Use menu." input directions. Finally, we display the red triangular indicator which is positioned by the administrator's mouse cursor.

The script below is called: html-form-creator.php

<?php
session_start();
include('config.php');
?>
<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>HTML Form Creator</TITLE>
<meta name="description" content="HTML Form Creator">
<meta name="keywords" content="HTML Form Creator,Form Creator,php,javascript, dhtml, DHTML">
<script language="javascript">
mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers
is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}
if(is_ie&&mactest){is_ie_mac=1}

var ii=25;var p=104;var yy=0;var x=0;var y=0;var yyy=0;var q=0;var ad=0;var f="";var qq=1;
if(Netscape){ii=26;p=119;}
if(is_opera){ii=25;p=99;}
if(wsafari){ii=26;p=99;}
if(is_ie){ii=25;p=104;}
if(is_chrome){ii=26;p=99;}
if(msafari){ii=21;p=90;}

function u(f){var url="html-form-creator.php?f="+f+"&w="+qq;window.location.href=url;}

function addem(){document.myform.box.focus();}

function yyyy(){
var v=document;ad=Math.max(Math.max(v.body.scrollHeight, v.documentElement.scrollHeight),
Math.max(v.body.offsetHeight, v.documentElement.offsetHeight),
Math.max(v.body.clientHeight, v.documentElement.clientHeight));}

function calculateBgX(oElement) {return document.body.scrollLeft - getOffsetLeft(oElement);}

function calculateBgY(oElement) {return document.body.scrollTop - getOffsetTop(oElement);}

function getOffsetTop(oElement) {var iResult= oElement.offsetTop;
while (oElement.offsetParent) {oElement = oElement.offsetParent;iResult += oElement.offsetTop;}
return iResult;}

function getOffsetLeft(oElement) {var iResult= oElement.offsetLeft;
while (oElement.offsetParent) {oElement = oElement.offsetParent;iResult += oElement.offsetLeft;}
return iResult;}

function check(){
var ck_item = /^[A-Za-z0-9 !$%-_()\?\.\,\']{1,50}$/;
if (document.myform.box.value.search(ck_item)==-1)
{alert("Please enter 1 to 50 letters, numbers, period,\ncomma, space and these for item: ' ! ? $ % ( ) _ -"); document.myform.box.focus();return false;}else{l=document.myform.box.value; document.myform.box.value=l.replace(/'/gi, "·");}

if (document.myform.box.value.length<1 || document.myform.box2.value.length<1 || document.myform.box2.value.length>2 || isNaN(document.myform.box2.value)==true || document.myform.box2.value<1 || document.myform.box2.value>50){alert("Please enter a number from 1 to 50.");document.myform.box2.focus();return false;}
}

function check2(){
var ck_item2 = /^[A-Za-z0-9_]{3,20}$/;
if (document.nameform.db.value.search(ck_item2)==-1)
{alert("Please enter 3 to 20 letters, numbers, or underscore."); document.nameform.db.focus();return false;}}

function startmouse() {if(Netscape) {document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove=getCoords;}

function getCoords(e){
if (!e) var e = window.event;
if (e.pageX){y = e.pageY;x = e.pageX;}
else if (e.clientX){y = e.clientY + document.body.scrollTop;x = e.clientX + document.body.scrollLeft;}
if(x>148){if (y>ad-70){y=ad-70;}
if (y<p){y=p;}
q=parseInt((y-p)/ii);qq=q+1;if(qq==0){qq=1;}
yy=p+q*ii;
if(yyy!=yy){e=document.getElementById("j");e.style.top=yy+"px";yyy=yy;}}}

function fix(){if(Netscape||is_opera){e=document.getElementById("mytable");e.style.position="absolute";e.style.marginTop=0+"px";
e=document.getElementById("j");e.style.top=p+"px";}}

</script>
<STYLE TYPE="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-image:url(t.gif);background-attachment:fixed;background-color:#ccc;}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
#mytable {margin:26px 0 0 150px;width:600px;padding:10px;border:2px solid blue;background: url('b.gif');background-attachment: fixed;background-position: expression((calculateBgX(this))+"px "+(calculateBgY(this))+"px");background-color:#eee;}
#table1 {width:100%;border:1px solid blue;text-align:center}
#menu {background-color:#eee;position:fixed;left:2px;width:130px;padding:5px;border:2px solid blue;position: expression("absolute");top: expression(eval(document.body.scrollTop)+60);}
#j {position:absolute;top:104px;left:153px;}
#getdbname {position:absolute;top:104px;left:353px;}
</STYLE>
</head>
<body onload="startmouse(),yyyy(),fix()">

<?php

function underscore(){
global $i;
$replacement="_";
$pattern9 = '/[^A-Za-z0-9_]/i';
for ($h = 0; $h < count($i); $h++) {
$i[$h]=preg_replace($pattern9, $replacement, $i[$h]);}}

$d=mysql_real_escape_string($_POST['db']);if(strlen($d)>2){$db=$d;$_SESSION['db']=$db;}
if(!isset($_SESSION['db'])){
echo "<div id='getdbname'><form name='nameform' id='nameform' method='post' action='html-form-creator.php' onsubmit='return check2()'>db name&nbsp;<input type='text' id='db' name='db' maxlength='20' size='20'><input type='submit' value='submit'></form></div>";}else{$db=$_SESSION['db'];}

if(isset($_SESSION['db']) && strlen($db)>2){

$a=$db."_inputs";

$sql = "CREATE TABLE IF NOT EXISTS $a (
id INT(4) NOT NULL AUTO_INCREMENT,
item VARCHAR(50) NOT NULL,
inputsize INT(4) NOT NULL default '50',
N INT(4) NOT NULL default '0',
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1";

mysql_query($sql);

$b=$_POST['box'];
$b2=mysql_real_escape_string(intval($_POST['box2']));
$edit2=$_POST['edit2'];
$result = mysql_query("SELECT * FROM $a WHERE item='$b'");
$num_rows = mysql_num_rows($result);
if(isset($edit2)){
if($b2<1 || $b2>50){echo '<script language="javascript">alert("Please enter a number from 1 to 50.");window.location="html-form-creator.php";</script>';}}

$b=substr($b,0,50);$replacement="";
$pattern4 = '/[^A-Za-z0-9\\!\\?\\$\\%\\(\\)\\_\\s\\.\\,\\-\\·]/i';
$b=preg_replace($pattern4, $replacement, $b);
$b=strip_tags($b);
$b=mysql_real_escape_string($b);

if(strlen($b)>0 && $num_rows==0 && $edit2=='0'){
$sql = mysql_query("INSERT INTO $a
(id,item,inputsize,N)
VALUES (NULL, '$b', '$b2', '$n')");
unset($b);echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

if(isset($edit2)){
$edit2=mysql_real_escape_string($edit2);
if(strlen($b)>0 && $b2>0 && $b2<51){
$sql = mysql_query("UPDATE $a SET item='$b',inputsize='$b2' WHERE N='$edit2'");}
unset($b);echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

$f=$_GET['f'];$w=$_GET['w'];$ff=$f;$ww=$w;$n=0;$s=array();$i=array();

if($f=='savetable'){
$aa=$db."_database";$aaa=$db."_options";
mysql_query("CREATE TABLE IF NOT EXISTS $aaa (
id INT(4) NOT NULL AUTO_INCREMENT,
field_name VARCHAR(50) NOT NULL,
number_of_options TINYINT(4) NOT NULL,
options TEXT NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1");
$sql=mysql_query("SELECT item,inputsize FROM $a");
$num_rows = mysql_num_rows($sql);
while($row = mysql_fetch_array($sql)){
array_push ($i, $row['item']); array_push ($s, $row['inputsize']);}
underscore();
mysql_query("CREATE TABLE IF NOT EXISTS $aa (
id INT(4) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1");
for ($h = 0; $h < $num_rows; $h++) {
mysql_query("ALTER TABLE $aa ADD $i[$h] VARCHAR($s[$h])") or die(mysql_error());}
echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

if($f=='delete'){
$sql=mysql_query("DELETE FROM $a WHERE N='$w'");echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

if($f=='edit'){
$result = mysql_query("SELECT item,inputsize FROM $a WHERE N='$w'");
$row = mysql_fetch_array($result); $the_item=$row['item'];$inputsize=$row['inputsize'];}

if($f=='moveu'){
$result = mysql_query("SELECT item,inputsize FROM $a WHERE N='$w'");
$row = mysql_fetch_array($result); $i1=$row['item']; $s1=$row['inputsize'];
$moveu=$w-1;
if($moveu>0){
$result = mysql_query("SELECT item,inputsize FROM $a WHERE N='$moveu'");
$row = mysql_fetch_array($result); $i2=$row['item']; $s2=$row['inputsize'];
$sql = mysql_query("UPDATE $a SET item='$i1',inputsize='$s1' WHERE N='$moveu'");
$sql = mysql_query("UPDATE $a SET item='$i2',inputsize='$s2' WHERE N='$w'");}
unset($b);echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

if($f=='moved'){
$result = mysql_query("SELECT item,inputsize FROM $a WHERE N='$w'");
$row = mysql_fetch_array($result); $i1=$row['item']; $s1=$row['inputsize'];
$moved=$w+1;
$result=mysql_query("SELECT max(N) FROM $a");
$row = mysql_fetch_array($result);
if($moved<=$row[0]){
$result = mysql_query("SELECT item,inputsize FROM $a WHERE N='$moved'");
$row = mysql_fetch_array($result); $i2=$row['item']; $s2=$row['inputsize'];
$sql = mysql_query("UPDATE $a SET item='$i1',inputsize='$s1' WHERE N='$moved'");
$sql = mysql_query("UPDATE $a SET item='$i2',inputsize='$s2' WHERE N='$w'");}
unset($b);echo '<script language="javascript">window.location="html-form-creator.php";</script>';}

$result = mysql_query("SELECT * FROM $a ORDER BY id");
$num_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)) {$id=$row['id'];$n++;
mysql_query("UPDATE $a SET N='$n' WHERE id='$id'");}

$sql = mysql_query("SELECT * FROM $a ORDER BY N") or die(mysql_error());
echo "<center><h1>HTML Form Creator</h1></center><div id='mytable'><table id='table1' border='1' width='578'>";
echo "<tr><th width='25'>Number</th><th width='25'>Size</th><th width='528' align='center'>Question</th></tr>";
while($row = mysql_fetch_array($sql)) {
echo "<tr><td>";
echo htmlentities(stripslashes($row['N']), ENT_QUOTES);
echo "</td><td>";
echo htmlentities(stripslashes($row['inputsize']), ENT_QUOTES);
echo "</td><td align='left'>";
echo htmlentities(stripslashes($row['item']), ENT_QUOTES);
echo "</td></tr>";}
echo "</table><a name='form1'></a><form name='myform' id='myform' method='post' action='html-form-creator.php' onsubmit='return check()'>item&nbsp;
<input type='text' id='box' name='box' maxlength='50' size='50'>&nbsp;&nbsp;&nbsp;&nbsp;size&nbsp;<input type='text' id='box2' name='box2' maxlength='2' size='2'><input type='hidden' name='edit2' value='0'>&nbsp;&nbsp;<input type='submit' value='submit'></div>";
mysql_close();
unset($b);unset($f);unset($w);
}
?>

<script language="javascript">
var menu_item = <?php echo json_encode($ff); ?>;
var w = <?php echo json_encode($ww); ?>;
var item = <?php echo json_encode($the_item); ?>;
var inputsize = <?php echo json_encode($inputsize); ?>;
if(menu_item=="edit"){
document.myform.edit2.value=w;
document.myform.box.value=item;
document.myform.box2.value=inputsize;
addem();}
</script>

<div id='menu'>
<a HREF="#" onClick="addem()">Add</a><BR><BR>
<a HREF="#" onClick="u('delete')">Delete</a><BR><BR>
<a HREF="#" onClick="u('edit')">Edit</a><BR><BR>
<a HREF="#" onClick="u('moveu')">Move up</a><BR><BR>
<a HREF="#" onClick="u('moved')">Move down</a><BR><BR>
<a HREF="#" onClick="u('savetable')">Save table</a><BR><BR>
<a HREF="edit-options-in-html-form-creator-form.php?f=main">Edit options</a><BR><BR>
<a HREF="administrator-page.php">Return to<BR>Admin Page</a><BR><BR><hr><BR>
<b>&nbsp;&nbsp;&nbsp;&nbsp;Select row.<BR>&nbsp;&nbsp;&nbsp;&nbsp;Move left.<BR>&nbsp;&nbsp;&nbsp;&nbsp;Use menu.</b><BR><BR><hr><BR>( ' will change to · )
</div>
<div id='j'><IMG SRC="indicator.gif" WIDTH=7 HEIGHT=15 BORDER=0></div>
</body>
</html>