Solved

little problem coming in this code.

Posted on 2009-06-27
1
190 Views
Last Modified: 2012-05-07
there is a little problem coming in this code.
1) when i comment the form tags line 25 and 79 then 28 and 30

line code will not work and line 79 generate php code will

work.
2) when i uncommented the form tags then 28 and 30 line code

will work and line 79 code will not work. the url becomes very

awkward. in 2nd case, on clicking the button of generate php

code, the page gets post and nothing happens and the url

becomes like  http://localhost/new/12_table_create/dropdown_values/new.php?mname=&tname=&fname=&dtype=varchar&ftype=textbox&foptions=NULL&flength=&b=Generate+php+code

this query string gets added , why??

this is the js function
function rt(){
var tname = document.getElementById("tname").value;
var fname = document.getElementById("fname").value;
var dtype = document.getElementById("dtype").value;
var ftype = document.getElementById("ftype").value;
var foptions = document.getElementById("foptions").value;
var flength = document.getElementById("flength").value;
var obj = document.getElementById("show3");

h.open('get','php_code_generator.php?tname='+tname+'&fname='+fname+'&dtype='+dtype+'&ftype='+ftype+'&foptions='+foptions+'&flength='+flength);
h.onreadystatechange=function(){
      if(h.readyState == 4){
            obj.innerHTML=h.responseText;
      }
}
h.send(null);            
}
<?php
$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>
 
<form name="frmcopytext">
	<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" /></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" /></td><td>
	<select id="theList" onchange="number()">
	<option>Select</option>
 
<?php //here i have written the code for 1 table not to be displayed in the dropdown.
 
$tables_to_hide = array('field_types', 'login');
$res = mysql_query("show tables") or die(mysql_error());
while ($row = mysql_fetch_array($res)){
// SKIP OVER THE TABLES WE DO NOT WANT TO SHOW
    if (in_array($row[0], $tables_to_hide)) continue;
   $my_tables[] = $row[0];
}
foreach ($my_tables as $tablename){
   echo "<option>$tablename</option>\n";   
}
?>
 
</select></td></tr>
	<tr><td>Field name</td><td colspan="2"><input type="text" name="fname" id="fname" /></td></tr>
	<tr><td>Data Type</td>
	<td colspan="2">
		<select name="dtype" id="dtype">
			<option>varchar</option>
			<option>integer</option>
		</select>
	</td></tr>
	<tr><td>Field Type</td>
	<td colspan="2">
		<select name="ftype" id="ftype">
			<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>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="a" value="Add to the database" onclick="javascript:createtable();" /><input type="submit" name="b" value="Generate php code" onclick="javascript:rt();" /></td></tr>
</table>
</form>
<div id="show2"></div>
 
<div id="show3"></div>

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
1 Comment
 
LVL 17

Accepted Solution

by:
nanharbison earned 250 total points
ID: 24727669
You should move this question to the javascript zone. Some of the lines you comment out involve javascript, not PHP.
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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…

617 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