Jump to content

Recommended Posts

Hello there,

 

I own www.portlandmetal.net , which started as a simple HTML site (which I know a little more about), until my friend decided to spend a day and make my website a little more interesting.

 

While I like what he's done and I'm thankful for the help he's given me, he's a pretty busy guy and doesn't really have time to help me troubleshoot things.

 

Here is my problem: there is a form where visitors can enter some data for an upcoming show, and upon submission the show listing is supposed to appear on portlandmetal.net/listings.php , the private admin part of the website, for me to review and accept/decline. After the user clicks "submit" on the submission form, it redirects and shows a message like "thanks for submitting a show, an admin will review it shortly for approval." At this time, I am sent an email notification that someone has submitted a show. However, recently, when I go to review it, there's nothing to review; the information is getting lost somewhere. So, it's pretty frustrating to know that users are submitting things to my website, only to lose the data.

 

I know my friend is using some kind of a mysql database, which I know nothing about, or even where it's located.

 

I know my description has probably been pretty vague... please let me know what additional information you would need to help me with this problem. Should I attach the code from index.php?

 

Thanks a lot!

-Joe

Link to comment
https://forums.phpfreaks.com/topic/208059-new-to-php-user-submitted-data-is-lost/
Share on other sites

I added some de-bugging into this script.

 

PS. save this as index2.php, so you don't overwrite what is already there, and user's won't see the de-bugging.

<?php
include("includes/connections.php");
$datetoday = date("Y-m-d");
$futuredate = "2074-12-12";
$pastdate = "2000-12-12";

//************COMP UPDATE*****************//

if(isset($_REQUEST['listing_id']))
{
   if(isset($_REQUEST['delete']))
  {		
   mysql_query("DELETE FROM listing WHERE listing_id = ".$_REQUEST['listing_id']."") or die('Delete Error: ' . mysql_error());
   header("Location:index.php#".$_REQUEST['listing_id']."");
  }
}
//*Edit*//
if(isset($_REQUEST['update_listing']))
{
list($month, $day, $year) = explode('/', $_REQUEST['date']);
if(strlen($month<2)){$month = "0".$month;}
if(strlen($day<2)){$day = "0".$day;}
$date = "20".$year."-".$month."-".$day;



mysql_query("UPDATE listing SET date='".$date."', bands='".$_REQUEST['bands']."', venue='".$_REQUEST['venue']."',venue_url='".$_REQUEST['venue_url']."',age_id='".$_REQUEST['age_id']."',cost='".$_REQUEST['cost']."',door_cost='".$_REQUEST['door_cost']."',venue_start='".$_REQUEST['venue_start']."',music_start='".$_REQUEST['music_start']."',comments='".$_REQUEST['comments']."' WHERE listing_id = ".$_SESSION['listing_id']."") or die('Update Error ' . mysql_error());	

unset ($_SESSION['listing_id']);
}
/*ADD COMP*/
if(isset($_REQUEST['add_listing']))
{	
list($month, $day, $year) = explode('/', $_REQUEST['date']);
if(strlen($month<2)){$month = "0".$month;}
if(strlen($day<2)){$day = "0".$day;}
$date = "20".$year."-".$month."-".$day;

if($_REQUEST['venue_start']=='HH:MM') $venue_start="";
else $venue_start=$_REQUEST['venue_start'];

if($_REQUEST['music_start']=='HH:MM') $music_start="";
else $music_start=$_REQUEST['music_start'];



mysql_query("INSERT INTO listing (date, bands, venue, venue_url, age_id, cost, door_cost, venue_start, music_start, comments, approved)
VALUES ('".$date."', '".$_REQUEST['bands']."', '".$_REQUEST['venue']."', '".$_REQUEST['venue_url']."', '".$_REQUEST['age_id']."', '".$_REQUEST['cost']."', '".$_REQUEST['door_cost']."', '".$venue_start."', '".$music_start."', '".$_REQUEST['comments']."', '0')") or die('Insert error: ' . mysql_error());

unset ($_SESSION['listing_id']);
  header("Location:index.php?thanks");
}
//*************END COMP UPDATE***************//



//Include header
include("includes/header.php");

//Top Bar info/Nav
$pagetitle = "Portland, Salem, Eugene Metal Show Listings";
$to = "admin@portlandmetal.net";
$subject = "New show";
$body = "";
echo "<div class='titlebox'>".$pagetitle."";
echo "</div><div class='contentbox'>";

if(isset($_REQUEST['thanks']))
{
echo "<div class='thanksbox'>";
echo "Thanks for submitting a show. If you don't see it listed here within 24 hours, please contact me at admin@portlandmetal.net (we have experienced a lot of issues with the code and need to troubleshoot!).";
echo "</div>";
mail($to, $subject, $body);
}





//*************************************************RACE REGISTRATION FUNCTION*************************
if(isset($_REQUEST['upcoming']))
{
$listingstring = "SELECT listing_id, date, bands, venue, venue_url, age_id, cost, door_cost, venue_start, music_start, comments FROM listing WHERE approved = '1' AND date BETWEEN '".$datetoday."' AND '".$futuredate."' ORDER by approved, date";
}
else if(isset($_REQUEST['archives']))
{
$listingstring = "SELECT listing_id, date, bands, venue, venue_url, age_id, cost, door_cost, venue_start, music_start, comments FROM listing WHERE approved = '1' AND date BETWEEN '".$pastdate."' AND '".$datetoday."' ORDER by approved, date DESC";
}
else
{
$listingstring = "SELECT listing_id, date, bands, venue, venue_url, age_id, cost, door_cost, venue_start, music_start, comments FROM listing WHERE approved = '1' AND date BETWEEN '".$datetoday."' AND '".$futuredate."' ORDER by approved, date";
}
$listingquery = mysql_query($listingstring) or die('Error in: ' . $listingstring . ' <br />' . mysql_error());	
?>
<form method="POST" action="index.php">
<div class="graybox margin">
<?php 
if(isset($_REQUEST['upcoming']))
{
echo "<strong>Current Upcoming Shows</strong>    <a href='index.php?archives'>See Archives</a><br /><br />";
}
else if(isset($_REQUEST['archives']))
{
echo "<strong>Past Shows</strong>    <a href='index.php?upcoming'>See Upcoming Listings</a><br /><br /><br />";
}
else
{
echo "<strong>Current Upcoming Shows</strong>    <a href='index.php?archives'>See Archives</a><br /><br />";
}
?>
<table width="100%" cellpadding="8px">
<?php

while($row = mysql_fetch_assoc($listingquery))
{
$bands = $row['bands'];
if(strlen($bands)>200)
{
$bands = substr($bands, 0, 200)."...";
}
//IF THE USER SELECTED TO EDIT A RACE//
if(isset($_REQUEST['details']))
{
	if($_REQUEST['listing_id']==$row['listing_id'])
	{
		$_SESSION['listing_id']=$row['listing_id'];
		?>
<tr>
<td width="90%" colspan="7" class="listing_details">
    <a name="details"></a>
   <h2><?php echo $row['bands'];?></h2>
    <h3><?php echo date("l, F jS Y",strtotime($row['date']));?></h3>
    <strong><a href="<?php echo $row['venue_url'];?>" target="blank"><?php echo $row['venue'];?></a></strong> 
<?php if($row['age_id']==1) echo "All Ages";?>    
<?php if($row['age_id']==2) echo "18+";?>
<?php if($row['age_id']==3) echo "21+";?><br />

<?php if(empty($row['cost']))
			  {
echo "$".$row['door_cost']." at the door";
			  }
			  else if(empty($row['door_cost']))
			  {
			echo "$".$row['cost'];	  
			  }
			  else
			  {
				 echo "$".$row['cost'].", $".$row['door_cost']." at the door";	 
			  }
			  
			  
                  echo "<br />";
                  if($row['venue_start']=="00:00:00") echo date("g:i a",strtotime($row['music_start']));
else if($row['music_start']=="00:00:00") echo date("g:i a",strtotime($row['venue_start']));
else echo "Doors Open at ".date("g:i a",strtotime($row['venue_start'])).", Music Starts at ".date("g:i a",strtotime($row['music_start']));

?><br />

<?php
if(empty($row['comments'])){}
		  else{
			  echo "<br /><strong>Additional Comments</strong><br />";
echo $row['comments'];
		  }?>
<br />
<input type="hidden" name="listing_id" value="<?php $row['listing_id']?>" />
<?php if(isset($_REQUEST['archives']))
{
echo "<input type='hidden' name='archives'/>";	
}
?>
    </td>
    <td width="10%" class="listing_details">
    <input type="submit" name="cancel_listing" value="Close Details" />
    </td>
    </tr>
<?php
}
	else{
echo "<tr>";
echo "<td width='8%'><a name='".$row['listing_id']."'></a>".date("M j (D)",strtotime($row['date']))."</td>";
echo "<td width='8%'><strong>".$bands."</strong></td>";
echo "<td width='8%'>".date("g:i a",strtotime($row['venue_start']))."</td>";
if(empty($row['cost']))
			  {
echo "<td width='16%'>$".$row['door_cost']." at the door</td>";
			  }
			  else if(empty($row['door_cost']))
			  {
			echo "<td width='16%'>$".$row['cost']."</td>";	  
			  }
			  else
			  {
				 echo "<td width='16%'>$".$row['cost'].", $".$row['door_cost']." at the door</td>";	 
			  }
echo "<td width='16%'><a href='".$row['venue_url']."' target='blank'>".$row['venue']."</a></td>";
echo "<td width='8%'>";
if($row['age_id']=='1')echo "All Ages"; 
else if($row['age_id']=='2')echo "18+";
else if($row['age_id']=='3')echo "21+";
echo "</td>";

echo "<td width='26%'>";




echo "</td>";
echo "<input type='hidden' value='".$row['listing_id']."' name='listing_id'>";
if(isset($_REQUEST['archives']))
{
echo "<td width='10%'>   <a href='index.php?archives&listing_id=".$row['listing_id']."&details=1#details'>Details</a></td>";	
}
else{
echo "<td width='10%'>   <a href='index.php?listing_id=".$row['listing_id']."&details=1#details'>Details</a></td>";	}
echo "</tr>";
	}
}
	else{
		echo "<tr>";
echo "<td width='8%'><a name='".$row['listing_id']."'></a>".date("M j (D)",strtotime($row['date']))."</td>";
echo "<td width='24%'><strong>".$bands."</strong></td>";
if($row['venue_start']=="00:00:00") echo "<td width='8%'>".date("g:i a",strtotime($row['music_start']))."</td>";
else if($row['music_start']=="00:00:00") echo "<td width='8%'>".date("g:i a",strtotime($row['venue_start']))."</td>";
else echo "<td width='8%'>".date("g:i a",strtotime($row['venue_start']))."</td>";
if(empty($row['cost']))
			  {
echo "<td width='16%'>$".$row['door_cost']." at the door</td>";
			  }
			  else if(empty($row['door_cost']))
			  {
			echo "<td width='16%'>$".$row['cost']."</td>";	  
			  }
			  else
			  {
				 echo "<td width='16%'>$".$row['cost'].", $".$row['door_cost']." at the door</td>";	 
			  }
echo "<td width='16%'><a href='".$row['venue_url']."' target='blank'>".$row['venue']."</a></td>";
echo "<td width='8%'>";
if($row['age_id']=='1')echo "All Ages"; 
else if($row['age_id']=='2')echo "18+";
else if($row['age_id']=='3')echo "21+";
echo "</td>";
echo "<td width='16%'>";

echo "</td>";
echo "<input type='hidden' value='".$row['listing_id']."' name='listing_id'>";
if(isset($_REQUEST['archives']))
{
echo "<td width='20%'>   <a href='index.php?archives&listing_id=".$row['listing_id']."&details=1#details'>Details</a></td>";		
}
else{
echo "<td width='20%'>   <a href='index.php?listing_id=".$row['listing_id']."&details=1#details'>Details</a></td>";	}
echo "</tr>";
echo "</tr>";
}
}

echo "</table>";
echo "<a name='new_listing'></a>";
if(isset($_REQUEST['new_listing']))
{
		$_SESSION['listing_id']=$row['listing_id'];
		?>
     <div class="addnewcontainer"><div class="addnewtitle"></div></div>       
<div class="add_listing_public">
    <label for="date">Date: </label><input name="date" type='text' value="MM/DD/YY"/><br />
<label for="bands">Bands: </label><input style="width:350px" name="bands" type="text"/><br />
       <label for="venue">Venue: </label><input style="width:300px;" name="venue" type="text" /><br />
    <label for="venue_url">Website: </label><input style="width:300px;" name="venue_url" type="text" value="http://" /><br />
    <label for="age_id">Age: </label>
    <select name="age_id">
    <option value="1">All Ages</option>
    <option value="2">18+</option>
    <option value="3">21+</option>
    </select><br />
    <label for="cost">Cost: $</label><input style="width:3em;" name="cost" type="text" /><br />
    <label for="door_cost">Door Cost: $</label><input style="width:3em;" name="door_cost" type="text" /><br />
    <label for="venue_start">Venue Start: </label><input name="venue_start" type="text" value="HH:MM" /> <span class='notes'>(Military Time)</span><br />
        <label for="music_start">Music Start: </label><input name="music_start" type="text" value="HH:MM"/> <span class='notes'>(Military Time)</span><br />
                <label for="comments">Comments: </label><br />
<textarea cols="60" rows="4" name="comments" type="text" /></textarea><br />

<input type="submit" name="add_listing" value="Add" /> <input type="submit" name="cancel_listing" value="Cancel" />
<?php } ?>
<br />

<?php if(isset($_REQUEST['new_listing'])) echo""; else{?>
<div class="listshow">Know about a show? Submit one! <br />
It's free and fast (no account required):<br />
<br />
<input type="submit" name="new_listing" value="Submit New Show" /></div>
<?php } ?>
</div></div>
</div>
</form>

<?php
//*************************************************END RACE REGISTRATION FUNCTION*************************



echo"</div>";

//INCLUDE FOOTER
include("includes/footer.php"); ?>

I think I found one possible cause of the problem...

 

My code changes the user-entered year from "10" to "2010", automatically adding the "20" in front. If users enter "2010" rather than "10" as instructed, the year becomes "202010", which is outside the range of the "futuredate" parameter of 2074. I'll try changing the future date to 202074 and see if that works (I can always change a mis-entered date myself).

 

Another upgrade I'd like to make is to have the submission form be a bit easier... maybe click a button and select the date from a calendar, or something like that. I don't have much of an idea how to do it though.

 

Thanks again,

-Joe

 

Edit: that didn't work. I'm guessing php has a function similar to "Right()" in Excel VBA, maybe I'll add a line like "if string length =4 then year = right(year, 2)"

Sorry for the multiple posts in a row. It seems like I can't edit my last post anymore.

 

I changed this code

 

//*Edit*//
if(isset($_REQUEST['update_listing']))
{
list($month, $day, $year) = explode('/', $_REQUEST['date']);
if(strlen($month<2)){$month = "0".$month;}
if(strlen($day<2)){$day = "0".$day;}
$date = "20".$year."-".$month."-".$day;

 

to read:

//*Edit*//
if(isset($_REQUEST['update_listing']))
{
list($month, $day, $year) = explode('/', $_REQUEST['date']);
if(strlen($month<2)){$month = "0".$month;}
if(strlen($day<2)){$day = "0".$day;}
if(strlen($year<4)){$year = "20".$year;}
$date = $year."-".$month."-".$day;

 

but no success on the 2010 problem.

Try:

//*Edit*//
if(isset($_REQUEST['update_listing']))
{
list($month, $day, $year) = explode('/', $_REQUEST['date']);
if(strlen($month<2)){$month = "0".$month;}
if(strlen($day<2)){$day = "0".$day;}
if(strlen($year<4)){$year = "20".substr($year,-2);}
$date = $year."-".$month."-".$day;

 

Also, you are getting header errors, make sure your file has no spaces above, or in front of, the "<?php", or after the "?>" in your index file, and your included file.

Hello,

 

I realized the problem is that I changed the code in the "Edit" section of code instead of the "add new listing" section :) so that solved this problem.

 

Still, I don't know if that was the only thing keeping listings from appearing. My friend added ~5-6 shows today, which was a good test; I think he had to do a few re-dos though.

 

I don't like the current submission form because the user really has to be careful to follow the format, and there's a lot of text entering. I think changing to a better form (mainly having a calendar that pops up, and a better way of entering the start times I guess) would be helpful both for user ease of interaction, and for data consistency. Also it should prompt people for necessary information like the date if they forgot it. Should I start a new thread for this or is it OK to discuss here?

 

Many thanks,

-Joe

Cool. Thanks for the suggestions, I'll check it out.

 

My friend showed me how to access the database, and from what I've seen there, the ones that didn't go through had problems with the date. So now I can troubleshoot the problems on my own, and manually edit the ones that doesn't appear on the website. So I'm happy.

 

If I need more help with the calendar / time, I'll make another thread.

 

Thanks,

-Joe

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.