Jump to content

Button not working..


MDanz

Recommended Posts

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];

 

?>

 

 

 

Link to comment
Share on other sites

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];

 

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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];
}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
        )

)

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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];

} ?>

 

 

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.