Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-11-2005, 02:38 AM   #1
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Rep: Reputation: 15
how to pass a row to another PHP script

i have this peice of code. it fetches all the rows from a table and displays it on a web page and also adds a "Add to cart button" at the end of every page.

what i wan is that when i press that "Add to cart button" it should send that particular row of the table to the script cart.php and then display it in the cart.
what do i do in this script to acheive this?

		//fetch each record in result set		
		for ( $counter = 0;$row = mysql_fetch_row( $result ); $counter++)   
			{ //build the table to display the items			 	 
			print( "<tr>" );     
print( "<form method=\"post\" name=\"item\" action=\"cart.php\" target=\"lowerframe\">");   
				foreach ( $row as $key => $value )
				   print( "<td>$value</td>" );
print("<td><input type=\"Submit\" value=\"Add to Cart\" name=\"btnSubmit\"/></td>"); 
			print( "</tr>" );				
			mysql_close( $link );	
Old 04-13-2005, 02:02 AM   #2
Registered: Jan 2004
Location: new zealand
Distribution: Mandrake,Slackware
Posts: 165

Rep: Reputation: 30
you can pass the varible $row to the page cart.php
print("<form method='post' name='item' action='cart.php?row=".$row."' target='lowerframe'>");
on the cart.php page you will need to get the value of row. how you do that depends on weather your php install is setup with global varibles turned on/off.
if its on you should be able to just add the $row varible to the database without having to get it first.

is that what you are asking?

Old 04-13-2005, 02:14 AM   #3
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Original Poster
Rep: Reputation: 15
yes exactly thats what i am asking.

how to get a desired row from a result to be sent to another script and printed on the page.

i think one way of doing it would be to use sessions which will make the row a global variable incase i cant access it through just calling it.

i ll post any problems encountered if i cant solve it.
Old 12-21-2011, 12:21 AM   #4
LQ Newbie
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
how to post the table row to another php file.

<td> <a href="Update.php?row= $Row"> <?php echo $update ?></a></td>
how can i post the current row to Update.php and how can i retrive and use it in the Update.php.
Please let me know.

Old 12-22-2011, 06:02 AM   #5
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,984

Rep: Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444
Within any PHP (or other web...) script, there exists a pool of so-called "session variables" (by any other name) which can be stored by PHP on the server. The session-cookie handling logic enables PHP to locate that pool of variables for you. Each variable is, in fact, an arbitrary data-structure ... lists, arrays, structs, what have you ... and it is stored in the pool under some name (known to you).

So... when you need to "pass" information from one area of the program to another, do so by passing a meaningless, randomly-generated short string ... which is a key into some session-variable (which is an "array[string] of some structure"). (Yes, I am speaking in non-PHP-specific terms here; catch the idea and you can find your way to the PHP implementation.)

This approach is not only much more secure, but it is also much easier. For instance, your generated HTML might include a tag that looks vaguely like this:

<input name="input_xyzzyQz39foobar">Confirm this order</input>

Your code detects this string in the POST data, then looks for:


If that key exists in $$SESSION[]('post_keys'), then there's all the information that you are looking for. If not, the user is feeding you a bogus-or-stale string.

In any case: the user does not have anything on his computer that means anything at all to him. He can't forge a new one. He can't change any information that you have associated with the utterly random key that you have provided. And, you don't have to write messy code to store and retrieve whatever information it is. (PHP's implementors have already done that bit for you.) All of the modules in the system have access to the session pool.

It is a very good idea to write one class or object which encapsulates all of this logic in convenient terms within your application so that the code only occurs once.

HTH. (Please, don't ask me to write the code.)

Last edited by sundialsvcs; 12-22-2011 at 06:04 AM.
Old 12-24-2011, 02:07 AM   #6
Registered: Apr 2011
Posts: 81
Blog Entries: 1

Rep: Reputation: 0
can anyone help me to wtite a php script for creating users in centos 6,

i have created a html file:

<form action="create_user.php" method="POST">
Username: <input type="text" name="username" /><br />
Password: <input type="text" name="password" />
<input type="submit" />

and create_user.php:

echo $_POST[username];
$user = $_POST[username];
$password = $_POST[password];
exec ("sudo /sbin/useradd $user -p $password" );



i have made apache server with a user shank , but this script dosent able to create any users



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: changing row color showing mysql results emilioestevezz Programming 15 09-13-2004 07:27 PM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 06:30 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 07:16 AM
How to pass arguments from $prompt for php script ukjairaj Linux - Software 4 06-25-2004 12:14 PM
PHP Pass Parameter Gerardoj Programming 2 05-25-2004 09:12 AM

All times are GMT -5. The time now is 07:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration