Log in

View Full Version : Form Data Submission to Scrolling Marquee



JBest
05-07-2012, 04:15 PM
Help! I need script that allows data submitted in a form on one page, to appear in a scrolling marquee on another. Please include links for any necessary
CSS or JQuery.

Thanks!

keyboard
05-07-2012, 11:12 PM
1.html


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="2.html" method="get">
<input type="text" name="userInput1">
<input type="submit">
</form>
</body>
</html>

2.html


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<marquee><div id="div1"></div></marquee>
<script>
var query = window.location.search;
if (query.substring(0, 1) == '?') {
query = query.substring(1);
}
var data = query.substring(11);
document.getElementById('div1').innerHTML = data;
</script>
</body>
</html>

JBest
05-08-2012, 08:26 AM
Thanks so much, forgive me, I am new at this. I created the two html pages. Where do I put the php code?:confused: I need to be more specific as well. I want the data submitted in the form on this page (see below) to appear on another page in a vertically scrolling marquee, adding each name to the list once submitted.

http://godsmasterdesign.org/EcoPower/Earnings.cgi (I'm going to change it to a html page with no captha code)

keyboard
05-08-2012, 11:55 AM
This doesn't use any php. It's just javascript.
I didn't realise you had access to php. If you want, just say so and I'll do this in php.

Why would you have .cgi pages, but be using php? The file extension for php is .php (or are you swapping from one to the other?). If you want the list to be updated, you're going to need a database (Mysql is good) to store the values. Does your webhost support php/mysql?

JBest
05-08-2012, 05:09 PM
Yes! My web host supports php/mysql. Yes Please do it for me in php. Thanks!

keyboard
05-08-2012, 11:44 PM
1.php


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="2.php" method="post">
<input type="text" name="userInput1" />
<input type="submit" name="submit1" />
</form>
</body>
</html>

2.php


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("dbName") or die(mysql_error());
if(isset($_POST['submit1'])) {
$maxChars = 100; // Put the maximum number of characters you want them to be able to enter here.
$userInput = mysql_real_escape_string($_POST['userInput1']);
$userInput = substr($userInput, $maxChars); // This the maximum number of characters that a user can submit. Anything after this is simply dropped from their submission
$timeObject = time();
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("INSERT INTO userPosts (id, post, timeObject, ip) VALUES('0', '$userInput', '$timeObject', '$ip') ");
$result = mysql_query("SELECT * FROM userPosts ORDER BY timeObject");
echo '<marquee direction="up" loop="true" scrollamount="2">';
while($row = mysql_fetch_array( $result )) {
echo $row['post'];
echo '<br />';
}
echo '</marquee>';

}
?>

</body>
</html>

The three bits in yellow you need to change to you're database username, database password, and the name of the database you want to store the information in.

After that, open up phpmyadmin (should be installed on your webhost) navigate to the database you've made, then run this sql code under the sql tab.


CREATE TABLE userPosts(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
post VARCHAR(100),
timeObject VARCHAR(14),
ip VARCHAR(20))


The two numbers in red should match up. This the maximim(?spelling?) number of characters you want users to be able to post. Anything after that number will be deleted.

If you've got any questions, don't hesatate to ask.

keyboard
05-10-2012, 11:21 PM
One more thing;
The <marquee> tag is only supported by IE. In all the other browsers, it won't do anything...