timecatcher Posted December 7, 2008 Share Posted December 7, 2008 <? 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. Quote Link to comment https://forums.phpfreaks.com/topic/135972-only-adding-one-entry/ Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/135972-only-adding-one-entry/#findComment-708805 Share on other sites More sharing options...
timecatcher Posted December 7, 2008 Author Share Posted December 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135972-only-adding-one-entry/#findComment-708823 Share on other sites More sharing options...
timecatcher Posted December 8, 2008 Author Share Posted December 8, 2008 BUMP. Sorry anyone know the answer to this as I've check around today and still to no avail . Timecatcher. Quote Link to comment https://forums.phpfreaks.com/topic/135972-only-adding-one-entry/#findComment-709590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.