Hello,
I made a very simple note taking app in PHP / MySQL on XAMPP lite. It's so tiny, I thought I'd share it all right here.
It's extremely simple: You get a 255 character text entry form. The text you enter is submitted as a new note entry. Upon submitting, the exact same page loads, plus ALL of the notes you've entered. In order.
The PHP:
The SQL:
Simple, elegant, far from the best solution, but fun in its complexity:functionality ratio. Let me know what you think!
I made a very simple note taking app in PHP / MySQL on XAMPP lite. It's so tiny, I thought I'd share it all right here.
It's extremely simple: You get a 255 character text entry form. The text you enter is submitted as a new note entry. Upon submitting, the exact same page loads, plus ALL of the notes you've entered. In order.
The PHP:
Code:
<html>
<head><title>OneLine</title></head>
<body>
<h1>OneLine</h1>
<form action="oneline.php" method="POST">
<input type="text" name="newrecord" maxlength="255" size="75">
<input type="submit" value="Add">
</form>
<?php
$con = mysql_connect("localhost","root","magic");
mysql_select_db("oneline", $con);
if ($_POST[newrecord] != "") {
echo $_POST[newrecord];
$sql = "insert into oneline.lines (line) values ('$_POST[newrecord]');";
$thing = mysql_query($sql, $con);
echo (string)$thing;
}
$sql2 = "select * from oneline.lines order by lineindex desc;";
$result = mysql_query($sql2, $con) or die("Query failed with error: ".mysql_error());
while ($row = mysql_fetch_array($result)) {
echo "<p>";
echo $row['lineindex'];
echo " - ";
echo $row['line'];
echo "</p>\n";
}
mysql_free_result($result);
mysql_close();
?>
</body>
</html>
The SQL:
Code:
-- phpMyAdmin SQL Dump
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 02, 2011 at 09:32 AM
-- Server version: 5.1.41
-- PHP Version: 5.3.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `oneline`
--
-- --------------------------------------------------------
--
-- Table structure for table `lines`
--
CREATE TABLE IF NOT EXISTS `lines` (
`lineindex` int(10) unsigned NOT NULL AUTO_INCREMENT,
`line` varchar(255) CHARACTER SET armscii8 COLLATE armscii8_bin NOT NULL,
PRIMARY KEY (`lineindex`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
Simple, elegant, far from the best solution, but fun in its complexity:functionality ratio. Let me know what you think!