php - copy values to another mysql database -
i have table displays fields sent form. there buttons can edit or delete selected row selecting id. want add button insert selected row table. cannot work.
here's code table:
<?php /* view.php displays data 'players' table */ // connect database include('config2.php'); // results database $result = mysql_query("select * articles") or die(mysql_error()); // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>author</th> <th>email</th> <th>title</th> <th>poem</th> <th>id</th>"; // loop through results of database query, displaying them in table while($row = mysql_fetch_array( $result )) { // echo out contents of each row table echo "<tr>"; echo '<td>' . $row['name'] . '</td>'; echo '<td>' . $row['email'] . '</td>'; echo '<td>' . $row['title'] . '</td>'; echo '<td>' . $row['content'] . '</td>'; echo '<td>' . $row['id'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['id'] . '">edit</a></td>'; echo '<td><a href="delete.php?id=' . $row['id'] . '">delete</a></td>'; echo '<td><a href="publish.php?id=' . $row['id'] . '">publish</a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?>
here's code delete function:
// connect database include('config2.php'); // check if 'id' variable set in url, , check valid if (isset($_get['id']) && is_numeric($_get['id'])) { // id value $id = $_get['id']; // delete entry $result = mysql_query("delete stories id=$id") or die(mysql_error()); // redirect view page header("location: secret.php"); } else // if id isn't set, or isn't valid, redirect view page { header("location: secret.php"); }
and here's how think function insert row other table should not working
// connect database include('config2.php'); // check if 'id' variable set in url, , check valid if (isset($_get['id']) && is_numeric($_get['id'])) { // id values $id = $_get['id']; $name = $_get['name']; $email = $_get['email']; $title = $_get['title']; $content = $_get['content']; //upload $result = mysql_query("insert publish (name, email, title, content) values name=$name, email=$email, title=$title, content=$content") or die(mysql_error()); // redirect view page header("location: secret.php"); } else // if id isn't set, or isn't valid, redirect view page { header("location: secret.php"); }
i'm new @ not sure correct syntax in case
using select query $id = $_get['id']; $result = mysql_query("select *stories id=$id") or die(mysql_error()); $row = mysql_fetch_array( $result ); $query= mysql_query("insert publish (name, email, title, content) values ('$row['name']','$row['email']',$row['title'],$row['content'])");
Comments
Post a Comment