I've got a simple script that allows users to submit their own emoticons. The submissions get added to a 'pending' database. I'd like to then be able to review the submissions and authorize those that are appropriate.
Currently, the first part of the script works great, however, I'm having trouble with the second part that retrieves the rows from the 'pending' database. Each row is displayed along with a checkbox. On pressing submit, I'd like the records that are checked to be inserted into the main database and removed from the 'pending' one.
Here is the first script that displays the contents of the main database and also allows users to make submissions:
Code: Select all
<html>
<body>
<?php
#connect to mysql
$connection = @mysql_connect("localhost","user","pass")
or die("Sorry, unable to connect to MySQL");
#select db
$result = @mysql_select_db(asciiart,$connection)
or die("Sorry, unable to to get database.");
#--------------
# submit data
#--------------
if($_POSTї'submit'] and $title and $art)
{
#create query
$sql="insert into pending(author,title,art) values("$author", "$title", "$art")";
#execute query (result is bool)
$result=mysql_query($sql,$connection);
#success?
if(result){
$url=$PHP_SELF.'?processed=' .$title;
print "<html><head><meta http-equiv='Refresh' content='1; url=$url'></head></html>";
die("Processing record $title");
}
else{
echo("Record was not added successfully!");
}
}
#--------------
# retrieve data
#--------------
#create query
$sql="select author,title,art from asciiart";
#execute query (result is bool)
$result=mysql_query($sql,$connection);
#write the data
echo("<center>");
echo("<table width=600 border=0 bordercolor=#666666 bgcolor=#FFFFFF style="border: 1px solid #ccd7e0; background-color: #fff;">");
echo("<tr>");
$i=0;
while($currentRow = mysql_fetch_array($result))
{
echo("<td width=20%>");
echo("<font size="1" face="verdana">");
echo($currentRowї"title"] ."<br>");
echo("</font>");
echo("<font size="2" face="verdana">");
echo("<b>" .$currentRowї"art"] ."</b><br><br>");
echo("</font>");
echo("</td>");
$i++;
if($i==5){
echo("</tr>");
echo("<tr width=100%>");
$i=0;
}
}
echo("</tr>");
echo("</table>");
echo("</center>");
#close
mysql_close();
?>
<center>
<form action="<? echo($PHP_SELF); ?>" method="post">
<table bordercolor="#666666" bgcolor="#FFFFFF" style="border: 1px solid #ccd7e0; background-color: #fff;">
<tr>
<td colspan=2>
<table bgcolor="#ccd7e0" border=0 width=100%>
<tr width=100%><td>
<center><font face=verdana size=2>Submit your own art...</font></center>
</td></tr>
</table>
</td>
</tr>
<tr>
<td><font size=2 face=verdana>Your Name: </font></td>
<td><input type="text" name="author" size="18"></td>
</tr>
<tr>
<td><font size=2 face=verdana>Art Title: </font></td>
<td><input type="text" name="title" size="18"></td>
</tr>
<tr>
<td><font size=2 face=verdana>Emoticon: </font></td>
<td><input type="text" name="art" size="18"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit!"></td>
</tr>
</table>
</form>
</center>
</body>
</html>Code: Select all
<html>
<head>
<body>
<?php
#connect to mysql
$connection = @mysql_connect("localhost","user","pass")
or die("Sorry, unable to connect to MySQL");
#select db
$result = @mysql_select_db(asciiart,$connection)
or die("Sorry, unable to to get database.");
#--------------
# retrieve data
#--------------
#create query
$sql="select id,author,title,art from pending";
#execute query (result is bool)
$result=mysql_query($sql,$connection);
#write the data
echo("<form action="$PHP_SELF" method=post>");
echo("<center>");
echo("<table width=600 border=0 bordercolor=#666666 bgcolor=#FFFFFF style="border: 1px solid #ccd7e0; background-color: #fff;">");
echo("<tr>");
$i=0;
while($currentRow = mysql_fetch_array($result))
{
echo("<td width=20%>");
echo("<font size="1" face="verdana">");
echo($currentRowї"title"] ."<br>");
echo("</font>");
echo("<font size="2" face="verdana">");
echo("<b>" .$currentRowї"art"] ."</b><br><br>");
echo("</font>");
echo("<input type=checkbox name=" .$currentRowї"id"] ." value=off>");
echo("</td>");
$i++;
if($i==5){
echo("</tr>");
echo("<tr width=100%>");
$i=0;
}
}
echo("</tr>");
echo("</table>");
echo("</center>");
echo("<center><input type=submit name=submit value=Submit!></center>");
#close
mysql_close();
?>
<tr>
<td><td>
</tr>
</table>
</body>
</html>Thanks in advance!
CoreLEx