vietboy505 Posted March 12, 2006 Share Posted March 12, 2006 I have run createTable.php and everything is created.Now I want to run insertData.php. I want the user to enter stuff in the form & everything must be fill in before they click the submit button. It will call submitData() & all the information was enter will insert into the database.How can I do that.config.php[code]<?php$errCon = "<br> Contact your webmaster. <br>";$server = "localhost";$user = "root";$password = "pass";$tableDaily="issue";$dbnameDaily="daily_issue";?> <?php mysql_connect($server, $user, $password) or die($errCon . mysql_error()); echo "SUCCESS";?>[/code]createTable.php[code]<?php include("config.php"); ?><?phpmysql_query("CREATE DATABASE $dbnameDaily") or die($errCon . mysql_error());echo "success in database creation. $dbnameDaily";?> <?php mysql_select_db($dbnameDaily) or die($errCon . mysql_error());// Create a MySQL table in the selected databasemysql_query("CREATE TABLE $tableDaily(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),owner VARCHAR(30),problem VARCHAR(999),status VARCHAR(1),dateCreate DATETIME, //YYYY-MM-DD HH:MM:SSdateModify TIMESTAMP)") //YYYY-MM-DD HH:MM:SSor die($errCon . mysql_error());echo "Table Created!";?>[/code]insertData.php[code]<?php include("config.php"); ?><?phpfunction submitData() {mysql_select_db($dbnameDaily) or die($errCon . mysql_error());$DATECREATE=$DATEMODIFY=date("Y-m-d H:i:s");// Insert a row of information into the tablemysql_query("INSERT INTO $tableDaily(owner, problem, status, dateCreate, dateModidy)VALUES('$OWNER', '$PROBLEM','$STATUS', '$DATECREATE', '$DATEMODIFY' ) ")or die($errCon . mysql_error());//owner VARCHAR(30),//problem VARCHAR(999),//status VARCHAR(1),//dateCreate DATETIME, //YYYY-MM-DD HH:MM:SS//dateModify TIMESTAMP)") //YYYY-MM-DD HH:MM:SSecho "Data Inserted!";}?><?phpecho('<form name="create_form" method="post"><input type="hidden" name="require" value="OWNER,PROBLEM"><table><tr> <td align="right">Name:</td> <td><input name="OWNER" size="25"></td></tr><tr> <td align="right">Status:</td> <td><select name="STATUS"> <option value="W">Work <option value="I">Idle </select> </td></tr><tr> <td align="right">Problem:</td> <td><textarea name="PROBLEM" rows="10" cols="40"></textarea> </td></tr><tr> <td colspan="2" align="center"><input type="submit" value="Submit" name="create_form"> <input type="reset" value="Reset" name="reset"></td></tr></table></form>');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4736-insert-data-from-form-to-mysql-database/ Share on other sites More sharing options...
fenway Posted March 12, 2006 Share Posted March 12, 2006 First, no need to post all of the scripts. Second, it looks basically correct -- what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/4736-insert-data-from-form-to-mysql-database/#findComment-16600 Share on other sites More sharing options...
neo926 Posted March 12, 2006 Share Posted March 12, 2006 I'm not going to pretend to know what I'm talking about, but doesn't he need:[code]<form name="create_form" method="post" action="<?php echo $PHP_SELF ?>">[/code]his form tag to look like that? Otherwise the form isn't sending the data anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/4736-insert-data-from-form-to-mysql-database/#findComment-16715 Share on other sites More sharing options...
fenway Posted March 12, 2006 Share Posted March 12, 2006 I'm fairly sure that the default action for a FORM tag is to submit back to the current page, but you're right, it should always be explicit. Quote Link to comment https://forums.phpfreaks.com/topic/4736-insert-data-from-form-to-mysql-database/#findComment-16760 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.