Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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

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
designersx
Asked:
designersx
  • 5
  • 4
  • 2
1 Solution
 
gamebitsCommented:
Try it with single quote

value='<?php echo $tname; ?>'
instead of
value="<?php echo $tname; ?>"
0
 
jfromanskiCommented:
$html value should be created in double-quotes:
$html=".....";
Otherwise variables inside $html will be not expanded
0
 
designersxAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gamebitsCommented:
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
 
designersxAuthor Commented:
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
 
gamebitsCommented:
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
 
jfromanskiCommented:
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
 
designersxAuthor Commented:
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
 
designersxAuthor Commented:
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
 
gamebitsCommented:
If you want to show the variable in the dropdown do this

<option value=$dtype selected=selected >$dtype</option>
0
 
designersxAuthor Commented:
thanks sir
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now