所以我一直在努力与此,我不是专业的网页设计师。但基本上我有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
页面,U输入名称。
<!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>
这里是clouds_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();
?>
对不起...我只是真的为此而努力......可能是一些小的是我太傻看..
我的上帝!你的源代码令人难以置信的奇怪。 – 2012-04-14 21:17:54
欢迎来到Stack Overflow! – 2012-04-14 21:21:50
你需要http://w3schools.com/php/和http://www.w3schools.com/js/ – 2012-04-14 21:22:17