CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: htmlphp

User Agent Input

82 Views   
<?php $html = array( 'textinput' => htmlentities($_POST['textinput']), 'nameinput' => htmlentities($_POST['nameinput']) ); $nameinput = $_POST['nameinput']; $textinput = $_POST['textinput']; $today = date("m.d.y, g:i a"); // example 03.10.01, 5:16 pm echo "Valid User Agent Messages:" . "<br />" . "<br />"; if ( $_SERVER['HTTP_USER_AGENT'] == 'useragentname' ) { // if User Agent matches // logs into database mysql_connect ("localhost", "username", "password") or die ('Error: ' . mysql_error() ); mysql_select_db ("databasename"); // opens the database $query="INSERT INTO InputTable (name,text,date) VALUES ('$_POST[nameinput]','$_POST[textinput]','$today')"; echo $textinput . "<br />"; // echos input message $SQL = "SELECT * FROM TableName"; // pulls previous messages from sql table $result = mysql_query($SQL); while ($row = mysql_fetch_array($result)) { // echos messages from column in table echo $row['name'] . ": " . $row['text'] . " " . $row['date'] . "<br />"; } echo " "; // kills mysql connect mysql_query($query) or die (' :: Error sending message.'); } else { echo "Error: Wrong User Agent."; } ?>
by Atak
  June 12, 2012 @ 7:15pm
Add a comment


Report Abuse
brought to you by:
West Wind Techologies