Jump to content

Have PHP script - don't know SQL table schema to create for it?


Padgoi

Recommended Posts

I was wondering if anyone could help me - I have a PHP script.  I know it works, but I'm not sure of the SQL table structure that I have to create in order for it to work properly.  I was wondering if anyone could help me?  I'll attach the file(s) to this message.  Any help is greatly appreciated.  

Link to comment
Share on other sites


<?php


if(isset($id)){?>
<html>
<HEAD>
<STYLE type="text/css">
<!--
td { vertical-align: top; }
#corner { display: block; position: absolute; left: 0; top: 0px; overflow: visible; width: 100px; height: 100px; margin: 0 0 0 0; padding: 0; z-index: 9999; border: none; float: none; }
#infobar { display: none; z-index: 1; height: 100px; width:100%; top: 0; left: 0; position: absolute; margin: 0px 0px 0px 0px; background-color: #FFFFFF; overflow: hidden; border-bottom: dotted 1px #000; }
#keywords { border: 1px solid black; padding: 5px 5px 5px 5px; width: 500px; text-align: left;}
.keyword { background-color: #CCCCFF; color:0000FF; text-decoration:underline; font-weight:bold; }
#loader { position: relative; top: 200px; border: 0px; display: block; }
-->
</STYLE>
<script type="text/javascript">

var is_vis = false;

function showvote() {
if (is_vis == false) {
document.getElementById('infobar').style.display = 'block';

if (document.getElementById('corner') != false) {
document.getElementById('corner').style.display = 'none';
}
if (document.getElementById('restroom') != false) {
document.getElementById('restroom').style.display = 'none';
}

is_vis = true;
} else {

document.getElementById('infobar').style.display = 'none';

if (document.getElementById('corner') != false) {
document.getElementById('corner').style.display = 'block';
}
if (document.getElementById('restroom') != false) {
document.getElementById('restroom').style.display = 'block';
}


is_vis = false;
}

return false;
}

</script>


</HEAD>
<body>

<?php
$part1=' <div id="corner"> <img src="CE2.gif" border="0" usemap="#rc" style="filter:alpha(opacity=60);opacity: 0.60;-moz-opacity:0.60;"> <map name="rc">

<area shape="poly" coords="0,0,100,0,0,100" href="#" onclick="javascript:showvote(); return false;" title="" /></map></div><div id="restroom"></div> <div id="infobar">

<table align="left"><tr><td style="text-align: center;">
<a onclick="javascript:showvote(); return false;"><img src="CE2.gif" border="0"></a>
<br></td><td>

';

$part2='
</td>
</tr>
</table>
</div>';


}
function stars($rating){
if($rating!=0){
$disp="<br />";
for($i=1;$i<=$rating;$i++)
$disp.="<img src=\"star.png\">";
$disp.=""; } else { $disp="<br/><img src=blank.gif width=12 height=12>";}
return $disp;
}
function show_site2($skey, $title, $rating, $user, $image)
{ $disp= stars($rating);
//$br="";
//if($rating=0)
//$br="<br />";
return sprintf("<center><a href=\"?id=%s\">%s</a> %s<br /><a href=\"?id=%s\"><img height=75 width=75 src=\"%s\"></a><br />By <a href=\"?u=%s\">%s</a></center><br />\n", $skey, $title, $disp,$skey, $image,$user,$user);
}
function show_site($skey, $title, $rating, $user, $image)
{//<a href=\"wlist.php?u=%s\">
//$br="";
$disp= stars($rating);
//if($rating=0)
//$br="<br />";
return sprintf("<td width=150><center><a href=\"?id=%s\">%s </a>%s<br /><a href=\"?id=%s\"><img height=75 width=75 src=\"%s\"><br /></a>By <a href=\"?u=%s\">%s</a></center><br /><br /></td>\n", $skey, $title, $disp,$skey,$image,$user,$user);
}

include("wootcfg.php");

if(isset($_GET[$uname]))
{
if($_GET[$uname] == $pword)
{
setcookie('lol', md5($pword), time() + 3600);
header('location: ?');
die('Logged in');
}
}
if(isset($latest)){
title('Top 5 Strips', 'Top 5 Strips','',true);
echo 'Menu:<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="?new">Create New Single Panel Strip</a><br/> <a href="?list=1">View Available 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a><br />';
$q = 'SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where panels>=3 GROUP BY `sid` ORDER BY `avg` DESC LIMIT 0,5';
echo "<table><tr><td width=300 valign='top'>";
echo '<h2><center>Top Rated</center></h2><br />';

for($r = mysql_query(sprintf($q, 'avg')); $row = mysql_fetch_assoc($r)
{
echo show_site2($row['sid'], $row['title'], round($row['avg'], 2),$row['creator'],$row['file']);
}

echo '</td><td width =300 valign="top"><h2><center>Latest</center></h2><br />';
$q = 'SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` GROUP BY `sid` ORDER BY `id` DESC LIMIT 0,5';
for($r = mysql_query(sprintf($q, 'id')); $row = mysql_fetch_assoc($r)
{
$prnt=$row['parent'];
if($row['sid']==$row['parent']){
echo show_site2($row['sid'], $row['title'], round($row['avg'], 2),$row['creator'],$row['file']);} else {
$sql="select * from groupcomic where sid='$prnt'";
$res=mysql_query($sql);
$prnet=mysql_fetch_assoc($res);
$title=$prnet['title'];
echo show_site2($row['sid'], $title, round($row['avg'], 2),$row['creator'],$row['file']);
}
}
echo "</td></tr></table>";



}
if(!isset($list) && !isset($new) && !isset($id) && !isset($latest) && !isset($woot) && !isset($u)){
title('WootStrips', 'WootStrips','',true);

?>Welcome to the new and improved WootStrips, a unique idea that allows users to create their own funny images or comic strips. Using the Paint program on your computer, users can easily
create their own humorous pictures, images, or strips by drawing a simple image or skit and saving it as a <b>.jpg, .gif, .jpeg, .bmp, or .png</b> file. Users can then take those image files and
insert them into the Creation Form. However, now, users can also create single-panel strips and have OTHER USERS continue the strips by adding their own panels. It really can be a blast! Not only that, but any really funny strips will be put on the homepage for other
users to enjoy. So give it a try. <br><br>

A brief description of the Menu Options below:<br>
<b>Create New Complete Strip</b> - create your own full and completed Strip, just like before. This will now net you 50 Woot Bux.<br>
<b>Create New Single Panel Strip</b> - create a single panel of a comic strip. Another user will add the second panel and a third user will add the third. Three panels = a completed strip. All users who contribute a panel get credit and 25 Woot Bux.<br>
<b>View Available 1 or 2-panel Strips</b> - if you wanna see the unfinished strips, click one of these choices to see them and to add a panel.<br><br>

Please enter your <b>exact forum username</b> in the column marked username in order to receive Woot Bux for each submission. You will receive 4 Woot Bux for new complete submissions and 2 Woot Bux for each additional single-panel entry.<br><br>

You have 2 options in submitting a Strip:<br><br>

1. <a href="http://www.wootability.com/draw/dessin.php">Click Here</a> to begin drawing your Strip using the WootPad. Upon completing your Strip,
click the save button. Once saved, choose the number of your Strip in the dropdown menu and click edit, then click Viewing Mode at the top of the screen.
In viewing mode, click "Convert file to .jpeg image" and save to your computer. Then upload that file in the form below in the column marked Strip Image File and complete the rest of the form.<br><br>

2. Open the MSPaint program on your computer (click Start - Programs - Accessories - Paint) and draw an image or skit to begin the process. Then upload that image and fill out the rest of the form. Anyone can try, no registration necessary!
<br><br>
<?php

echo '<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="?new">Create New Single Panel Strip</a><br/> <a href="?list=1">View Available 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a>';
}
if(isset($list)){
title("List",'','',true);

echo 'Menu:<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="?new">Cretae New Single Panel Strip</a><br/> <a href="?list=1">View Available 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a><br/>';
if(!empty($list)){
$sql="select * from groupcomic where panels=$list and sid=parent";
if($list==3)
$sql="SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where `panels`>=3 GROUP BY `sid` ORDER BY `avg` DESC";
$r=mysql_query($sql);
$num_entrys=mysql_num_rows($r);
$remain=$num_entrys % 4;
$entrys_per_row=floor(($num_entrys-($remain))/4);
//get average


echo "<br /><center><table>";
for($i=1; $i<=$entrys_per_row;$i++)
{
echo "<tr>";
for($j=1;$j<=4;$j++){
$row=mysql_fetch_assoc($r);
$id=$row['sid'];
$avg=0;
if($row['panels']>=3){

$avg=$row['avg'];
}
echo show_site($row['sid'], $row['title'], round($avg,2),$row['creator'],$row['file']);
}
/* if($i < $remain){
$row=mysql_fetch_assoc($r);
echo show_site($row['sid'], $row['title'], round($row['avg'], 2),$row['user'],$row['image']);
}*/
echo "</tr>";
}
echo "<tr>";
while($row=mysql_fetch_assoc($r)){
$avg=0;
if($row['panels']>=3){
$avg=$row['avg'];
}

echo show_site($row['sid'], $row['title'], round($avg,2),$row['creator'],$row['file']);
}
echo "</tr></table></center>";
}
}

if(isset($u)){
title("$u's Comics","$u's Comics",'',true);
$sql="SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where creator='$u' GROUP BY `sid` ORDER BY `title` Asc";
$result=mysql_query($sql);
$num_entrys=mysql_num_rows($result);


$remain=$num_entrys % 4;
$entrys_per_row=floor(($num_entrys-($remain))/4);
echo "<br /><center><table>";
for($i=1; $i<=$entrys_per_row;$i++)
{
echo "<tr>";
for($j=1;$j<=4;$j++){
$row=mysql_fetch_assoc($result);
$id=$row['sid'];
$avg=0;
if($row['panels']>=3){

$avg=$row['avg'];
}
$parz=$row['parent'];
$sql="SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where sid='$parz' GROUP BY `sid` ORDER BY `title` Asc";
$r2=mysql_fetch_assoc(mysql_query($sql));

echo show_site($row['parent'], $r2['title'], round($r2['avg'],2),$row['creator'],$row['file']);
}
/* if($i < $remain){
$row=mysql_fetch_assoc($r);
echo show_site($row['sid'], $row['title'], round($row['avg'], 2),$row['user'],$row['image']);
}*/
echo "</tr>";
}
echo "<tr>";
while($row=mysql_fetch_assoc($result)){
$avg=0;
if($row['panels']>=3){
$avg=$row['avg'];
}
$parz=$row['parent'];
$sql="SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where sid='$parz' GROUP BY `sid` ORDER BY `title` Asc";
$r2=mysql_fetch_assoc(mysql_query($sql));
echo show_site($row['sid'], $r2['title'], round($r2['avg'],2),$row['creator'],$row['file']);
}
echo "</tr></table></center>";




}
if(isset($id) && !isset($list) && !isset($u)){
$q="select * from groupcomic where sid='$id'";
$result=mysql_query($q);
$info=mysql_fetch_assoc($result);
$title=$info['title'];
$nsfw=$info['nsfw'];
$npanels=$info['panels'];
title($title);
$q = mysql_query('SELECT * FROM `yrat` WHERE `skey` = \'' . mysql_real_escape_string($_GET['id']) . '\' AND `ip` = \'' . $_SERVER['REMOTE_ADDR'] . '\'');
if(isset($_POST['rate']))
{
if(mysql_num_rows($q) > 0)
{
$msg = 'You have already rated this site.';
}
else
{
mysql_query('INSERT INTO `yrat` (`skey`, `rating`, `ip`) VALUES(\'' . mysql_real_escape_string($_GET['id']) . '\', ' . intval($_POST['rating']) . ', \'' . addslashes($_SERVER['REMOTE_ADDR']) . '\')') or die(mysql_error());
$msg = 'Rating successful.';
}
}
else
{
if(mysql_num_rows($q) > 0)
{
$q = mysql_query('SELECT SUM(`rating`), COUNT(`rating`) FROM `yrat` WHERE `skey` = \'' . mysql_escape_string($_GET['id']) . '\'') or die(mysql_error());
$r = mysql_fetch_row($q);

$msg = 'Rating: ';
if($r[0] == 0)
{
$msg .= '0.00';
}
else
{
$msg .= round($r[0] / $r[1], 2);
}
}
else
{
$msg = '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
Rate this site:
<select name="rating">';

for($i = 1; $i <= 5; $i++)
{
$msg .= "<option value='$i'>$i</option>\n";
}

$msg .= ' </select>
<input type="submit" value="Rate" name="rate" />
</form>';
}
}




//echo 'Menu:<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="">Create New Single Panel Strip</a><br/> <a href="?list=1">View Available 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a><br /><br />';
if(!isset($pass) && $nsfw){
echo "This strip is NSFW! <a href=\"?pass&id=$id\">I affirm I am 18+</a>";

} else {
$q2="select * from groupcomic where sid='$id' or parent='$id' order by id asc";
$res2=mysql_query($q2);
$comic=mysql_fetch_array($res2);
$title=$comic['title'];
$maintitle=$title;
$author=$comic['creator'];
$authors="<a href=?u=$author>$author</a>";
$imagesrc=$comic['file'];

$key=$comic['sid'];
if($npanels!=4) {$something="height=400 width=350";} else { $something="";}
echo "<table><tr><td><img $something ALT=\"$title\" src=\"$imagesrc\"><br /><center><a href=?u=$author>$author</a></center></td>";
$i=1;
while($comic=mysql_fetch_array($res2)){
$title=$comic['title'];
$author=$comic['creator'];
$imagesrc=$comic['file'];
$id=$comic['sid'];
$authors.=", <a href=?u=$author>$author</a>";
$i++;
echo "<td><img ALT=\"$title\" height=400 width=350 src=\"$imagesrc\"><br /><center><a href=?u=$author>$author</a></center></td>";
}
echo "</tr></table><br/>";
if($npanels<3){
$nextpan=$npanels+1;
echo "<center><a href=\"?new&parent=$key&npan=$nextpan\">Create New Panel for this strip</a></center>";

} else {
echo $part1 ."<table><tr><td colspan=2>". $msg ."</td><td width=225 align=right><a href=\"com_comments.php?id=$id\" target=\"new\">View/Add Comments</a></td></tr><tr><td>Title:<br />Author:</td><td>$maintitle<br />$authors<br /></td></tr></table>". $part2;
echo "<center>Strip Is CLOSED!</center>";
}
} }
if(!isset($_POST['add']) && !isset($id) & !isset($list) & isset($new)){
title("New Strip", "New Strip",'',true);
echo 'Menu:<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="?new">Create New Single Panel Strip</a><br/> <a href="?list=1">View Available 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a><br /><br />'; ?>

<form action="" method="post" name="hi" enctype="multipart/form-data">
<?php
$nodisp='';
if(isset($parent)){
$par=$parent;

$nodisp="style='display:none;'";}
else {
$npan='';
$par='';
echo "Choose a Title for your Strip: ";
}
echo "<input type=\"text\" $nodisp name=\"title\" value=\"$par$npan\">";
?>
(20 character limit)
<script>
displaylimit("document.hi.title","",20)
</script><br />
Your UserName: <input type="text" name="username" value="" />
(15 character limit - use exact Forum log-in name)
<script>
displaylimit("document.hi.username","",15)
</script><br />

The Strip image file: <input type="file" id="image" name="image" /><br />
<?php
if(isset($complete)){
echo "<input type=\"hidden\" name=\"complete\" value=\"true\">";
}
if(!isset($parent))
$parent="";
echo "<input type=\"hidden\" name=\"parent\" value=\"$parent\">" ?>
<input type="checkbox" name="nsfw" id="nsfw" value="1" /> <label for="nsfw" title="Not Safe For Work">NSFW</label><br />
<input type="submit" name="add" value="Submit Comix!" />
</form>

<?php
}elseif(isset($_POST['add'])){
title("Strip Submitted",'','',true);
//echo 'Menu:<br /><a href="?new&complete">Create New Complete Strip</a><br /><a href="?new">Create New Single Panel Strip</a><br/> <a href="?list=1">View Availeable 1-Panel Strips</a><br/> <a href="?list=2">View Available 2-Panel Strips</a><br/><a href="?list=3">View Completed Strips</a><br/><a href="?latest">Top 5 Strips</a><br /><br />';
$key = strtolower(preg_replace('#[^a-zA-Z0-9\-]#', '', str_replace(array(' ', '_'), '-', $_POST['title'])));
$query="select * from groupcomic where parent='$key'";
if(isset($_POST['complete']))
{$pnum=4;}else{$pnum=1;}
$numrows=mysql_num_rows(mysql_query($query));
$errors = array(

'Please choose another title' => (strlen($key) < 1 || mysql_num_rows(mysql_query('SELECT * FROM `groupcomic` WHERE `sid` = \'' . $key . '\'')) > 0),
'Error with upload - make sure that you are uploading an allowed type of image and/or music' => upload($key,1),
'Please submit an image' => strlen($_FILES['image']['name']) < 1,
'There are already 3 panels to this strip' => $numrows==3,
'Invalid username' => strlen($_POST['username']) < 1,
);

if(in_array(true, $errors))
{
echo "<h2>Error</h2>\n";
foreach($errors as $msg => $v)
{
if($v)
{
echo "<h3>" . $msg . "</h3>";
}
}
}else{
$creator=htmlspecialchars($_POST['username']);
$title=htmlspecialchars($_POST['title']);
$added=time();
$parent=$_POST['parent'];
if(!empty($parent)){
$sql="update groupcomic set panels = panels+1 where sid='$parent'";
mysql_query($sql);
} else {
$parent=$key;
}
$imgfile=$_GET['new_image'];
$nsfw=(isset($_POST['nsfw']) ? 1 : 0);
$q ="insert into groupcomic (sid, title, creator, added, panels, nsfw, file, parent) values ('$key', '$title', '$creator', $added, $pnum, $nsfw, '$imgfile', '$parent')";
// echo "$q";

mysql_query($q) or die('Error in SQL.<br />' . mysql_error() . '<br />' . $q);


$user=$_POST['username'];

if(isset($_POST['complete'])){
$padd=25;}else{$padd=10;}
$sql="update ibf_members set points=points+$padd where name='$creator'";
mysql_query($sql);
echo 'Thank you for your submission. If you entered your forum username in correctly, you will be awarded Woot Bux. If you do not have a forum username, you will not be awarded any Bux, but you can <a href="http://www.wootability.com/Woot">Click Here</a> to register.';
die('<h2>Success!</h2> You have submitted your site. <a href="?id=' . $parent . '">Click here to be taken to it.</a>');
}
}



if($ADMIN)
{
if(isset($_GET['key']))
{
$k = $_GET['key'];

echo '<h2>Editing ' . $k . "</h2>\n";
if(isset($_GET['del']))
{
mysql_query('update groupcomic set panels=panels-1 where sid=\'' . addslashes($p) . '\'');
mysql_query('DELETE FROM `groupcomic` WHERE `sid` = \'' . addslashes($k) . '\'');
mysql_query('update groupcomic set parent=\'\' where parent=\'' . addslashes($k) . '\'');

echo $k . ' was deleted';
}
else
{
echo 'Are you sure you want to delete? <a href="?key=' . $k . '&p='.$p.'&del">Yes</a>';
}

echo '<br /><a href="?">Go Back</a>';
}
else
{
if(isset($_GET['logout'])) { setcookie('lol', '', 1); header('location: ?'); }
echo "<h2>Current Comix</h2>\n";
$q = mysql_query('SELECT * FROM `groupcomic`');
while($r = mysql_fetch_assoc($q))
{
echo '<a href="?id=' . $r['sid'] . '">' . $r['title'] . '</a> - <a href="?key=' . $r['sid'] . '&p='.$r['parent'].'"' . ">Delete</a><br />\n";
}
echo '<h3><a href="?logout">Logout</a></h3>';
}
}

?>
Link to comment
Share on other sites

I know it works

 

how do you know that it works? do you have a working system that you just need to get the table definitions for? if so, you can use a SHOW CREATE TABLE table_name query.

 

did you not try to do this yourself? it's pretty straight-forward. find the queries, make a list of the fields for each database table, either used directly in a query or in the data fields fetched from a query, and determine the datatype of each field.

Link to comment
Share on other sites

how do you know that it works? do you have a working system that you just need to get the table definitions for? if so, you can use a SHOW CREATE TABLE table_name query.

 

did you not try to do this yourself? it's pretty straight-forward. find the queries, make a list of the fields for each database table, either used directly in a query or in the data fields fetched from a query, and determine the datatype of each field.

 

Yes, it's working, I just need the table structure to save the entries.  My SQL skills are not up to snuff with you guys, that's why I was asking for help.  I don't know how to run this show create table query you speak of.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.