▼  Site Navigation Main Articles News Search  ▼  Anime + Manga Anime Reviews Anime Characters Gallery Screenshots Manga Reviews  ▼  Misc Links to Webcomics Bible Quotes About Older Musings
site version 7.3
MySQL –– send info from one page to another using POST
written by: admin


Date Written: 8/2/08 Last Updated: 4/2/10

The following will retrieve a value from the database for viewing and editing.

Name one file what ever you want and enter the following code into it:
<?php
$host="hostname";
$user="username";
$password="password";
$database="database name";
  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");

$query = "SELECT ranks FROM admin WHERE ID=0";
  $result = mysql_query($query)
       or die ("Couldn't execute query.");
  $value = mysql_fetch_array($result,MYSQL_ASSOC);
$value= $value['ranks'];
$value=explode("\r\n",$value);
print_r($value);$five=$value[1];
?>
<form action="/file1.php" method="post">
<br><br><input type="text" name="ranks" value="<?php print $five;?>">
<input type="submit" name="newbutton" value="Submit">

In the same folder name the next file "file1.php" and enter the following code into it:
<?php
$host="hostname";
$user="username";
$password="password";
$database="databasename";
  $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection) or die ("Couldn't select database");
$ranks=$_POST['ranks'];
echo "pp $ranks pp";
$query = "update admin set sum='$sum' where ID=0";
$result = mysql_query($query)
or die ("Couldn't execute query.");
?>

With this example you will be able to update an entry in the database quite easily.  As always be sure you have some security set up so that only you can access the information.  By using sessions or htaccess you should be quite secure.

TAGS: php, mysql
copyright 2005–2024