Jump to content

Recommended Posts

I am still learning to address the code errors. There are still many standard html issues with this that I have not begun to work on. Waitning on that until I get the script working right.

 

I have the username and password parts working perfectly. You can register and the information gets entered in the database and can be retrieved.

 

The problem is in the form. I am starting a memorial site and can not get the memorial posts to input in the database. Therefore, no retrieving information either.

 

Here is the code that I have for the php and html form pages. Any help is greatly appreciated.

 

Form Page

<script language="javascript">

function checkForm(theForm) {
    if(theForm.dead_person_f_name.value==""){
  alert("First Name is empty!");
      return false;
    }
    return true;
}
</script>
<?php
    $text = "";
    if (!isset($_COOKIE["logged"])) {
    $text .= "<table width=\"84%\"  border=\"0\">
    <form name=\"form1\" method=\"post\" action=\"login.php\">
      <table width=\"80%\"  border=\"0\" align=\"left\" class=\"text\">
        <tr> 
                        <td height=\"13\"><b>
					<font size=\"2\" color=\"#631503\" face=\"Arial\">Username 
					</font></b></td>
                      </tr>
                      <tr> 
                        <td><form name=\"form1\" method=\"post\" action=\"login.php\"><input name=\"username\" type=\"text\" size=\"23\"></td>
                      </tr>
                      <tr> 
                        <td height=\"20\" valign=\"bottom\"><b>
					<font size=\"2\" color=\"#631503\" face=\"Arial\">Password</font></b></td>
                      </tr>
                      <tr> 
                        <td><table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
                            <tr> 
                              <td><input name=\"password\" type=\"password\" size=\"23\"></td>
                              <td width=\"20\"><div align=\"center\"></div></td>
                            </tr>
                          </table></td>
                      </tr>
				  <tr> 
                        <td height=\"20\" valign=\"bottom\"><b>
					<font size=\"2\" color=\"#631503\" face=\"Arial\"><input type='submit' value='LOGIN'></font></b></td>
                      </tr>	
      </table>
    </form>";
    }

    elseif (isset($_COOKIE["logged"]) && $_COOKIE["logged"]==true) {
      include "config/db.php";
      $connection = mysql_connect($db_server,$db_user,$db_pass);
      mysql_select_db($db);

	$q1 = "select * from settings";
	$r1 = mysql_query($q1);
	while ($a1 = mysql_fetch_row($r1))
	{
		$swidth = $a1[8];
		$sheight = $a1[9];
		$sdwidth = $a1[10];
		$sdheight = $a1[11];
		$spcnt = $a1[12];
	}

      $query = "select mem from users where username='".$_COOKIE["username"]."'";
      $result = mysql_query($query);
      $row = mysql_fetch_row($result);
      if (isset($_GET["action"])) {
        $action = $_GET["action"];
        if ($action == "ok") {
          $text .= "Your memorial is now online. Let your family and friends know that they may view this anytime.<b>";
        }
	else
	{
		$text .= "<font color=#FF0000>Your photo is to big ( 1 megs max) or not a .jpg format.</font>";
	}
      }
      if ($action == "" || $action == "nok")
  {
	  if ($row[0]==1) {
		$text .= "<br>Your already have a memorial online, redo another account (username and password) to add another one!";
	  }
	  else {
		$text .= "";
		if (!isset($_COOKIE["fh"])) {
			$text .= "";
		}
		$text .= "<form action='add_memorial.php' method='post' enctype=\"multipart/form-data\" onsubmit=\"return checkForm(this)\">
				<table width='100%'>
				<tr>
					<td class='text'>Name of person</td>
					<td align='left' class='text'><table align='left'><tr><td align='left'>(First Name)</td><td align='left'>(Middle Name)</td><td align='left'>(Last Name)</td></tr>
								<tr><td align='left'><input type='text' size='13' name='dead_person_f_name'></td><td align='left'><input type='text' size='17' name='dead_person_m_name'><td align='left'><input type='text' size='15' name='dead_person_l_name'></td></tr>
						</table></td>
				</tr>
				<tr>
					<td class='text'>Town and State</td>
					<td><input type='text' size='43' name='dead_person_location'><br></td>
				</tr>
				<tr>
					<td class='text' valign='top'>Main Profile Photo( 1 meg max)</td>
					<td class='text'><input type='file' class='text' size='22' name='dimage'></td>
				</tr>
				<tr>
					<td class='text' valign='top'><b>Photo Album (1 meg max each)</td>
					<td class='text'>";
		for ($i = 0; $i < $spcnt; $i++)
		{						
			$text .= "<input type='file' class='text' size='22' name='images[]'> Text of photo <input type='text' class='text' size='50' name='title[]'><br>";
		}
		$text .= "</td>
				</tr>
				<tr>
					<td class='text'>Music (* midi or mp3 )</td>
					<td class='text'><input type='file' class='text' size='43' name='dead_person_sound'><br></td>
				</tr>
				<tr>
					<td class='text'>Birth Year</td>
					<td class='text'> 
						<select class='text' name='b_year'>";
		for ($i = 1850; $i <=2010; $i++)
		{							
			$text .= "<option value='$i' >$i</option>";
		}

		$text .= "</select>
					<br></td>
				</tr>
				<tr>
					<td class='text'>Past away Year</td>
					<td class='text'> 
						<select class='text' name='d_year'>";
		for ($i = 1851; $i <=2010; $i++)
		{							
			$text .= "<option value='$i' >$i</option>";
		}

		$text .= "</select>
			 </select>
					<br></td>
				</tr>
				<tr>
					<td class='text'>Memorial text or Prayer</td>
					<td class='text'><textarea rows='15' class='text' cols='50' name='memorial'></textarea><br></td>
				</tr>
				<tr>
					<td><br></td>
					<td><br><br></td>
				</tr>
				<tr>
					<td><br></td>
					<td><input type='submit' class='text' value='Create the memorial'></td>
				</tr>
				</table>
				</form>";
	  }
	}
      $text .= "";
    }
    include "template/index.php";
?>

 

Database


-- --------------------------------------------------------

--
-- Structure de la table `admin`
--

CREATE TABLE `admin` (
  `username` varchar(10) NOT NULL default '',
  `password` varchar(10) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `admin`
--

INSERT INTO `admin` VALUES('admin', 'demo');

-- --------------------------------------------------------

--
-- Structure de la table `condoleances`
--

CREATE TABLE `condoleances` (
  `id` int(10) NOT NULL auto_increment,
  `condoleance_for` varchar(100) NOT NULL default '',
  `condoleance_by_name` varchar(100) NOT NULL default '',
  `condoleance_title` varchar(200) NOT NULL default '',
  `condoleance_date` varchar(30) NOT NULL default '',
  `condoleance_by_relation` varchar(200) NOT NULL default '',
  `condoleance_by_email` varchar(100) NOT NULL default '',
  `condoleance` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=69 ;

--
-- Contenu de la table `condoleances`
--


-- --------------------------------------------------------

--
-- Structure de la table `funeral_homes`
--

CREATE TABLE `funeral_homes` (
  `id` int(10) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `username` varchar(20) NOT NULL default '',
  `password` varchar(20) NOT NULL default '',
  `website` text NOT NULL,
  `resell_id` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

--
-- Contenu de la table `funeral_homes`
--


-- --------------------------------------------------------

--
-- Structure de la table `memorials`
--

CREATE TABLE `memorials` (
  `id` int(10) NOT NULL auto_increment,
  `dead_person_f_name` varchar(100) NOT NULL default '',
  `dead_person_m_name` varchar(100) NOT NULL default '',
  `dead_person_l_name` varchar(100) NOT NULL default '',
  `dead_person_location` varchar(100) NOT NULL default '',
  `dead_person_birth` varchar(30) NOT NULL default '',
  `dead_person_death` varchar(30) NOT NULL default '',
  `dead_person_picture` text NOT NULL,
  `dead_person_sound` varchar(100) NOT NULL default '',
  `memorial` text NOT NULL,
  `memorializer_name` varchar(100) NOT NULL default '',
  `memorial_date` varchar(30) NOT NULL default '',
  `image_title` text NOT NULL,
  `image` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=130 ;

--
-- Contenu de la table `memorials`
--


-- --------------------------------------------------------

--
-- Structure de la table `reseller`
--

CREATE TABLE `reseller` (
  `resell_id` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `password` varchar(50) NOT NULL default '',
  `f_name` varchar(50) NOT NULL default '',
  `l_name` varchar(50) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`resell_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Contenu de la table `reseller`
--


-- --------------------------------------------------------

--
-- Structure de la table `settings`
--

CREATE TABLE `settings` (
  `tfont` varchar(150) NOT NULL default '',
  `dfont` varchar(150) NOT NULL default '',
  `tsize` int(3) NOT NULL default '0',
  `dsize` int(3) NOT NULL default '0',
  `clr` varchar(20) NOT NULL default '',
  `mfont` varchar(50) NOT NULL default '',
  `msize` tinyint(4) NOT NULL default '0',
  `bclr` varchar(15) NOT NULL default '',
  `width` int(4) NOT NULL default '0',
  `height` int(4) NOT NULL default '0',
  `dwidth` int(4) NOT NULL default '0',
  `dheight` int(4) NOT NULL default '0',
  `pcnt` tinyint(4) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `settings`
--

INSERT INTO `settings` VALUES('Monotype Corsiva', 'Monotype Corsiva', 7, 5, 'white', 'Verdana', 12, '#d66b21', 330, 330, 150, 150, 10);

-- --------------------------------------------------------

--
-- Structure de la table `users`
--

CREATE TABLE `users` (
  `id` int(10) NOT NULL auto_increment,
  `username` varchar(20) NOT NULL default '',
  `password` varchar(20) NOT NULL default '',
  `f_name` varchar(30) NOT NULL default '',
  `l_name` varchar(30) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `mem` int(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=71 ;

--
-- Contenu de la table `users`
--


 

Thanks Again in Advance!!!!

Link to comment
https://forums.phpfreaks.com/topic/169814-solved-phpmysql-input-not-working/
Share on other sites

Ok, I started to email the person I bought the script from. He sent me a new edited version. Now I am not seeing that the form was submitted successful without showing in the database. Now it is giving me an error.

 

Fatal error: Can't use function return value in write context in /hermes/web01/b2498/moo.designspluspro/memorial/add_memorial.php on line 98

 

Any help here would be greatly helpful.

 

Thank you  :D

 

Here is script of the page.

<?php
    include "config/db.php";
    $connection = 
    

$insert = true;
$cnt = 0;
    
$q1 = "select * from settings";
$r1 = mysql_query($q1);
while ($a1 = mysql_fetch_row($r1))
{
	$swidth = $a1[8];
	$sheight = $a1[9];
	$sdwidth = $a1[10];
	$sdheight = $a1[11];
	$spcnt = $a1[12];
}

$t = time();

include ("image.class.php");

if (!empty($_FILES['dimage']))
{
	$type = $_FILES[dimage][type];

	$size = filesize($_FILES['dimage']['tmp_name']);
	$size = $size / ( 1024 * 1024);

	if ( $type != "image/pjpeg" && $type != "image/jpeg" && $type != "")
	{
		$insert = false;
	}
	if ($size > 1)
	{
		if ($size > 0)
		{
			$insert = false;
		}
	}

	if ($insert && $type != "")
	{
		$ty = explode(".",$_FILES['dimage']['name']);
		$cnt = count($ty);
		$dname = $t."_main.".$ty[$cnt-1];

		$thumb = new Thumbnail( $_FILES[dimage][tmp_name], $sdwidth, $sdheight, "pictures/" .$dname, 100, '');
		$thumb->create();
		unset($thumb);
	} 
}

if (!empty($_FILES['images']))
{
	while(list($key,$value) = each($_FILES[images][name]))
	{
		$type = "";
		$size = "";
		if(!empty($value))
		{
			$type = $_FILES[images][type][$key];

			$size = filesize($_FILES['images']['tmp_name'][$key]);
			$size = $size / ( 1024 * 1024);

			if ( $type != "image/pjpeg" && $type != "image/jpeg" && $type != "")
			{
				$insert = false;
			}
			if ($size > 1)
			{
				if ($size > 0)
				{
					$insert = false;
				}
			}

			if ($insert && $type != "")
			{
				$pex = explode(".",$value);
				$pcnt = count($pex);
				$pname = $key ."_sub.". $pex[$pcnt-1];
				$filename = $t."_".$pname;

				$myimages[] = $filename;
				$inkey[] = $key;

				$thumb = new Thumbnail( $_FILES[images][tmp_name][$key], $swidth, $sheight, "pictures/" .$filename, 100, '');
				$thumb->create();
				unset($thumb);
			} 
		}
	}
}

if (!empty(escape($_POST['title'])))
{
	while(list($key,$value) = each(escape($_POST['title'])))
	{
			$mytitle[] = $value;
	}
}

if(!empty($myimages) && $insert)
{
	$inimage = implode("|", $myimages);

	$cnt = count($inkey);

	for ($i = 0; $i < $cnt; $i++)
	{
		$j = $inkey[$i];
		$nmytitle[$i] = $mytitle[$j];
	}

	$intitle = implode("|",$nmytitle);
}

if ($insert)
{
	if (!isset($filename_picture))
	{	
		$filename_picture = "";
	}
	if (isset($_FILES['dead_person_sound']['tmp_name']))
	{
		if (is_uploaded_file($_FILES['dead_person_sound']['tmp_name']))
		{
			$sty = explode(".",$_FILES['dead_person_sound']['name']);
			$scnt = count($sty);
			$sname = $t ."_sound.".$sty[$scnt-1];
			$filename = rand(1,100000).$sname;
			if (file_exists('sounds/'.$filename))
			{
				$filename = rand(1,100000).$sname;
			}
			if (move_uploaded_file($_FILES['dead_person_sound']['tmp_name'],'sounds/'.$filename))
			{
				$filename_sound = $filename;
			}
		}
	}
	if (!isset($filename_sound))
	{
		$filename_sound = "";
	}   
	$today = getdate();
	$mon = $today['mon'];

	if ($mon == 1)
	{
		$mon = "Jan";
	}
	else if ($mon == 2)
	{
		$mon = "Feb";
	}
	else if ($mon == 3)
	{
		$mon = "Mar";
	}
	else if ($mon == 4)
	{
		$mon = "Apr";
	}
	else if ($mon == 5)
	{
		$mon = "May";
	}
	else if ($mon == 6)
	{
		$mon = "Juin";
	}
	else if ($mon == 7)
	{
		$mon = "July";
	}
	else if ($mon == 
	{
		$mon = "Aug";
	}
	else if ($mon == 9)
	{
		$mon = "Sept";
	}
	else if ($mon == 10)
	{
		$mon = "Oct";
	}
	else if ($mon == 11)
	{
		$mon = "Nov";
	}
	else
	{
		$mon = "Dec";
	}

	$date = $mon ." ". $today['mday'] .", ". $today['year'];
	$query = "insert into memorials (dead_person_f_name,dead_person_m_name,dead_person_l_name,dead_person_location,dead_person_picture,dead_person_sound,dead_person_birth,dead_person_death,memorial,memorializer_name,memorial_date,image_title,image) values('".escape($_POST["dead_person_f_name"])."','".escape($_POST["dead_person_m_name"])."','".escape($_POST["dead_person_l_name"])."','".escape($_POST["dead_person_location"])."','".escape($inimage)."','".escape($filename_sound)."','".escape($_POST["b_year"])."',' ".escape($_POST["d_year"])."','".escape($_POST["memorial"])."','".$_COOKIE["username"]."',now(), '".escape($intitle)."', '".escape($dname)."')";
	mysql_query($query) or die("ERROR:".mysql_error());

	$query = "update users set mem='1' where username='".$_COOKIE["username"]."'";
	mysql_query($query);
	//mysql_close();
	header("Location: place_memorial.php?action=ok");
} 
else
{
	header("Location: place_memorial.php?action=nok");
}
?>

That change stopped the error from happening. However, the information is still not going into the database. The only info that gets to the database is the user that put it in and the timestamp.

 

None of the rest of the form gets there. On the page that shows the results, I get:

 

Memorial created : august 13 /  2009

() added by dkdie dkdie

 

Inside the () is supposed to be the person's name that has past away. Example:

 

Memorial created : august 13 /  2009

(First M Last) added by dkdie dkdie

 

However, without the info going to the database, that is why i get that. When I go to the database and manually enter that info, it does show up.

 

:wtf: I am so lost here...

The results page is fine. Like I said earlier, if I input the information directly to the database, it shows up fine. I am trying to set this up for everyone to use free of charge; therefore, I can not be entering everything in the database manually.

 

The results are fine, but I can not get the script above to upload to the database itself. Not really 100% on what you are asking about where the function is defined, sorry for that.

 

Thanks again!!!

 

The code on that page (after the correction you pointed out) is:

<?php
    include "config/db.php";
    $connection = 
    

$insert = true;
$cnt = 0;
    
$q1 = "select * from settings";
$r1 = mysql_query($q1);
while ($a1 = mysql_fetch_row($r1))
{
	$swidth = $a1[8];
	$sheight = $a1[9];
	$sdwidth = $a1[10];
	$sdheight = $a1[11];
	$spcnt = $a1[12];
}

$t = time();

include ("image.class.php");

if (!empty($_FILES['dimage']))
{
	$type = $_FILES[dimage][type];

	$size = filesize($_FILES['dimage']['tmp_name']);
	$size = $size / ( 1024 * 1024);

	if ( $type != "image/pjpeg" && $type != "image/jpeg" && $type != "")
	{
		$insert = false;
	}
	if ($size > 1)
	{
		if ($size > 0)
		{
			$insert = false;
		}
	}

	if ($insert && $type != "")
	{
		$ty = explode(".",$_FILES['dimage']['name']);
		$cnt = count($ty);
		$dname = $t."_main.".$ty[$cnt-1];

		$thumb = new Thumbnail( $_FILES[dimage][tmp_name], $sdwidth, $sdheight, "pictures/" .$dname, 100, '');
		$thumb->create();
		unset($thumb);
	} 
}

if (!empty($_FILES['images']))
{
	while(list($key,$value) = each($_FILES[images][name]))
	{
		$type = "";
		$size = "";
		if(!empty($value))
		{
			$type = $_FILES[images][type][$key];

			$size = filesize($_FILES['images']['tmp_name'][$key]);
			$size = $size / ( 1024 * 1024);

			if ( $type != "image/pjpeg" && $type != "image/jpeg" && $type != "")
			{
				$insert = false;
			}
			if ($size > 1)
			{
				if ($size > 0)
				{
					$insert = false;
				}
			}

			if ($insert && $type != "")
			{
				$pex = explode(".",$value);
				$pcnt = count($pex);
				$pname = $key ."_sub.". $pex[$pcnt-1];
				$filename = $t."_".$pname;

				$myimages[] = $filename;
				$inkey[] = $key;

				$thumb = new Thumbnail( $_FILES[images][tmp_name][$key], $swidth, $sheight, "pictures/" .$filename, 100, '');
				$thumb->create();
				unset($thumb);
			} 
		}
	}
}

if (!empty($_POST['title']))
{
	while(list($key,$value) = each(escape($_POST['title'])))
	{
			$mytitle[] = $value;
	}
}

if(!empty($myimages) && $insert)
{
	$inimage = implode("|", $myimages);

	$cnt = count($inkey);

	for ($i = 0; $i < $cnt; $i++)
	{
		$j = $inkey[$i];
		$nmytitle[$i] = $mytitle[$j];
	}

	$intitle = implode("|",$nmytitle);
}

if ($insert)
{
	if (!isset($filename_picture))
	{	
		$filename_picture = "";
	}
	if (isset($_FILES['dead_person_sound']['tmp_name']))
	{
		if (is_uploaded_file($_FILES['dead_person_sound']['tmp_name']))
		{
			$sty = explode(".",$_FILES['dead_person_sound']['name']);
			$scnt = count($sty);
			$sname = $t ."_sound.".$sty[$scnt-1];
			$filename = rand(1,100000).$sname;
			if (file_exists('sounds/'.$filename))
			{
				$filename = rand(1,100000).$sname;
			}
			if (move_uploaded_file($_FILES['dead_person_sound']['tmp_name'],'sounds/'.$filename))
			{
				$filename_sound = $filename;
			}
		}
	}
	if (!isset($filename_sound))
	{
		$filename_sound = "";
	}   
	$today = getdate();
	$mon = $today['mon'];

	if ($mon == 1)
	{
		$mon = "Jan";
	}
	else if ($mon == 2)
	{
		$mon = "Feb";
	}
	else if ($mon == 3)
	{
		$mon = "Mar";
	}
	else if ($mon == 4)
	{
		$mon = "Apr";
	}
	else if ($mon == 5)
	{
		$mon = "May";
	}
	else if ($mon == 6)
	{
		$mon = "Juin";
	}
	else if ($mon == 7)
	{
		$mon = "July";
	}
	else if ($mon == 
	{
		$mon = "Aug";
	}
	else if ($mon == 9)
	{
		$mon = "Sept";
	}
	else if ($mon == 10)
	{
		$mon = "Oct";
	}
	else if ($mon == 11)
	{
		$mon = "Nov";
	}
	else
	{
		$mon = "Dec";
	}

	$date = $mon ." ". $today['mday'] .", ". $today['year'];
	$query = "insert into memorials (dead_person_f_name,dead_person_m_name,dead_person_l_name,dead_person_location,dead_person_picture,dead_person_sound,dead_person_birth,dead_person_death,memorial,memorializer_name,memorial_date,image_title,image) values('".escape($_POST["dead_person_f_name"])."','".escape($_POST["dead_person_m_name"])."','".escape($_POST["dead_person_l_name"])."','".escape($_POST["dead_person_location"])."','".escape($inimage)."','".escape($filename_sound)."','".escape($_POST["b_year"])."',' ".escape($_POST["d_year"])."','".escape($_POST["memorial"])."','".$_COOKIE["username"]."',now(), '".escape($intitle)."', '".escape($dname)."')";
	mysql_query($query) or die("ERROR:".mysql_error());

	$query = "update users set mem='1' where username='".$_COOKIE["username"]."'";
	mysql_query($query);
	//mysql_close();
	header("Location: place_memorial.php?action=ok");
} 
else
{
	header("Location: place_memorial.php?action=nok");
}
?>

Done for the night. Any ideas would be helpful. I know I am just overlooking something, because I have looked about 50 times. Everything is becoming a blur now.  :facewall:

 

Thanks wildteen88 for the help so far. Still can not get the script to upload to the server. The only information that appears in the database is the user that submitted the memorial and the timestamp.

 

Any help posted will greatly help come first thing tomorrow morning when I log back in.  ;)

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.