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
169 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now