MDanz Posted August 10, 2009 Share Posted August 10, 2009 it just displays "you have not pressed add yet" .. when i press the add button nothing happens. Its supposed to echo the form. Any idea why? <?php session_start(); $add = $_GET['add']; echo "<p align='right'><input type='submit' name='add' value='add'></p>"; if ($_SESSION['username']){ if(isset($add)){ $stacks[0] = " <font color=white>Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a></font> <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'> <p align='center'> <input name='image' value='image' type='text'> <br> <input type='text' name='hyperlink'value='hyperlink'> <br> <input type='text' name='currency' value='currency'> <br> <input type='text' name='name' value='name'> <br> <input type='text' name='info' value='info'> <br> <input type='text' name='keywords' value='keywords'> <br> <input type='text' name='type' value='type'> <br> <input type='submit' value='Submit'><br></p>"; } else { $stacks[0] = "you have not pressed add yet."; } } else { $stacks[0] = "You must be logged in!"; } echo $stacks[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/ Share on other sites More sharing options...
Fadion Posted August 10, 2009 Share Posted August 10, 2009 What does the "Add" submit button do? I don't see any form tags around it. Are you trying to pass a GET variable with it? Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894434 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 the add button should echo $stacks[0].. what type of form should it be in? Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894439 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 What does the "Add" submit button do? I don't see any form tags around it. Are you trying to pass a GET variable with it? Mate, where the $_SESSION['username'] coming from? have you passed it from some other pages? See if this help you <?php session_start(); $add = $_POST['add']; if ($_POST['username'] != '' && $_POST['password'] != '') { foreach ($_POST as $key => $val){ $_SESSION[$key] = $val; } } ?> <p align='right'> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Username<input type="text" name="username" value="<?php echo $_SESSION['username']; ?>" > Password<input type="password" name="password" value="" > <input type="hidden" name="add" value="add" > <input type='submit' value='GO'> </form> </p> <?php if ($_SESSION['username']){ if(isset($add)){ $stacks[0] = " <font color=white>Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a></font> <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'> <p align='center'> <input name='image' value='image' type='text'> <br> <input type='text' name='hyperlink'value='hyperlink'> <br> <input type='text' name='currency' value='currency'> <br> <input type='text' name='name' value='name'> <br> <input type='text' name='info' value='info'> <br> <input type='text' name='keywords' value='keywords'> <br> <input type='text' name='type' value='type'> <br> <input type='submit' value='Submit'><br></p>"; } else { $stacks[0] = "you have not pressed add yet."; } } else { $stacks[0] = "You must be logged in!"; } echo $stacks[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894449 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 thx for reply, not exactly what i'm looking for. I want to be able to add multiple stack of input fields on the press of an add button. Your code put a login form at the top and then when pressing the button GO. The input fields appeared. So i need to put the button Add in a form. Its on the same page so shall the method be 'post'? i'm a noob... Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894461 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 How about this? <?php session_start(); $add = $_GET['add']; if (isset($add)) { if (empty($_SESSION['username'])) { $_SESSION['username'] = ""; } } ?> <p align='right'><input type='button' name='add' value='add' onClick="parent.location=('<?php $_SERVER['PHP_SELF']; ?>?add=add')"></p> <?php if ($_SESSION['username']){ if(isset($add)){ $stacks[0] = " <font color=white>Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a></font> <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'> <p align='center'> <input name='image' value='image' type='text'> <br> <input type='text' name='hyperlink'value='hyperlink'> <br> <input type='text' name='currency' value='currency'> <br> <input type='text' name='name' value='name'> <br> <input type='text' name='info' value='info'> <br> <input type='text' name='keywords' value='keywords'> <br> <input type='text' name='type' value='type'> <br> <input type='submit' value='Submit'><br></p>"; } else { $stacks[0] = "you have not pressed add yet."; } } else { $stacks[0] = "You must be logged in!"; } echo $stacks[0]; ?> I would use javascript to add multiple fields (Use jQuery or Mootools) it is quicker and your page doesnt need to be refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894469 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 I tried that and same, the add button doesn't work. look here.. if you willing to register to my site... http://www.u-stack.com/Index.php when you get to the admin page.. you press the add button and nothing happens i don't know anything about javascript, so i'm not looking for that option.. i already have trouble on php Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894473 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 I have made an account my username is test but it wont let me in, it says the user dosent exist!! Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894476 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 it says your username is toddy? is that you? i've tested registration everything works fine.. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894478 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 it says your username is toddy? is that you? i've tested registration everything works fine.. No mate my fullname is houman How about you make a demo user with the demo password so I can get in. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894481 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 Username:testing Password:testing Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894484 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 mate this is the worst way of coding but I think I have got the answer test this: <?php session_start(); $add = $_GET['add']; if (isset($add)) { if (empty($_SESSION['username'])) { $_SESSION['username'] = ""; } } ?> <p align='right'><input type='button' name='add' value='add' onClick="parent.location=('<?php $_SERVER['PHP_SELF']; ?>?add=add')"></p> <?php if (isset($_SESSION['username'])){ if (empty($_SESSION['stack'])) { $_SESSION['stack'] = ""; } $i = 0; if(isset($add)){ $i = $_SESSION['i']; $_SESSION['stack'][$i] = " <font color=white>Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a></font> <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'> <p align='center'> <input name='image' value='image' type='text'> <br> <input type='text' name='hyperlink'value='hyperlink'> <br> <input type='text' name='currency' value='currency'> <br> <input type='text' name='name' value='name'> <br> <input type='text' name='info' value='info'> <br> <input type='text' name='keywords' value='keywords'> <br> <input type='text' name='type' value='type'> <br> <input type='submit' value='Submit'><br></p>"; $_SESSION['i'] += 1; } else { $_SESSION['stack'][$i] = "you have not pressed add yet."; } } else { $_SESSION['stack'][$i] = "You must be logged in!"; } foreach ($_SESSION['stack'] as $key => $val){ echo $_SESSION['stack'][$key]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894495 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 thx so much it works.. now i'll just figure out how to submit them individually... thx again Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894497 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 thanks so much it works.. now i'll just figure out how to submit them individually... thanks again No worries mate, If you stuck just post your problem I will try to figure it out for your problem Good luck Cheers Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894501 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 hello again.. I've adjusted it you can see here if your logged in username:testing password:testing. www.u-stack.com/Admin.php But submit only submits one input stack of fields.. I'm guessing its hard for submit button to do multiple entry into the database... Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894542 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 Ofcourse because they all have same name at the end of the each field add [] like <input type="text" name ="fieldName[]" value="" > then you will get the array of the values inside the [] you can put the $i so you know the reference. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894545 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 I did this... <p align='center'> <input name='image' value='image[$i]' type='text'> <br> <input type='text' name='hyperlink[$i]'value='hyperlink'> <br> <input type='text' name='currency[$i]' value='currency'> <br> <input type='text' name='name[$i]' value='name'> <br> <input type='text' name='info[$i]' value='info'> <br> <input type='text' name='keywords[$i]' value='keywords'> <br> <input type='text' name='type[$i]' value='type'> <br> </p>"; in phpmyadmin all the fields say Array?? Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894550 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 I have replied to this, have no idea what happend to it, I ll do it again you need to rationalise your code first, you need to have one submit button for all the stacks. anyhow check the below code <?php session_start(); ?> <pre> <?php print_r($_POST); ?> </pre> <?php $add = $_GET['add']; if (isset($add)) { if (empty($_SESSION['username'])) { $_SESSION['username'] = ""; } } ?> <p align='right'><input type='button' name='add' value='add' onClick="parent.location=('<?php $_SERVER['PHP_SELF']; ?>?add=add')"></p> <?php if (isset($_SESSION['username'])){ if (empty($_SESSION['stack'])) { $_SESSION['stack'] = ""; } $i = 0; if(isset($add)){ $i = $_SESSION['i']; $_SESSION['stack'][$i] = " <font color=white>Welcome, ".$_SESSION['username']."!<br><a href='Logout.php'>Log Out</a></font> <form enctype='multipart/form-data' action='index.php' method='post' name='changer'> <p align='center'> <input name='image[$i]' value='image' type='text'> <br> <input type='text' name='hyperlink[$i]'value='hyperlink'> <br> <input type='text' name='currency[$i]' value='currency'> <br> <input type='text' name='name[$i]' value='name'> <br> <input type='text' name='info[$i]' value='info'> <br> <input type='text' name='keywords[$i]' value='keywords'> <br> <input type='text' name='type[$i]' value='type'> <br> <input type='submit' value='Submit'><br></p>"; $_SESSION['i'] += 1; } else { $_SESSION['stack'][$i] = "you have not pressed add yet."; } } else { $_SESSION['stack'][$i] = "You must be logged in!"; } foreach ($_SESSION['stack'] as $key => $val){ echo $_SESSION['stack'][$key]; } ?> run this and you will get the array on top, you need to write a loop (foreach or while) array to extract the data the dump result is something like this Array ( [image] => Array ( [0] => image [1] => image ) [hyperlink] => Array ( [0] => hyperlink [1] => hyperlink ) [currency] => Array ( [0] => currency [1] => currency ) [name] => Array ( [0] => name [1] => name ) [info] => Array ( [0] => info [1] => info ) [keywords] => Array ( [0] => keywords [1] => keywords ) [type] => Array ( [0] => type [1] => type ) ) Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894557 Share on other sites More sharing options...
MDanz Posted August 10, 2009 Author Share Posted August 10, 2009 Can i have an example please? you need to write a loop (foreach or while) array to extract the data Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-894730 Share on other sites More sharing options...
halfman Posted August 11, 2009 Share Posted August 11, 2009 Can i have an example please? you need to write a loop (foreach or while) array to extract the data Mate there are different major problems in here not only with the codes but also with the logics. Can you first let me know what exactly you want to do in that page, maybe your approach is wrong, we can work on your approach, then we can fix the logics and make a cleaner code with less bugs. Writing code is the easiest bit if you get the structue right. I would suggest write down all the steps that you want your user to follow, post them though then we can find the best solution. (Basic Flowchart is very handy!!) How is it sound? If you need just to know about the loop, go to php.net and look for "foeach, for, while" they are all loops and relatively easy to use. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895213 Share on other sites More sharing options...
MDanz Posted August 11, 2009 Author Share Posted August 11, 2009 thanks i really appreciate the help. I now have Everything working on the page but in phpadmin when i check the records it says Array for each field. Its not displaying what i typed in the fields. I added $i to reference each and that works but still displays Array. Just need an understanding of this. <?php session_start(); echo "<font color=white>Welcome, " . $_SESSION['username'] . "!<br><a href='Logout.php'>Log Out</a></font>"; $add = $_GET['add']; if (isset($add)) { if (empty($_SESSION['username'])) { $_SESSION['username'] = ""; } } ?> <p align='right'><input type='button' name='add' value='add' onClick="parent.location=('<?php $_SERVER['PHP_SELF']; ?>?add=add')"></p> <?php if (isset($_SESSION['username'])) { if (empty($_SESSION['stack'])) { $_SESSION['stack'] = ""; } $i = 0; if (isset($add)) { $i = $_SESSION['i']; $_SESSION['stack'][$i] = " <form enctype='multipart/form-data' action='insert.php' method='post' name='changer'> <p align='center'> <input name='image[$i]' value='image' type='text'> <br> <input type='text' name='hyperlink[$i]'value='hyperlink'> <br> <input type='text' name='currency[$i]' value='currency'> <br> <input type='text' name='name[$i]' value='name'> <br> <input type='text' name='info[$i]' value='info'> <br> <input type='text' name='keywords[$i]' value='keywords'> <br> <input type='text' name='type[$i]' value='type'> <br> </p>"; $_SESSION['i']+= 1; } } else { $_SESSION['stack'][$i] = "You must be logged in!"; } foreach($_SESSION['stack'] as $key => $val) { echo $_SESSION['stack'][$key]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895235 Share on other sites More sharing options...
halfman Posted August 11, 2009 Share Posted August 11, 2009 There you go, but I have no idea how you are going to continue. Anyhow this your answer mate: <?php // I HAVE CHANGED THE INSERT.PHP TO INDEX.PHP COPY THE HEADER INTO INSERT.PHP session_start(); echo "<font color=white>Welcome, " . $_SESSION['username'] . "!<br><a href='Logout.php'>Log Out</a></font>"; // HOW TO EXTRACT THE VALUE -- PUT THIS BLOCK IN INSERT.PHP foreach ($_POST as $key => $val) { foreach ($val as $k => $v) { echo $v; // PUT THE SQL CODE IN HERE // UPDATE tableName SET 'filedName' = '".$v."' WHERE If you stock here and dont knwo what to put here then use insert then use mysql_insert_id() to update the last insert } } // IT IS BETTER TO MAKE ALL THE ACTION IN ONE PAGE THEN REDIRECT THE HEADER TO ANOTHER PAGE FOR THE RESULT. ?> <pre> <?php print_r($_POST); ?> </pre> <?php $add = $_GET['add']; if (isset($add)) { if (empty($_SESSION['username'])) { $_SESSION['username'] = ""; } } ?> <p align='right'><input type='button' name='add' value='add' onClick="parent.location=('<?php $_SERVER['PHP_SELF']; ?>?add=add')"></p> <?php if (isset($_SESSION['username'])) { if (empty($_SESSION['stack'])) { $_SESSION['stack'] = ""; } $i = 0; if (isset($add)) { $i = $_SESSION['i']; $_SESSION['stack'][$i] = " <form enctype='multipart/form-data' action='index.php' method='post' name='changer'> <p align='center'> <input name='image[$i]' value='image' type='text'> <br> <input type='text' name='hyperlink[$i]'value='hyperlink'> <br> <input type='text' name='currency[$i]' value='currency'> <br> <input type='text' name='name[$i]' value='name'> <br> <input type='text' name='info[$i]' value='info'> <br> <input type='text' name='keywords[$i]' value='keywords'> <br> <input type='text' name='type[$i]' value='type'> <br> </p>"; $_SESSION['i']+= 1; } } else { $_SESSION['stack'][$i] = "You must be logged in!"; } foreach($_SESSION['stack'] as $key => $val) { echo $_SESSION['stack'][$key]; } ?> <input type="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895264 Share on other sites More sharing options...
MDanz Posted August 11, 2009 Author Share Posted August 11, 2009 thx for the help one again foreach ($_POST as $key => $val) { foreach ($val as $k => $v) { $query = " UPDATE Upload SET (`image`, `hyperlink`,`currency`,`name`,`info`,`keywords`,`type`) = '$v' INSERT mysql_insert_id() "; } } $query = "INSERT INTO Upload"; $query = "(`image`, `hyperlink`,`currency`,`name`,`info`,`keywords`,`type`) VALUES ('$image','$hyperlink','$currency','$name','$info','$keywords','$type')"; $results = mysql_query($query, $link); is the bolded correct? Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895283 Share on other sites More sharing options...
halfman Posted August 11, 2009 Share Posted August 11, 2009 No mate: To use the mysql_insert_id(); your primary key in mysql needs to be auto_increamented field. Then write the insert sql and use the $id = mysql_insert_id(); so you can get the last insert id then use it for the update. Also I would suggest reading some documents about UPDATE and INSERT, it will help to to finish this task. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895288 Share on other sites More sharing options...
MDanz Posted August 11, 2009 Author Share Posted August 11, 2009 There you go, but I have no idea how you are going to continue. Not anything to do after this on this page. the upload page will be done. I just want it simple as possible. thx for help. I'm more innovative when it comes to design and ideas but implementing them is where i have trouble. Quote Link to comment https://forums.phpfreaks.com/topic/169522-button-not-working/#findComment-895296 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.