Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. send data

send data

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
question
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Elham M

    How can I send variable to another form without include:confused:?

    C Offline
    C Offline
    cjoki
    wrote on last edited by
    #2

    Depends...is this second form on the same page or a different page?

    Chris J www.redash.org

    E 1 Reply Last reply
    0
    • C cjoki

      Depends...is this second form on the same page or a different page?

      Chris J www.redash.org

      E Offline
      E Offline
      Elham M
      wrote on last edited by
      #3

      Different page

      C 1 Reply Last reply
      0
      • E Elham M

        Different page

        C Offline
        C Offline
        cjoki
        wrote on last edited by
        #4

        This is done with either a $_POST or a $_GET variable. Your can read more info and see some code sample here http://php.net/manual/en/language.variables.external.php[^]

        Chris J www.redash.org

        E 1 Reply Last reply
        0
        • C cjoki

          This is done with either a $_POST or a $_GET variable. Your can read more info and see some code sample here http://php.net/manual/en/language.variables.external.php[^]

          Chris J www.redash.org

          E Offline
          E Offline
          Elham M
          wrote on last edited by
          #5

          $_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error

          query("INSERT INTO register(`user`, `lsname`, `teachername`, `classday`, `starttime`, `endtime`, `examtime`)VALUES('$_SESSION[user]','$row[lsname]','$row[teachername]','$row[classday]','$row[starttime]','$row[endtime]','$row[examtime]') ");

          echo "one record added";
          }
          echo "";
          echo "";
          $result = mysql_query("SELECT * FROM class");
          while($row = mysql_fetch_assoc($result))
          {
          if($_POST[t]==$row[lsname])
          {
          foreach($row as $key=>$var2)
          {
          echo "";
          }
          echo " ";

          }
          
            echo "";
          }
          

          echo"

          Name

          Professor

          Capacity

          Exam

          classtime

          $var2

          ";

          ?>

          please help me I mystify in my project :(

          E C 2 Replies Last reply
          0
          • E Elham M

            $_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error

            query("INSERT INTO register(`user`, `lsname`, `teachername`, `classday`, `starttime`, `endtime`, `examtime`)VALUES('$_SESSION[user]','$row[lsname]','$row[teachername]','$row[classday]','$row[starttime]','$row[endtime]','$row[examtime]') ");

            echo "one record added";
            }
            echo "";
            echo "";
            $result = mysql_query("SELECT * FROM class");
            while($row = mysql_fetch_assoc($result))
            {
            if($_POST[t]==$row[lsname])
            {
            foreach($row as $key=>$var2)
            {
            echo "";
            }
            echo " ";

            }
            
              echo "";
            }
            

            echo"

            Name

            Professor

            Capacity

            Exam

            classtime

            $var2

            ";

            ?>

            please help me I mystify in my project :(

            E Offline
            E Offline
            effayqueue
            wrote on last edited by
            #6

            if you mean what I think you mean: first page:

            ';

            // end your form here...

            ?>

            second page:

            1 Reply Last reply
            0
            • E Elham M

              $_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error

              query("INSERT INTO register(`user`, `lsname`, `teachername`, `classday`, `starttime`, `endtime`, `examtime`)VALUES('$_SESSION[user]','$row[lsname]','$row[teachername]','$row[classday]','$row[starttime]','$row[endtime]','$row[examtime]') ");

              echo "one record added";
              }
              echo "";
              echo "";
              $result = mysql_query("SELECT * FROM class");
              while($row = mysql_fetch_assoc($result))
              {
              if($_POST[t]==$row[lsname])
              {
              foreach($row as $key=>$var2)
              {
              echo "";
              }
              echo " ";

              }
              
                echo "";
              }
              

              echo"

              Name

              Professor

              Capacity

              Exam

              classtime

              $var2

              ";

              ?>

              please help me I mystify in my project :(

              C Offline
              C Offline
              cjoki
              wrote on last edited by
              #7

              When I must debug post, get or session variables I use this at the top of the target page.

              <?php
              session_start();
              echo "<pre>";
              print_r($_POST);
              print_r($_SESSION);
              echo "</pre>";
              /// rest of page below here
              ?>

              This will allow you to see what is being passed to your target page so you will know if the data is making it or not. I see that you defined your function aa()...but where is it called from?

              Chris J www.redash.org

              E 1 Reply Last reply
              0
              • C cjoki

                When I must debug post, get or session variables I use this at the top of the target page.

                <?php
                session_start();
                echo "<pre>";
                print_r($_POST);
                print_r($_SESSION);
                echo "</pre>";
                /// rest of page below here
                ?>

                This will allow you to see what is being passed to your target page so you will know if the data is making it or not. I see that you defined your function aa()...but where is it called from?

                Chris J www.redash.org

                E Offline
                E Offline
                Elham M
                wrote on last edited by
                #8

                I called it when I define submit button onclick attributes

                echo " ";

                C 1 Reply Last reply
                0
                • E Elham M

                  I called it when I define submit button onclick attributes

                  echo " ";

                  C Offline
                  C Offline
                  cjoki
                  wrote on last edited by
                  #9

                  no you are calling a javascript function called aa() and that I'm guessing does not exist? remeber php is executed on the server. The onclick is a javascript event that is triggered on the users browser. So you are most likely getting a undefined from the browser if the form submits to itself (i.e. - the scripts name is "reqire.php") But the error I think is wiped as the page reloads. The php function aa() is never called. On a side note, its really bad to: 1) have a database connection based on root, to much access for what is needed. 2) display a password in a forum, big security hole.

                  Chris J www.redash.org

                  E 1 Reply Last reply
                  0
                  • C cjoki

                    no you are calling a javascript function called aa() and that I'm guessing does not exist? remeber php is executed on the server. The onclick is a javascript event that is triggered on the users browser. So you are most likely getting a undefined from the browser if the form submits to itself (i.e. - the scripts name is "reqire.php") But the error I think is wiped as the page reloads. The php function aa() is never called. On a side note, its really bad to: 1) have a database connection based on root, to much access for what is needed. 2) display a password in a forum, big security hole.

                    Chris J www.redash.org

                    E Offline
                    E Offline
                    Elham M
                    wrote on last edited by
                    #10

                    The function aa() work but I can't access the variable my big problem is I don't know user click in which button to insert data I agree with you but I can't insert in javascript!I think I should solve this problem in another way what's your suggestion?

                    C 1 Reply Last reply
                    0
                    • E Elham M

                      The function aa() work but I can't access the variable my big problem is I don't know user click in which button to insert data I agree with you but I can't insert in javascript!I think I should solve this problem in another way what's your suggestion?

                      C Offline
                      C Offline
                      cjoki
                      wrote on last edited by
                      #11

                      This is what I have issues with in your code..

                      <?php
                      session_start();
                      echo ($_SESSION[users]);
                      echo "$_POST[t]"; // "$_POST[t]" should be $_POST['t']
                      ?>
                      <html>
                      <form method="post" action="reqire.php">
                      <?php
                      require_once ('db.php');
                      // never ever show log in data in code to others. I will make a
                      // seperate script just for the connection function and include the page and call the function for the page that will run queries
                      $db = new db("root","","regstudent","localhost");

                      	function aa()  // function is defined... but not called, this is useless
                      	{
                      		require\_once ('db.php');
                      		// calling this again when you could just use the one defined outside of the function like this
                      		// global $db;....or you could pass the $db as a parameter of the function like aa($db)
                      		$db = new db("root","","regstudent","localhost");
                      		
                      		$db->query("INSERT INTO register(\`user\`, \`lsname\`, \`teachername\`, \`classday\`, \`starttime\`, \`endtime\`, \`examtime\`)VALUES('$\_SESSION\[user\]','$row\[lsname\]','$row\[teachername\]','$row\[classday\]','$row\[starttime\]','$row\[endtime\]','$row\[examtime\]') ");
                      		
                      		echo "one record added"; 
                      	}
                      	
                      	echo "<table border='4' bordercolor='CC0099' width=100% height=20% >";  
                      	echo "<tr><th>Name</th><th>Professor</th><th>Capacity</th><th>Exam</th><th colspan='3'>classtime</th></tr>";   
                      	
                      	// add a die condition in case of failure. In production code it should write to a log, but is ok to display for development
                      	$result = mysql\_query("SELECT \* FROM class");   
                      	 // btw - the \* will make a additional query on the db to look up the field names, best practice is to include field names yourself.
                      	 
                      	// this is how I would write the die....test it by forcing an error, like an incorrect table name in the query.
                      	$result = mysql\_query("SELECT \* FROM class") or die("<br>...LINE ".\_\_LINE\_\_."<br>...SQL: ".$sql."<br>...ERROR: ".mysql\_error()."<br>");
                      	
                      	while($row = mysql\_fetch\_assoc($result)) 
                      	{    
                      		if($\_POST\[t\]==$row\[lsname\])  // $\_POST\[t\] should be $\_POST\['t'\], but why do you want to show either 1 record or 0 records?
                      		{
                      			foreach($row as $key=>$var2)     
                      			{       
                      				// this is risky, the table will look like hell if the db schema changes with more or less
                      				//	fields than the seven columns expected in the header of this table
                      				echo "<td align='center'>$var2 </td>"; 
                      			}
                      
                      E 1 Reply Last reply
                      0
                      • C cjoki

                        This is what I have issues with in your code..

                        <?php
                        session_start();
                        echo ($_SESSION[users]);
                        echo "$_POST[t]"; // "$_POST[t]" should be $_POST['t']
                        ?>
                        <html>
                        <form method="post" action="reqire.php">
                        <?php
                        require_once ('db.php');
                        // never ever show log in data in code to others. I will make a
                        // seperate script just for the connection function and include the page and call the function for the page that will run queries
                        $db = new db("root","","regstudent","localhost");

                        	function aa()  // function is defined... but not called, this is useless
                        	{
                        		require\_once ('db.php');
                        		// calling this again when you could just use the one defined outside of the function like this
                        		// global $db;....or you could pass the $db as a parameter of the function like aa($db)
                        		$db = new db("root","","regstudent","localhost");
                        		
                        		$db->query("INSERT INTO register(\`user\`, \`lsname\`, \`teachername\`, \`classday\`, \`starttime\`, \`endtime\`, \`examtime\`)VALUES('$\_SESSION\[user\]','$row\[lsname\]','$row\[teachername\]','$row\[classday\]','$row\[starttime\]','$row\[endtime\]','$row\[examtime\]') ");
                        		
                        		echo "one record added"; 
                        	}
                        	
                        	echo "<table border='4' bordercolor='CC0099' width=100% height=20% >";  
                        	echo "<tr><th>Name</th><th>Professor</th><th>Capacity</th><th>Exam</th><th colspan='3'>classtime</th></tr>";   
                        	
                        	// add a die condition in case of failure. In production code it should write to a log, but is ok to display for development
                        	$result = mysql\_query("SELECT \* FROM class");   
                        	 // btw - the \* will make a additional query on the db to look up the field names, best practice is to include field names yourself.
                        	 
                        	// this is how I would write the die....test it by forcing an error, like an incorrect table name in the query.
                        	$result = mysql\_query("SELECT \* FROM class") or die("<br>...LINE ".\_\_LINE\_\_."<br>...SQL: ".$sql."<br>...ERROR: ".mysql\_error()."<br>");
                        	
                        	while($row = mysql\_fetch\_assoc($result)) 
                        	{    
                        		if($\_POST\[t\]==$row\[lsname\])  // $\_POST\[t\] should be $\_POST\['t'\], but why do you want to show either 1 record or 0 records?
                        		{
                        			foreach($row as $key=>$var2)     
                        			{       
                        				// this is risky, the table will look like hell if the db schema changes with more or less
                        				//	fields than the seven columns expected in the header of this table
                        				echo "<td align='center'>$var2 </td>"; 
                        			}
                        
                        E Offline
                        E Offline
                        Elham M
                        wrote on last edited by
                        #12

                        Thanks alot for your help ;)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups