0

我的标题可能有点混乱,所以让我尝试详细解释一下,我有一个青年足球联赛的表格,要求用户从下拉框中选择他们的球队,当他们选择他们的球队时,它会更改徽标将表格添加到他们的团队徽标。我需要做的是在 mysql 中发布徽标的路径,并在结果页面上显示徽标。我的问题是我不知道如何获取要在 mysql 中发布的徽标路径。这是我用于更改徽标的表单的jsfiddle 。

这是html:

<body style="height: 449px; width: 933px;">
<form method="post" action="process_rentals.php" enctype="multipart/form-data">
<div id="container" class="auto-style5" style="height: 234px">
<br>
<div class="auto-style1" style="height: 168px">

<img name="logo_image" id="logoimage"  style="float: left" width="175" height="175"/>

<br/><br/>

<br><br><br><br><br>

<select name="team_name" id="dd" onChange="swapImage()" style="width: 150px">
<option value=""></option>
<option value="FALCONS" title="decals/falcons2013.jpg" >Falcons</option>
<option value="GREEN VALLEY KNIGHTS" title="decals/gvklogo2013.png">Green Valley Knights</option>
<option value="LONGHORNS" title="decals/longhorns2013.jpg">Longhorns</option>
<option value="MUSTANGS" title="decals/mustangs2013.jpg">Mustangs</option>
<option value="NW NINERS" title="decals/nwniners2013.jpg">NW Niners</option>
<option value="REBELS" title="decals/rebels2013.jpg">Rebels</option>
<option value="WILDCATS" title="decals/wildcats2013.jpg">Wildcats</option>

</select>

</div>

和javascript:

function swapImage(){
var image = document.getElementById("logoimage");
var dropd = document.getElementById("dd");
image.src = dropd.options[dropd.selectedIndex].title;   
};

有没有办法说,如果 title value=MUSTANGS 然后在这个路径显示图像?因此,如果标题是野马,那么在 decals/images/mustangs2013.jpg 中显示图像,或者是否有更简单的方法在 mysql 中获取图像路径?我的表单有效,所有数据都发布到 mysql 我只是无法显示徽标,因为我不知道如何告诉它它在哪里。

    <?php
//----------PATH OF UPLOADED IMAGE----------//
$target = "uploads/images/logos/";
$target = $target . basename($_FILES['logo_image']['name']);

//----------FORM INFO----------//
$team_name=$_POST['team_name'];
$player_name=$_POST['player_name'];
$chinstrap_number=$_POST['chinstrap_number'];
$shoulderpad_number=$_POST['shoulderpad_number'];
$parent_signature=$_POST['parent_signature'];
$print_name=$_POST['print_name'];
$date=$_POST['date'];
$pic=($_FILES['logo_image']['name']);

//----------CONNECT TO DATABASE----------//
include 'elite_connect.php';

//----------WRITES TO DATABASE----------//
mysql_query("INSERT INTO rentals (date, team_name, player_name, chinstrap_number, shoulderpad_number, parent_signature, print_name, logo_image)
VALUES ('$date','$team_name','$player_name','$chinstrap_number','$shoulderpad_number','$parent_signature','$print_name','$target')");
echo mysql_error();

//----------WRITES LOGO TO SERVER----------//
//if(move_uploaded_file($_FILES['logo_image']['tmp_name'], $target))
//{//----------TELLS IF ALL IS OK----------//
//echo "The file ". basename($_FILES['logo_image']['name']). " has been uploaded!";
//}
//else{
//----------GIVES AN ERROR IF IT'S NOT----------//
//echo "Sorry, there was a problem uploading your file.";
//}
?>
<html>
<body>
<center>
<form name="rental_results" method="post" action="rental_results.php" enctype="multipart/form-data" id="rentalresults">
<input type="submit" name="submit" id="submit" value="Display Form"/>
<input type="submit" name="newform" id="newform" value="New Rental"/>
</form>
</center></body></html>

所以我没有使用灰色的代码部分,因为它需要文件选择才能将图像上传到文件夹并在数据库中插入文件的路径,该代码与图像的使用方式无关形式。

4

1 回答 1

0

好吧,我们现在正在取得进展。因此,在</select>HTML 中的语句之后,添加以下内容:

<input type="hidden" id="logo_src" name="logo_src" value="" />

然后进行以下更改:

function swapImage(){
  var image = document.getElementById("logoimage");
  var dropd = document.getElementById("dd");
  var imgSrc = document.getElementById("logo_src");
  image.src = dropd.options[dropd.selectedIndex].title;
  imgSrc.value = image.src;   
};

process_rentals.php脚本中,添加:

$date=$_POST['date'];
$pic=($_FILES['logo_image']['name']);
$logo_source = $_POST['logo_src'];

然后,您将在处理脚本中获得所需的数据以添加到您的 mySQL 数据库中。

于 2013-07-06T03:11:04.083 回答