justinjkiss Posted July 15, 2008 Share Posted July 15, 2008 The code below is the php. I put ... in to represent layout html above and below. There is an include at the top i didnt include in code. I got rid of all errors so the page will load. Now i cant get the form to submit to the database and create a table. The table names are the same as im using for other tables. I just want to be able to create the tables quicker when we add a new dealer. I feel the problem lies withing the $sql line. Mostly to the $user not being read correctly. I am new and i know the order of single/double quotes make a difference but im not sure which way they should be. Does the $sql? ... <? /** * The user is already logged in and not allowed to register unless admin. */ if($session->isAdmin()){ echo "[<a href=\"../dealercenter.php\">Dealer Center Home</a>] "; echo "[<a href=\"process.php\">Logout</a>]"; ?> <br /><br /><p>Add Warranty Table</p> <form action="<?=$_SERVER['PHP_SELF']?>" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr> <td>Username:</td><td><input type="text" name="user" maxlength="30"></td> </tr> <tr> <td><input type="submit" value="Add Warranty table!"></td> </tr> </table> </form> <? $user=$_POST['user']; $sql = "CREATE TABLE `custkis6_login`.`$user` ( `model` varchar( 10 ) NOT NULL , `serial` int( 10 ) NOT NULL , `servdate` varchar( 10 ) NOT NULL , `faildate` varchar( 10 ) NOT NULL , `repairdate` varchar( 10 ) NOT NULL , `comment` longtext NOT NULL , `traveltime` mediumint( 3 ) NOT NULL , `repairtime` mediumint( 3 ) NOT NULL , `claimhours` mediumint( 3 ) NOT NULL , `hourrate` varchar( 3 ) NOT NULL , `claimname` varchar( 50 ) NOT NULL , PRIMARY KEY ( `serial` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;[...]"; } else if($session->logged_in){ echo "<p>Access Denied</p>"; echo "<p>We're sorry <b>$session->username</b>, but you've not allowed to view this page. " ."<a href=\"../dealercenter.php\">Main</a>.</p>"; } ... Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/ Share on other sites More sharing options...
JD* Posted July 15, 2008 Share Posted July 15, 2008 try to echo out your $sql string and see if the statement looks correct. If your $user variable is empty, you'll have to put in some error checking to make sure it can't be that way, and then find out why it is empty. Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590598 Share on other sites More sharing options...
justinjkiss Posted July 15, 2008 Author Share Posted July 15, 2008 it echos just fine with the correct form entry. `custkis6_login`.`$user` <-- is the period a problem or should that be a space? Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590608 Share on other sites More sharing options...
justinjkiss Posted July 15, 2008 Author Share Posted July 15, 2008 changing the period didnt do anything Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590779 Share on other sites More sharing options...
craygo Posted July 15, 2008 Share Posted July 15, 2008 Are you getting any error?? Does the user you are logging into MySql with, have rights to create a table?? Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590786 Share on other sites More sharing options...
justinjkiss Posted July 15, 2008 Author Share Posted July 15, 2008 no errors are popping up when i hit submit on the form. user has all rights. I rechecked and tried again but still nothing. When i enter killer as the user i get this when i echo $sql CREATE TABLE `custkis6_login` `killer` ( `model` varchar( 10 ) NOT NULL , `serial` int( 10 ) NOT NULL , `servdate` varchar( 10 ) NOT NULL , `faildate` varchar( 10 ) NOT NULL , `repairdate` varchar( 10 ) NOT NULL , `comment` longtext NOT NULL , `traveltime` mediumint( 3 ) NOT NULL , `repairtime` mediumint( 3 ) NOT NULL , `claimhours` mediumint( 3 ) NOT NULL , `hourrate` varchar( 3 ) NOT NULL , `claimname` varchar( 50 ) NOT NULL , PRIMARY KEY ( `serial` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;[...] Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590794 Share on other sites More sharing options...
craygo Posted July 15, 2008 Share Posted July 15, 2008 since you already selected the database in your connection string, just use the table name you want. $sql = "CREATE TABLE `$user` ( `model` varchar( 10 ) NOT NULL , `serial` int( 10 ) NOT NULL , `servdate` varchar( 10 ) NOT NULL , `faildate` varchar( 10 ) NOT NULL , `repairdate` varchar( 10 ) NOT NULL , `comment` longtext NOT NULL , `traveltime` mediumint( 3 ) NOT NULL , `repairtime` mediumint( 3 ) NOT NULL , `claimhours` mediumint( 3 ) NOT NULL , `hourrate` varchar( 3 ) NOT NULL , `claimname` varchar( 50 ) NOT NULL , PRIMARY KEY ( `serial` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;[...]"; $res = mysql_query($sql) or die(mysql_error()); make sure you have the "or die()" to give you any errors encountered. Ray Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590799 Share on other sites More sharing options...
justinjkiss Posted July 15, 2008 Author Share Posted July 15, 2008 putting the or die causes a problem like i thought it would. The connection to the database is from the include but the include also keeps the connection open until logout is hit because it is a protected section with a login. would i be better just putting this into a separate php file and have the form process it instead. Then just use a separate login and so i can close the connection each time. Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590816 Share on other sites More sharing options...
craygo Posted July 15, 2008 Share Posted July 15, 2008 Well the die is telling you your not connected to the database. If your using sessions just check to see if the user is logged in, if they are then include the connection. Quote Link to comment https://forums.phpfreaks.com/topic/114853-creating-a-mysql-table-from-a-form-submission/#findComment-590841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.