This is a really basic question.. What do I use to do simple things like make forms on the web with radio buttons etc that you can submit and the data gets analysed and then gives you feedback?
This is a really basic question.. What do I use to do simple things like make forms on the web with radio buttons etc that you can submit and the data gets analysed and then gives you feedback?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Favourite Colour Poll</title>
<style type="text/css" media="screen">
body {
font: 75% "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
}
#wrap {
width: 33em;
margin: 0 auto;
}
fieldset {
border: 1px solid #ccc;
margin-bottom: 1em;
}
legend {
border: 1px dotted #ccc;
padding: .5em;
background: #ececec;
}
p.centre {
text-align: center;
}
input#submit {
font-size: 1.5em;
}
</style>
</head>
<body>
<div id="wrap">
<?
if(isset($_POST['submit'])) {
if(!isset($_POST['lang']) || !isset($_POST['colour'])) {
echo("<h1>Form not Complete.</h1>");
echo("<p><a href=\"{$_SERVER['PHP_SELF']}\">Try Again »</a></p>");
}
else {
switch ($_POST['lang']) {
case 'us':
$colour = "color";
$favourite = "favorite";
break;
case 'uk':
$colour = "colour";
$favourite = "favourite";
break;
}
echo("<h1>Your $favourite $colour is {$_POST['colour']}.</h1>");
echo("<p><a href=\"{$_SERVER['PHP_SELF']}\">Vote Again »</a></p>");
}
}
else {
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post" accept-charset="utf-8">
<fieldset>
<legend>Vote:</legend>
<p><input type="radio" name="colour" value="red" id="red" /> <label for="red">Red</label></p>
<p><input type="radio" name="colour" value="green" id="green" /> <label for="green">Green</label></p>
<p><input type="radio" name="colour" value="blue" id="blue" /> <label for="blue">Blue</label></p>
</fieldset>
<fieldset>
<legend>Language:</legend>
<p><input type="radio" name="lang" value="us" id="us" /> <label for="us">American</label></p>
<p><input type="radio" name="lang" value="uk" id="uk" /> <label for="uk">English</label></p>
</fieldset>
<p class="centre"><input type="submit" id="submit" name="submit" value="Send!" /></p>
</form>
<? } ?>
</div>
</body>
</html>
I'd say if you're asking those questions, you really need to sit down with a current (x)html book and start from scratch. I don't mean that as an insult or put-down. I do think it helps to have an understanding.
That said, I'm sure something like Dreamweaver could help you build those forms.
the data gets analysed and then gives you feedback
Along these lines, anyone know a good place to learn the php necessary to make a simple form that will either send a text file in an email, or store the entries in a database to be retrieved later? I can work with SQL fairly well, as far as setting up a database to be used, but I haven't yet figured out the php side of the application, or how to associate it with a form effectively. The database would probably be better, btw, so if there's a secure way to access it (just a password will suffice, it's not going to be high profile), that would also be quite helpful. BTW, elppa, what you posted was very helpful to me already, it answered some of my previous questions about how to make that type of thing work.
jW
$host = "localhost"; // or whatever the server is
$user = "root"; // or whatever your username is
$password = "myGreatHardToHackPassword"; // or whatever your password is
$connection = mysql_connect("$host","$user","$password")
or exit ("Could not connect to server");
// Select the Database
$db = mysql_select_db("MyDatabase") // or whatever your database name is
or exit ("Cannot connect to database at present.");
$query = mysql_query("SELECT * FROM tablename WHERE id LIKE '1'");
$row = mysql_fetch_array($query);
echo $row['field1']; // will display the contents of the field called "field1" for row 1
echo $row['field2']; // will display the contents of the field called "field1" for row 1
// etc
// -- or --
extract($row); // creates variable names from the keys in the array
echo $field1;
echo $field2;
$query = mysql_query("SELECT * FROM tablename");
$number = mysql_num_rows($query);
echo "There are $number rows in the table.";
$query = mysql_query("SELECT id, name, price FROM tablename WHERE price > '4.50'");
echo "<h2>Products which cost more than €4.50</h2>";
while($row = mysql_fetch_array($query)) {
// The operations in this block are performed on each row from the table in turn until there are no more rows left!
echo "<h3>{$row['id']}</h2>";
echo "<p>{$row['name']} ({$row['price']})</p>";
}
$query = mysql_query("INSERT INTO tablename (field1,field2) VALUES ('value1','value2')");
$query = mysql_query("UPDATE tablename SET field1='value1', field2='value2' WHERE id LIKE '1'");
$query = mysql_query("DELETE FROM tablename WHERE id LIKE '1'");
I'd say if you're asking those questions, you really need to sit down with a current (x)html book and start from scratch. I don't mean that as an insult or put-down. I do think it helps to have an understanding.
That said, I'm sure something like Dreamweaver could help you build those forms.