私はこれに苦労しており、プロのウェブデザイナーでもありません。しかし、基本的に私は6種類の天気の画像を持っています。そして、それらが押された/クリックされたとき、どのような天気の種類がテーブルに保存されたのかに応じていました。したがって、クラウドの画像をクリックすると、「クラウド」という単語がMYSQLデータベースに保存されます。それが押された後、ユーザーは結局最終的なウェブページ上で見ることができる天気についての名前と投稿を入力することになる。画像をクリックしたときにデータを格納する配列として配置する
私の問題は、画像にそのデータを格納する方法を完全には分かりません。私はまた、視聴者がさまざまな天気予報の他の投稿を見ることができるようにしたいので、私は情報を配列に入れる必要があることを知っています。私はjavasciptの情報を保存するためにPHPを使用することを考えていたが、私はそれについて来る方法を完全には分かっていない、助けて!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WhethertheWeather.</title>
<!--<link rel="stylesheet" type="text/css" href="demo/css/screen.css" media="all" />-->
<script src="http://www.adrianpelletier.com/mint/?js" type="text/javascript"></script>
<script type="text/javascript" src="demo/scripts/jquery-1.3.2.min.js"> </script>
<script type="text/javascript" src="demo/scripts/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="demo/scripts/execute.js"></script>
<script>
function cloudy()
{
return "<?php
$dbc=mysql_connect('asite.com','$user','$password','$db') ;
mysql_select_db('$db',$dbc);
echo $_POST[weather];?>"
}
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/gradientsky.jpg">
<div id="logo">
WhethertheWeather.
</div>
<div id="question">
Whats your favorite weather?
</div>
<div id="weather">
<ul id="nav-reflection">
<form name="myform" method="post" action="cloudy_name.php">
<li class="button-color-1"><a href="cloudy_name.php" id="weather[]" onclick="cloudy();" title="My fancy link"><img src="images/cloudybubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="sunny_name.php" id="weather[]" onclick="sunny();" title="My fancy link"><img src="images/sunnybubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-2"><a href="snowy_name.php" id="weather[]" onclick="snowy();" title="My fancy link"><img src="images/snowbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="rainy_name.php" id="weather[]" onclick="rainy();" title="My fancy link"><img src="images/rainbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="mixy_name.php" id="weather[]" onclick="mixy();" title="My fancy link"><img src="images/mixbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="windy_name.php" id="weather[]" onclick="windy();" title="My fancy link"><img src="images/windybubble.png" width="211" height="180" align="left"></a></li>
<input type="hidden" name="weather" value="weather" id="weather">
</form>
</ul>
</div>
</body>
</html>
これは私が今作業しているコードです。
ここではインデックスページですが、名前を天気に変更したので、別の名前変数と混乱することはありません。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WhethertheWeather.</title>
<!--<link rel="stylesheet" type="text/css" href="demo/css/screen.css" media="all" />-->
<script src="http://www.adrianpelletier.com/mint/?js" type="text/javascript"></script>
<script type="text/javascript" src="demo/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="demo/scripts/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="demo/scripts/execute.js"></script>
<script>
function showweather(weather) {
window.location = 'cloudy_name.php?w=' + weather;
}
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/gradientsky.jpg">
<div id="logo">
WhethertheWeather.
</div>
<div id="question">
Whats your favorite weather?
</div>
<div id="weather">
<ul id="nav-reflection">
<form method="post" action="cloudy_name.php">
<li class="button-color-1"><a href="cloudy_name.php" id="weather[]" onclick="showweather('cloudy');" title="My fancy link"><img src="images/cloudybubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="sunny_name.php" title="My fancy link"><img src="images/sunnybubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-2"><a href="snowy_name.php" title="My fancy link"><img src="images/snowbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="snowy_name.php" title="My fancy link"><img src="images/rainbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="mixy_name.php" title="My fancy link"><img src="images/mixbubble.png" width="211" height="180" align="left"></a></li>
<li class="button-color-1"><a href="windy_name.php" title="My fancy link"><img src="images/windybubble.png" width="211" height="180" align="left"></a></li>
<input type="hidden" name="weather" value="none" id="myweather">
</form>
</ul>
</div>
</body>
</html>
ここでは、名前を入力するcloudy_name.php
ページです。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WhethertheWeather</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/cloudysky.jpg">
<div id="name">
First of all, what is your name?
</div>
<form method="post" action="cloudy_story.php?w=<?php echo htmlspecialchars($_GET['weather'])?>">
<table width="20%" border="1" align="center" cellpadding="1" cellspacing="1">
<td width="100%"><label>Name: <input type="text" name="name" value="<?php echo $_POST[name]; ?>"></input></label>
<input type="submit" value="Submit">
</table>
</form>
</body>
</html>
ここはcloudy_story.phpです。
<html>
<head>
<title>Forum</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/cloudysky.jpg">
<div id="cloudy">
Cloudy
</div>
<div id="white">
<div id="blue">
<div id="grey">
<div id="container">
<form method="post" action="cloudy_update.php?w=<?php echo htmlspecialchars($_GET['weather']); echo htmlspecialchars($_POST['name'])?>">
<table width="800px" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="800px"><h5><?php echo 'Hi, '. $_POST[name] ?>!
Write your story about your favorite weather. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quam urna, rutrum ut hendrerit sit amet, dictum ut dui. Cras id sem at tortor ornare porttitor at id dolor. Proin quis nulla sit amet felis tempus imperdiet eu id felis. Vivamus ac ultricies ipsum. Aliquam nec enim nec turpis mattis aliquam. Aliquam eu quam libero. Quisque vel ligula ante, ut tempor sapien. Nullam molestie elementum urna et consequat. Fusce turpis dolor, consectetur vel placerat vel, tempor vel justo. Donec odio orci, imperdiet quis varius dignissim, pulvinar id erat. Proin lectus enim, ornare tincidunt facilisis et, accumsan eget purus. Phasellus dolor mi, . </h5></td>
</tr>
<tr>
<td width="300px"><label>Story :
<textarea rows="10" cols="100" name="story" ><?php echo $_POST[story]; ?></textarea>
</label></td>
</tr>
<tr>
<td width="300px"><input type="submit" value="Post"></td>
</tr>
</table>
<input type="hidden" name="name" value="<?php echo $_POST[name]?>">
</form>
</div>
</div>
</div>
</div>
</body>
</html>
ここではすべてのページ(cloudy_update.php)を更新してmデータベースのテーブルに配置するページです。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$dbc=mysql_connect('localsite','user','pw','db') ;
mysql_select_db('db',$dbc);
/////////////////////////////////////////////////
//let's insert our data into the database //
/////////////////////////////////////////////////
$query = "insert into stories values('" . mysql_real_escape_string($_GET['weather']) . "', '" . mysql_real_escape_string($_POST['name']) . "' , '" . mysql_real_escape_string($_POST['story']) . "')"
or die ("Error - Couldn't register user.");
echo "Thank you $_POST[name]! You've been successfully posted<br /><br />
Please view all the posts <a href='view_forum.php'><b>here</b></a>.";
/////////////////////////////////////////////////
// finished inserting our data into the database //
/////////////////////////////////////////////////
exit();
?>
申し訳ありませんが...私は本当に
私の神!あなたのソースコードは信じられないほど奇妙です。 –
ようこそスタックオーバーフロー! –
http://w3schools.com/php/とhttp://www.w3schools.com/js/ –