Trying to save variables to a MYSQL database table

2019-09-09 04:54发布

问题:

So I'm not really sure how to ask this...but I'm making a website in which you would be able to click one of six weather icons leading you to a page that will allow you to enter your name and a story relating to the weather and post it on a final page with other peoples stories about the same type of weather. I have a table set up to save the name and story, but I'm not sure how to save the weather when a user click on one of the icons.

My teacher was saying to do something with javascript and making a hidden form or something. Heres the link to the site if that would help. http://www.tcnjart.com/christineaustin/whethertheweather/index.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 connect(){
var moveto= $.(#sel).attr("name");
$(#myweather).value=moveto;
myform.submit;

}

</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="javascript:connect();"id="sel"name"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"<imgsrc="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>

回答1:

Well, first of all, the point of this homework is for you to figure out how to do this on your own, although I guess SO kindof counts towards that.

Set an onclick property of the image set the value of a hidden form element. That should be enough for you to google and get a proper answer.

<img src=foo onclick="javascript_code_goes_here">

and

<input type=hidden name='weather' id='weather' value=''>