Solved

problem is in accessing the values of textboxes. it is showing the values like value=$fname instead of the value

Posted on 2009-06-27
11
181 Views
Last Modified: 2012-05-07
this is the code i am using.
i want to show the value of the textboxes but it is showing me like this value=$fname .this page has the value then why it is not showing me. please see the lines 36, 38, 39, 43, 51, 59 here see the value attribute that i have used ,is it wrong method??
<?php
$tname=$_REQUEST['tname'];
$fname=$_REQUEST['fname'];
$dtype=$_REQUEST['dtype'];
$ftype=$_REQUEST['ftype'];
$foptions=$_REQUEST['foptions'];
$flength=$_REQUEST['flength'];
 
$host = "localhost";
$username = "root";
$password = "";
$database = "cmsbuilder";
 
$con = mysql_connect($host,$username,$password) or die("could not connect".mysql_error());
$db = mysql_select_db($database,$con);
?>
 
<script type="text/javascript" language="javascript" src="1.js"></script>
<script type="text/javascript">
function number(){
        var thelist=document.getElementById("theList");
        if(thelist.selectedIndex>0){
                document.getElementById("tname").value=thelist.options[thelist.selectedIndex].text;
                document.getElementById("mname").value=thelist.options[thelist.selectedIndex].text;
        }
}
 
</script>
 
<?php 
$html =
'
<form id="common" name="form">
        <table border="1" bgcolor="#CCCCCC">
        <tr><td colspan="3" bgcolor="#CCCCCC"><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan="2"><input type="text" onKeyUp="this.form.tname.value = this.value; " name="mname" id="mname" value="<?php echo $tname; ?>" /></td></tr>
        <tr><td colspan="3"><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type="text" onKeyUp="this.form.mname.value = this.value; " name="tname" id="tname"  value=$tname /></td></tr>
        <tr><td>Field name</td><td colspan="2"><input type="text" name="fname" id="fname"  value=$fname/></td></tr>
        <tr><td>Data Type</td>
        <td colspan="2">
                <select name="dtype" id="dtype">
                        <option value=dtype selected="selected" >Select</option>
                        <option>varchar</option>
                        <option>integer</option>
                </select>
        </td></tr>
        <tr><td>Field Type</td>
        <td colspan="2">
                <select name="ftype" id="ftype">
                        <option value=ftype selected="selected" >Select</option>
                        <option>textbox</option>
                        <option>wysiwyg</option>
                        <option>date</option>
                        <option>upload</option>
       </select>
        </td></tr>
        <tr><td>Field Options</td><td colspan="2"><select name="foptions" id="foptions">
                        <option value=$foptions selected="selected" >Select</option>
                        <option>NULL</option>
                        <option>NOT NULL</option>
                        <option>NOT NULL DEFAULT 0</option>
                        <option>NOT NULL DEFAULT \'\'</option>
                        <option>NOT NULL DEFAULT \'(undefined)\'</option>
                        <option>NOT NULL AUTO_INCREMENT PRIMARY KEY</option>
                        <option>NOT NULL UNIQUE KEY</option>
                        <option>NOT NULL KEY</option>
        </select></td></tr>
        <tr><td>Field Length</td><td colspan="2"><input type="text" name="flength" id="flength" /></td></tr>
        <tr><td colspan="3">
                <input type="submit" name="b" value="Genarate php code" onclick="javascript:rt();" />
        </td></tr>
        </table>
</form>
';
 
$file = fopen($tname.".php","w");
fwrite($file,$html);
fclose($file);
?>
<textarea rows="20" cols="50" name="t"><?php echo $html; ?></textarea>

Open in new window

0
Comment
Question by:designersx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 24727542
Try it with single quote

value='<?php echo $tname; ?>'
instead of
value="<?php echo $tname; ?>"
0
 
LVL 10

Expert Comment

by:jfromanski
ID: 24727554
$html value should be created in double-quotes:
$html=".....";
Otherwise variables inside $html will be not expanded
0
 

Author Comment

by:designersx
ID: 24727569
please look at this code. it is same .

gamebits. error comes when i tried ur post, the error is
Parse error: syntax error, unexpected '?' in C:\wamp\www\new\12_table_create\dropdown_values\php_code_generator.php on line 36

<?php
$tname=$_REQUEST['tname'];
$fname=$_REQUEST['fname'];
$dtype=$_REQUEST['dtype'];
$ftype=$_REQUEST['ftype'];
$foptions=$_REQUEST['foptions'];
$flength=$_REQUEST['flength'];
 
$host = "localhost";
$username = "root";
$password = "";
$database = "cmsbuilder";
 
$con = mysql_connect($host,$username,$password) or die("could not connect".mysql_error());
$db = mysql_select_db($database,$con);
?>
 
<script type="text/javascript" language="javascript" src="1.js"></script>
<script type="text/javascript">
function number(){
        var thelist=document.getElementById("theList");
        if(thelist.selectedIndex>0){
                document.getElementById("tname").value=thelist.options[thelist.selectedIndex].text;
                document.getElementById("mname").value=thelist.options[thelist.selectedIndex].text;
        }
}
 
</script>
 
<?php 
$html =
'
<form id="common" name="form">
        <table border="1" bgcolor="#CCCCCC">
        <tr><td colspan="3" bgcolor="#CCCCCC"><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan="2"><input type="text" onKeyUp="this.form.tname.value = this.value; " name="mname" id="mname" value='<?php echo $mname;?>' /></td></tr>
        <tr><td colspan="3"><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type="text" onKeyUp="this.form.mname.value = this.value; " name="tname" id="tname"  value='<?php echo $tname;?>'/></td></tr>
        <tr><td>Field name</td><td colspan="2"><input type="text" name="fname" id="fname"  value=$fname/></td></tr>
        <tr><td>Data Type</td>
        <td colspan="2">
                <select name="dtype" id="dtype">
                        <option selected="selected" >Select</option>
                        <option>varchar</option>
                        <option>integer</option>
                </select>
        </td></tr>
        <tr><td>Field Type</td>
        <td colspan="2">
                <select name="ftype" id="ftype">
                        <option selected="selected" >Select</option>
                        <option>textbox</option>
                        <option>wysiwyg</option>
                        <option>date</option>
                        <option>upload</option>
       </select>
        </td></tr>
        <tr><td>Field Options</td><td colspan="2"><select name="foptions" id="foptions">
                        <option selected="selected" >Select</option>
                        <option>NULL</option>
                        <option>NOT NULL</option>
                        <option>NOT NULL DEFAULT 0</option>
                        <option>NOT NULL DEFAULT \'\'</option>
                        <option>NOT NULL DEFAULT \'(undefined)\'</option>
                        <option>NOT NULL AUTO_INCREMENT PRIMARY KEY</option>
                        <option>NOT NULL UNIQUE KEY</option>
                        <option>NOT NULL KEY</option>
        </select></td></tr>
        <tr><td>Field Length</td><td colspan="2"><input type="text" name="flength" id="flength" /></td></tr>
        <tr><td colspan="3">
                <input type="submit" name="b" value="Genarate php code" onclick="javascript:rt();" />
        </td></tr>
        </table>
</form>
';
 
$file = fopen($tname.".php","w");
fwrite($file,$html);
fclose($file);
?>
<textarea rows="20" cols="50" name="t"><?php echo $html; ?></textarea>

Open in new window

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 28

Expert Comment

by:gamebits
ID: 24727615
Haven't notice before but jfromanski is right the variables to be parse have to be enclosed between double quote, and since you are already in php mode you do not need <?php again to display the value of the variable but you will need to escape the double quote with a backslash \ so line 31 to 41 would look like this

$html =
"
<form id=\"common\" name=\"form\">
        <table border=\"1\" bgcolor=\"#CCCCCC\">
        <tr><td colspan=\"3\" bgcolor=\"#CCCCCC\"><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan=\"2\"><input type=\"text\" onKeyUp=\"this.form.tname.value = this.value;\" name=\"mname\" id=\"mname\" value=\"$mname\" /></td></tr>
        <tr><td colspan=\"3\"><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type=\"text\" onKeyUp=\"this.form.mname.value = this.value; \" name=\"tname\" id=\"tname\"  value=\"$tname\"/></td></tr>
        <tr><td>Field name</td><td colspan=\"2\"><input type=\"text\" name=\"fname\" id=\"fname\"  value=\"$fname\"/></td></tr>
        <tr><td>Data Type</td>
        <td colspan=\"2\">

And of course you need to do the same for the rest of the variable $html and don't forget to change the last quote ' to a double quote as well " (no escape for the last one)
0
 

Author Comment

by:designersx
ID: 24727629
my problem is almost solved , just want to ask how can i do it for the dropdowns, please see the lines 43,51,59

<?php
$tname=$_REQUEST['tname'];
$fname=$_REQUEST['fname'];
$dtype=$_REQUEST['dtype'];
$ftype=$_REQUEST['ftype'];
$foptions=$_REQUEST['foptions'];
$flength=$_REQUEST['flength'];
 
$host = "localhost";
$username = "root";
$password = "";
$database = "cmsbuilder";
 
$con = mysql_connect($host,$username,$password) or die("could not connect".mysql_error());
$db = mysql_select_db($database,$con);
?>
 
<script type="text/javascript" language="javascript" src="1.js"></script>
<script type="text/javascript">
function number(){
        var thelist=document.getElementById("theList");
        if(thelist.selectedIndex>0){
                document.getElementById("tname").value=thelist.options[thelist.selectedIndex].text;
                document.getElementById("mname").value=thelist.options[thelist.selectedIndex].text;
        }
}
 
</script>
 
<?php 
$html =
"
<form id=common name=form>
        <table border=1 bgcolor=#CCCCCC>
        <tr><td colspan=3 bgcolor=#CCCCCC><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan=2><input type=text onKeyUp=this.form.tname.value = this.value; name=mname id=mname value=$tname /></td></tr>
        <tr><td colspan=3><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type=text onKeyUp=this.form.mname.value = this.value;  name=tname id=tname  value=$tname /></td></tr>
        <tr><td>Field name</td><td colspan=2><input type=text value=$fname name=fname id=fname /></td></tr>
        <tr><td>Data Type</td>
        <td colspan=2>
                <select name=dtype id=dtype>
                        <option value=$dtype selected=selected >Select</option>
                        <option>varchar</option>
                        <option>integer</option>
                </select>
        </td></tr>
        <tr><td>Field Type</td>
        <td colspan=2>
                <select name=ftype id=ftype>
                        <option value=$type selected=selected >Select</option>
                        <option>textbox</option>
                        <option>wysiwyg</option>
                        <option>date</option>
                        <option>upload</option>
       </select>
        </td></tr>
        <tr><td>Field Options</td><td colspan=2><select name=foptions id=foptions>
                        <option value=$foptions selected=selected >Select</option>
                        <option>NULL</option>
                        <option>NOT NULL</option>
                        <option>NOT NULL DEFAULT 0</option>
                        <option>NOT NULL DEFAULT \'\'</option>
                        <option>NOT NULL DEFAULT \'(undefined)\'</option>
                        <option>NOT NULL AUTO_INCREMENT PRIMARY KEY</option>
                        <option>NOT NULL UNIQUE KEY</option>
                        <option>NOT NULL KEY</option>
        </select></td></tr>
        <tr><td>Field Length</td><td colspan=2><input type=text name=flength id=flength value=$flength /></td></tr>
        <tr><td colspan=3>
                <input type=submit name=b value=Generate php code onclick=javascript:rt(); />
        </td></tr>
        </table>
</form>
";
 
$file = fopen($tname.".php","w");
fwrite($file,$html);
fclose($file);
?>
<textarea rows="20" cols="50" name="t"><?php echo $html; ?></textarea>

Open in new window

0
 
LVL 28

Expert Comment

by:gamebits
ID: 24727645
same thing, you need to give a value for each options

<select name=ftype id=ftype>
                        <option value=$type selected=selected >Select</option>
                        <option value=\"textbox\">textbox</option>
                        <option value=\"wysiwyg\">wysiwyg</option>
                        <option value\"date\">date</option>
                        <option value=\"upload\">upload</option>
0
 
LVL 10

Expert Comment

by:jfromanski
ID: 24727658
This will not work - remember to escape all double-quotes inside $html as gamebits shows, ther is no need to escape single-quote. It will work in dropdowns as well, but after corrections.
0
 

Author Comment

by:designersx
ID: 24727687
see the lines 12, 20, 28 in the file that is generated. this is exactly fie but in the browser, option should be seen accordingly but select is shown in the dropdown. the below is not the code , it is the file that is generated.

<form id=common name=form>
        <table border=1 bgcolor=#CCCCCC>
        <tr><td colspan=3 bgcolor=#CCCCCC><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan=2><input type=text onKeyUp=this.form.tname.value = this.value; name=mname id=mname value=user /></td></tr>
        <tr><td colspan=3><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type=text onKeyUp=this.form.mname.value = this.value;  name=tname id=tname  value=user /></td></tr>
        <tr><td>Field name</td><td colspan=2><input type=text value=d4 name=fname id=fname /></td></tr>
        <tr><td>Data Type</td>
        <td colspan=2>
                <select name=dtype id=dtype>
                        <option value=varchar selected=selected >Select</option>
                        <option value=varchar>varchar</option>
                        <option value=integer>integer</option>
                </select>
        </td></tr>
        <tr><td>Field Type</td>
        <td colspan=2>
                <select name=ftype id=ftype>
                        <option value=textbox selected=selected >Select</option>
                        <option value=textbox>textbox</option>
                        <option value=wysiwyg>wysiwyg</option>
                        <option value=date>date</option>
                        <option value=upload>upload</option>
       </select>
        </td></tr>
        <tr><td>Field Options</td><td colspan=2><select name=foptions id=foptions>
                        <option value=NULL selected=selected >Select</option>
                        <option value=NULL>NULL</option>
                        <option value=NOT NULL>NOT NULL</option>
                        <option value=NOT NULL DEFAULT 0>NOT NULL DEFAULT 0</option>
                        <option value=NOT NULL DEFAULT \'\'>NOT NULL DEFAULT \'\'</option>
                        <option value=NOT NULL DEFAULT \'(undefined)\'>NOT NULL DEFAULT \'(undefined)\'</option>
                        <option value=NOT NULL AUTO_INCREMENT PRIMARY KEY>NOT NULL AUTO_INCREMENT PRIMARY KEY</option>
                        <option value=NOT NULL UNIQUE KEY>NOT NULL UNIQUE KEY</option>
                        <option value=NOT NULL KEY>NOT NULL KEY</option>
        </select></td></tr>
        <tr><td>Field Length</td><td colspan=2><input type=text name=flength id=flength value=245 /></td></tr>
        <tr><td colspan=3>
                <input type=submit name=b value=Generate php code onclick=javascript:rt(); />
        </td></tr>
        </table>
</form>

Open in new window

0
 

Author Comment

by:designersx
ID: 24727690
see my code
<?php
$tname=$_REQUEST['tname'];
$fname=$_REQUEST['fname'];
$dtype=$_REQUEST['dtype'];
$ftype=$_REQUEST['ftype'];
$foptions=$_REQUEST['foptions'];
$flength=$_REQUEST['flength'];
 
$host = "localhost";
$username = "root";
$password = "";
$database = "cmsbuilder";
 
$con = mysql_connect($host,$username,$password) or die("could not connect".mysql_error());
$db = mysql_select_db($database,$con);
?>
 
<script type="text/javascript" language="javascript" src="1.js"></script>
<script type="text/javascript">
function number(){
        var thelist=document.getElementById("theList");
        if(thelist.selectedIndex>0){
                document.getElementById("tname").value=thelist.options[thelist.selectedIndex].text;
                document.getElementById("mname").value=thelist.options[thelist.selectedIndex].text;
        }
}
 
</script>
 
<?php 
$html =
"
<form id=common name=form>
        <table border=1 bgcolor=#CCCCCC>
        <tr><td colspan=3 bgcolor=#CCCCCC><h2>Add Table or fields to the Database</h2></td></tr>
        <tr><td>Menu Name</td><td colspan=2><input type=text onKeyUp=this.form.tname.value = this.value; name=mname id=mname value=$tname /></td></tr>
        <tr><td colspan=3><b>Write new table name here or Select from the dropdown</b></tr>
        <tr><td>Table Name</td><td><input type=text onKeyUp=this.form.mname.value = this.value;  name=tname id=tname  value=$tname /></td></tr>
        <tr><td>Field name</td><td colspan=2><input type=text value=$fname name=fname id=fname /></td></tr>
        <tr><td>Data Type</td>
        <td colspan=2>
                <select name=dtype id=dtype>
                        <option value=$dtype selected=selected >Select</option>
                        <option value=varchar>varchar</option>
                        <option value=integer>integer</option>
                </select>
        </td></tr>
        <tr><td>Field Type</td>
        <td colspan=2>
                <select name=ftype id=ftype>
                        <option value=$ftype selected=selected >Select</option>
                        <option value=textbox>textbox</option>
                        <option value=wysiwyg>wysiwyg</option>
                        <option value=date>date</option>
                        <option value=upload>upload</option>
       </select>
        </td></tr>
        <tr><td>Field Options</td><td colspan=2><select name=foptions id=foptions>
                        <option value=$foptions selected=selected >Select</option>
                        <option value=NULL>NULL</option>
                        <option value=NOT NULL>NOT NULL</option>
                        <option value=NOT NULL DEFAULT 0>NOT NULL DEFAULT 0</option>
                        <option value=NOT NULL DEFAULT \'\'>NOT NULL DEFAULT \'\'</option>
                        <option value=NOT NULL DEFAULT \'(undefined)\'>NOT NULL DEFAULT \'(undefined)\'</option>
                        <option value=NOT NULL AUTO_INCREMENT PRIMARY KEY>NOT NULL AUTO_INCREMENT PRIMARY KEY</option>
                        <option value=NOT NULL UNIQUE KEY>NOT NULL UNIQUE KEY</option>
                        <option value=NOT NULL KEY>NOT NULL KEY</option>
        </select></td></tr>
        <tr><td>Field Length</td><td colspan=2><input type=text name=flength id=flength value=$flength /></td></tr>
        <tr><td colspan=3>
                <input type=submit name=b value=Generate php code onclick=javascript:rt(); />
        </td></tr>
        </table>
</form>
";
 
$file = fopen($tname.".php","w");
fwrite($file,$html);
fclose($file);
?>
<textarea rows="20" cols="50" name="t"><?php echo $html; ?></textarea>

Open in new window

0
 
LVL 28

Accepted Solution

by:
gamebits earned 250 total points
ID: 24727703
If you want to show the variable in the dropdown do this

<option value=$dtype selected=selected >$dtype</option>
0
 

Author Comment

by:designersx
ID: 24727715
thanks sir
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question