我是一个相当新的程序员,我目前正致力于为基于网络的艺术展创建一个程序,该程序将使用PHP表单中的数据显示随机图像和文本,这需要两者的输入。
我需要创建一个PHP表单,从访问者收集文本和图片。 示例PHP页面:
*What is your name?* = Max
*Upload photo.* = pic.jpg
完成的项目将是一个网页 - 在刷新时 - 会随机显示从PHP表单收集的图像和文本。因此,在刷新时,页面将显示随机文本输入(IE Max,Alan,Mark等)和随机图片(IE pic.jpg,pic1.jpg,pic2.jpg)我猜测是从MySQL数据库。< / p>
刷新页面因此会显示如下内容:
Max / pic.jpg
REFRESH
Alan / pic3.jpg
REFRESH
Mark / pic2.jpg
等等......
这是我到目前为止所做的:
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("mysite.com", "username", "password") or die(mysql_error()) ;
mysql_select_db("db_name") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
对此有任何帮助将不胜感激!
谢谢!
答案 0 :(得分:1)
首先,您需要创建html表单。我假设您对此有一些基本知识,所以我们假设您这样做并将其发布到post.php
。在这里你需要:
一些教程:
但是,这不是一项“微不足道”的任务。熟悉这些语言的人需要几天的时间,而如果你从头开始,可能需要一个星期的人。
答案 1 :(得分:1)
Pull out the data using
SELECT * FROM table ORDER BY RAND() LIMIT 0,1;
Then pull out the
<?
$sql=mysql_query("SELECT * FROM table ORDER BY RAND() LIMIT 0,1;");
while($row=mysql_fetch_array($sql)){
$name=$row['name'];
$imagename=$row['imagename'];
//write the logic here use echo or close and open php using <? and ?>
//giving an example
echo "Name: ".$name."<br>";
echo "<img src='directory/'".$imagename." width='100' height='100'>";
//OR other way
?>
Name : <? echo $name;?><br>
<img src="directory/<? echo $imagename;?>" width="100" height="100">
<?
}
?>