Jump to content

Php Data Base Issue


Recommended Posts

hello, i'm new to php... i like to design a form, which receive feedback.

the proces is like this:

1.i check cookie if exist, i dont ask any more for feedback

2.if not exist, i check for session, cause all action and form are in same page...

if session empty or not exist, i send user to form...

else if is set, i send him for validate data, and if data is valid, for data registeration.

 

the problem i face, is it show me success msg, but there's no record once i check my mySQL tables...

 

table = >

mrl_feedback

Fields =>

id int auto_increment not null

name tinytext

email tinytext

message text

 

[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]

The code is belo this msg:

[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]

 

<?php
define('HOST_NAME', 'localhost');
define('USERNAME', 'deadmann_*******');
define('PASSWORD', '*******************');
define('DATABASE', 'deadmann_**********');

if(isset ($_COOKIE['MRLFeedbackPassed']) )
{
	echo'<html><head></head>'
		.'<body bgcolor="black"><font color="white">'
		.'<H1>Multi-realm Launcher</H1></font></body></html>';
}
else
{
	session_start();
	if(isset ($_SESSION['mrl_feedback']) && ($_SESSION['mrl_feedback']!=''))
	{
		if (isset ($_POST['msg']) && (!empty ($_POST['msg'])) && (strlen($_POST['msg'])>5) )
		{
			if(! mysql_connect(HOST_NAME, USERNAME, PASSWORD))
			{
				die('<html><head></head>'
					.'<body bgcolor="black"><font color="white">Cannot connect to '
					.'server.</font></body></html>');
				exit;
			}
			
			if(! mysql_select_db(DATABASE))
			{
				die('<html><head></head>'
					.'<body bgcolor="black"><font color="white">Cannot connect to '
					.'database.</font></body></html>');
				exit;
			}

			mysql_query("insert into mrl_feedback (name,email,message) "
					."values ({$_POST['name']},{$_POST['email']}"
					.",{$_POST['msg']})");

	mysql_close();
	
			setcookie('MRLFeedbackPassed','is set',time()+60*60*24*365,'/','deadmann.heliohost.org',TRUE);

			echo '<html><head></head>'
					.'<body bgcolor="black"><font color="white">Your feed back '
					.'has been send successfully.</font></body></html>';
		}
		else
		{
			if( (!isset ($_POST['msg'])) || (empty ($_POST['msg'])))
			{
				header("Location: feedback.php?error=1");
				$_SESSION['mrl_feedback']='';
				exit;
			}
			else if(isset ($_POST['msg']) && (strlen($_POST['msg'])<=5))
			{
				header("Location: feedback.php?error=2");
				$_SESSION['mrl_feedback']='';
				exit;
			}
		}
	}
	else
	{
?>
<html>
<head></head>
<body bgcolor="black">
	<form action="<?php echo $GLOBALS['PHP_SELF']?>" method="post">
		<table>
			<tr>
				<td><font color="white">Name:</font></td>
				<td><input type="text" name="name"/></td>
				<td rowspan="2">
		<?php
			if(isset ($_GET['error'])) {
	   				 if($_GET['error']==1){
	   					 echo '<font color="red">*You must fill<br/> message field.</font>';
	   				 }
	   				 else if($_GET['error']==2){
	   					 echo '<font color="red">*Message<br/> length is<br/> too low.</font>';
	   				 }
	   				 else
	   				 {
			   			 echo '<font color="green">Feedback</font>';
			   		 }
   				 }
   				 else
   				 {
	   				 echo '<font color="green">Feedback</font>';
   				 }
  				 ?>
			</td>
			</tr>
			<tr>
				<td><font color="white">Email:</font></td>
				<td><input type="text" name="email"/></td>
				<td></td>
			</tr>
			<tr>
				<td><font color="white">Message:</font></td>
				<td><input type="text" name="msg"/></td>
				<td><input type="submit" value="Send"/></td>
			</tr>
		</table>
	</form>
</body>
</html>
<?php
		$_SESSION['mrl_feedback']='is set';
	}
}
?>

Edited by Tjoene
Added code-tags.
Link to comment
Share on other sites

hi

 

check this code :

<?php
define('HOST_NAME', 'localhost');
define('USERNAME', 'deadmann_*******');
define('PASSWORD', '*******************');
define('DATABASE', 'deadmann_**********');

if(isset ($_COOKIE['MRLFeedbackPassed']) )
{
 echo'<html><head></head>'
  .'<body bgcolor="black"><font color="white">'
  .'<H1>Multi-realm Launcher</H1></font></body></html>';
}
else
{
 session_start();
 if(isset ($_SESSION['mrl_feedback']) && ($_SESSION['mrl_feedback']!=''))
 {
  if (!empty($_POST['msg']) && (strlen($_POST['msg'])>5) )
  {
if(! $link = mysql_connect(HOST_NAME, USERNAME, PASSWORD))
{
 die('<html><head></head>'
  .'<body bgcolor="black"><font color="white">Cannot connect to '
  .'server.</font></body></html>');
 exit;
}
 
if(! mysql_select_db(DATABASE,$link))
{
 die('<html><head></head>'
  .'<body bgcolor="black"><font color="white">Cannot connect to '
  .'database.</font></body></html>');
 exit;
}
mysql_query('insert into `mrl_feedback` (`name`,`email`,`message`) values('
  .'"'.mysql_real_escape_string($_POST['name'],$link).'"'
  .',"'.mysql_real_escape_string($_POST['email'],$link).'"'
  .',"'.mysql_real_escape_string($_POST['msg'],$link).'"'
  , $link);
 mysql_close($link);

setcookie('MRLFeedbackPassed','is set',time()+60*60*24*365,'/','deadmann.heliohost.org',TRUE);
echo '<html><head></head>'
  .'<body bgcolor="black"><font color="white">Your feed back '
  .'has been send successfully.</font></body></html>';
  }
  else
  {
if( (!isset ($_POST['msg'])) || (empty ($_POST['msg'])))
{
 header("Location: feedback.php?error=1");
 $_SESSION['mrl_feedback']='';
 exit;
}
else if(isset ($_POST['msg']) && (strlen($_POST['msg'])<=5))
{
 header("Location: feedback.php?error=2");
 $_SESSION['mrl_feedback']='';
 exit;
}
  }
 }
 else
 {
?>
<html>
<head></head>
<body bgcolor="black">
 <form action="<?php echo $GLOBALS['PHP_SELF']?>" method="post">
  <table>
<tr>
 <td><font color="white">Name:</font></td>
 <td><input type="text" name="name"/></td>
 <td rowspan="2">
  <?php
if(isset ($_GET['error'])) {
	  if($_GET['error']==1){
	   echo '<font color="red">*You must fill<br/> message field.</font>';
	  }
	  else if($_GET['error']==2){
	   echo '<font color="red">*Message<br/> length is<br/> too low.</font>';
	  }
	  else
	  {
	   echo '<font color="green">Feedback</font>';
	  }
	 }
	 else
	 {
	  echo '<font color="green">Feedback</font>';
	 }
	?>
</td>
</tr>
<tr>
 <td><font color="white">Email:</font></td>
 <td><input type="text" name="email"/></td>
 <td></td>
</tr>
<tr>
 <td><font color="white">Message:</font></td>
 <td><input type="text" name="msg"/></td>
 <td><input type="submit" value="Send"/></td>
</tr>
  </table>
 </form>
</body>
</html>
<?php
  $_SESSION['mrl_feedback']='is set';
 }
}
?>

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...