Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>How To Insert Data Into MySQL db using form in php</title>
- </head>
- <body>
- <?php
- $hostname = "10.15.14.247"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
- $db_user = "root"; // change to your database password
- $db_password = "master"; // change to your database password
- $database = "acesbd"; // provide your database name
- $db_table = "tipo_actividade"; // leave this as is
- $db = mysql_connect($hostname, $db_user, $db_password);
- mysql_select_db($database,$db);
- ?>
- <?php
- if (isset($_REQUEST['Submit'])) {
- $sql = "INSERT INTO $db_table(TAC_ID,TAC_nome) values ('".mysql_real_escape_string(stripslashes($_REQUEST['TAC_ID']))."','".mysql_real_escape_string(stripslashes($_REQUEST['dropdown']))."')";
- if($result = mysql_query($sql ,$db)) {
- echo "<h1>Thank you</h1><br>Your information has been entered into our database<br><br>";
- //echo "<br> $TAC_ID $op <br>";
- } else {
- echo "ERROR: ".mysql_error();
- }
- } else {
- echo"<h1>How To Insert Data Into MySQL db using form in php</h1>";
- echo "<form method='post' action=''>";
- $sqlin = "SELECT TAC_ID, TAC_nome FROM tipo_actividade";
- if($result = mysql_query($sqlin ,$db)) {
- echo"<select name='dropdown'>";
- echo"<option value=1>--select a name--</option>";
- $a = 2;
- while ($row = mysql_fetch_array($result)){
- //echo "$row[TAC_nome]<br>";
- $field_name=$row[TAC_nome];
- echo "<option value=$a>$field_name</option>";
- $a = $a + 1;
- }
- echo"</select>";
- }
- echo"TAC_ID:<br>";
- echo"<input type='text' name='TAC_ID'>";
- echo"<br>";
- echo"TAC_nome: <br>";
- echo"<input type='text'' name='TAC_nome' >";
- echo"<br>";
- echo"<input type='submit' name='Submit' value='Submit'>";
- echo"</form>";
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment