Jump to content

Recommended Posts

<?
require("includes/connect.inc.php") ;
require("includes/navbar.inc.php") ;

	echo '<link rel=\'stylesheet\' href=\'includes/layoutstylesheet.css\' type=\'text/css\'><div id=\'content\'>' ;
$sql = "SELECT COUNT(*) FROM user WHERE username='".mysql_real_escape_string($_COOKIE['kurukouser'])."'";
$query = mysql_query($sql) or die(mysql_error());
$r = mysql_fetch_row($query);
if($r[0] == 1){

$username = htmlentities($_COOKIE['kurukouser'],ENT_QUOTES,"utf-8");
	echo '<center>' ;
$sql = "SELECT * FROM companion ";
$result = mysql_query($sql) ;
$companion = $_GET['companion'] ;
if(!isset($companion)) {
	echo'Hey '.$username.' welcome to companion rocks, here you can choose what you want you companion to be during your journeys, <br />of course this is optional but the benefits can be great!' ;
while($row=mysql_fetch_array($result)) {
$cname = $row['name'] ;
$cimage = $row['image'] ;
	echo'<br /><br />' ;
	echo'<img src="'.$cimage.'">' ;
	echo'<br />' ;
	echo $cname ;
	echo'<br />' ;
	echo'<a href="http://kurukolands.co.uk/companion.php?companion='.$cname.'">Take</a>' ;

	}
}elseif(isset($companion)) {
$sql = "SELECT * FROM companion" ;
$result = mysql_query($sql) ;
while($row=mysql_fetch_array($result)) {
if($row['name'] == $companion) {
$cimage = $row['image'] ;
$cdescription = $row['description'] ;
	echo $companion ;
	echo'<br /><br /><img src="'.$cimage.'">' ;
	echo'<br /><br />'.$cdescription.'' ;
	echo'<form method="post" action="companion.php?companion='.$companion.'"><br />Name: <input type="text" name="name"><br /><input type="submit" name="submit" value="Submit">' ;
if($_POST['submit'] == 'Submit') {
$name = $_POST['name'] ;
$food = 0 ;
$energy = 0 ;
mysql_query("INSERT INTO usercompanion(username, companion, image, name, food, energy) VALUES ('$username', '$companion', '$cimage', '$name', '$food', '$energy')") ;
	echo'<br />You now have a new companion called, '.$name.'' ;
				}
			}
		}
	}
}else{

	echo'Error: You must be logged in to view this page.' ;

}
	echo'</div></center>' ;
?>

 

Hey everyone, when I submit this form it enters everything fine, however it only allows me to enter the information once and I don't want this to happen, neighter do I know why it is as I haven't made it do that as far as I can see. Help appreciated. Thanks.

 

Oh and if you post about indentation im not entirely sure how so please explain thanks.

 

Timecatcher.

Link to comment
https://forums.phpfreaks.com/topic/135972-only-adding-one-entry/
Share on other sites

<?php
require("includes/connect.inc.php") ;
require("includes/navbar.inc.php") ;

echo '<link rel=\'stylesheet\' href=\'includes/layoutstylesheet.css\' type=\'text/css\'><div id=\'content\'>';
$sql = "SELECT COUNT(*) FROM user WHERE username='".mysql_real_escape_string($_COOKIE['kurukouser'])."'";
$query = mysql_query($sql) or die(mysql_error());
$r = mysql_fetch_row($query);
if($r[0] == 1){
$username = htmlentities($_COOKIE['kurukouser'],ENT_QUOTES,"utf-8");
    echo '<center>';
$sql = "SELECT * FROM companion ";
$result = mysql_query($sql);
$companion = $_GET['companion'];
	if(!isset($companion)) {
		echo'Hey '.$username.' welcome to companion rocks, here you can choose what you want you companion to be during your journeys, <br />of course this is optional but the benefits can be great!' ;
		while($row=mysql_fetch_array($result)) {
			$cname = $row['name'] ;
			$cimage = $row['image'] ;
			echo'<br /><br />' ;
			  echo'<img src="'.$cimage.'">' ;
			  echo'<br />' ;
			  echo $cname ;
			  echo'<br />' ;
			  echo'<a href="http://kurukolands.co.uk/companion.php?companion='.$cname.'">Take</a>' ;
		}
	}elseif(isset($companion)) {
		$sql = "SELECT * FROM companion" ;
		$result = mysql_query($sql) ;
		while($row=mysql_fetch_array($result)) {
			if($row['name'] == $companion) {
				$cimage = $row['image'];	
				$cdescription = $row['description'];
				echo $companion;
				echo'<br /><br /><img src="'.$cimage.'">';
				echo'<br /><br />'.$cdescription.'';
				echo'<form method="post" action="companion.php?companion='.$companion.'"><br />Name: <input type="text" name="name"><br /><input type="submit" name="submit" value="Submit">';

				if($_POST['submit'] == 'Submit') {
					$name = $_POST['name'] ;
					$food = 0 ;
					$energy = 0 ;
					mysql_query("INSERT INTO usercompanion(username, companion, image, name, food, energy) VALUES ('$username', '$companion', '$cimage', '$name', '$food', '$energy')") ;
					echo'<br />You now have a new companion called, '.$name.'';
			   }
			}
		}
	}
}else{
echo 'Error: You must be logged in to view this page.';      
}

echo '</div></center>';
?>

 

There is your code properly indented.

 

As to the problem, I guess I am confused on what you want...do you want to show the form after this is done processing so the person can keep adding records?

Yes im wanting it to contiue displaying the form, however I checked that after the first entry, it doesn't seem to add anymore to the database, untill I physically delete that one, so i can add a new one. So in effect people seem to only be able to use the form once, even though the message is still echoed.

 

Timecatcher.

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.