Advertisement
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_nome) values ('".mysql_real_escape_string(stripslashes($_REQUEST['TAC_nome']))."')";
- if($result = mysql_query($sql ,$db)) {
- echo "<h1>Thank you</h1><br>Your information has been entered into our database<br><br>";
- } else {
- echo "ERROR: ".mysql_error();
- }
- }
- echo "<form method='post' action=''>";
- $sqlin = "SELECT count(*) FROM tipo_actividade";
- $result = mysql_query($sqlin ,$db);
- echo"<h1>Gestão de tipo de actividades</h1>";
- $row = mysql_fetch_array($result);
- $ID = $row[0] + 1;
- $total = $row[0];
- $index = 1;
- echo"<br>TAC_ID:<br>";
- echo"<input type='text' name='TAC_ID' value=$ID readonly='readonly'>";
- 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>";
- if (!isset($SearchTAC_ID)) {
- $SearchTAC_ID = 1;
- $index = 1;
- }
- if ($SearchTAC_ID == 1) {
- $sqlsearch = "SELECT * FROM $db_table where TAC_ID = $SearchTAC_ID";
- if($result = mysql_query($sqlsearch ,$db)) {
- $row = mysql_fetch_array($result);
- $SearchTAC_nome = $row[1];
- } else {
- echo "ERROR: ".mysql_error();
- }
- }
- if (isset($_REQUEST['proximo']) and ($index < $total) ) {
- $sqlsearch = "SELECT * FROM $db_table WHERE TAC_ID > $SearchTAC_ID ORDER BY TAC_ID ASC LIMIT 1";
- if($result = mysql_query($sqlsearch ,$db)) {
- $row = mysql_fetch_array($result);
- $index++;
- echo"<br>index2: $index <br>";
- $SearchTAC_ID = $row[0];
- $SearchTAC_nome = $row[1];
- } else {
- echo "ERROR1: ".mysql_error();
- }
- }
- echo"<br>TAC_total: $total <br>";
- if (isset($_REQUEST['anterior']) and ($index > 1) ) {
- $sqlsearch = "SELECT * FROM $db_table WHERE TAC_ID < $SearchTAC_ID ORDER BY TAC_ID DESC LIMIT 1";
- if($result = mysql_query($sqlsearch ,$db)) {
- $row = mysql_fetch_array($result);
- $index--;
- $SearchTAC_ID = $row[0];
- $SearchTAC_nome = $row[1];
- } else {
- echo "ERROR2: ".mysql_error();
- }
- }
- if (isset($_REQUEST['apagar']) ) {
- $sqlsearch = "DELETE FROM $database.$db_table WHERE $db_table.`TAC_ID` = $SearchTAC_ID";
- if($result = mysql_query($sqlsearch ,$db)) {
- //$row = mysql_fetch_array($result);
- echo " $row <br>";
- } else {
- echo "ERROR2: ".mysql_error();
- }
- }
- echo"<form action='' method='post'>";
- echo"Search: ";
- echo"<br>TAC_ID:<br>";
- echo"<input type='text' name='SearchTAC_ID' value=$SearchTAC_ID readonly='readonly'>";
- echo"<br>";
- echo"TAC_nome: <br>";
- echo"<input type='text' name='SearchTAC_nome' value=$SearchTAC_nome>";
- echo"<br>";
- echo"<br>";
- echo"<input type='submit' name='anterior' value='anterior' > <input type='submit' name='proximo' value='proximo' >";
- echo"<input type='submit' name='apagar' value='apagar' > <input type='submit' name='actualizar' value='actualizar' >";
- echo"</form>";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement