PHP help please

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi Al

Working on a project for work and am stuck.

I have a page called addorder.php which contains a form. It posts its data to do_addorder.php which inserts it into the DB. Now on this page I need a link or button that opens a popup window and echos the fields, print a copy of the data for the customer to take away. Im guessing the best way would be to use a form with hidden fields which I can do, its the popup part that is going to be the issue, and getting the data into the popup.

What are the best ways of going about this, and could any volunteer some help.

Thanks
Aaron
 
have to admit my php skills are limited to playing around in wordpress but could you pass the info accross on a query string ? or im guessing php has some sort of session object maybe you could use that instead
 
You have to remember that PHP is a server side language, and is parsed on the server, thus you couldn't use PHP to create a popup for example, which would be done using client side code.

You'd use PHP to generate JavaScript, which when the page is loaded, is executed. This can then do your popup, printing etc, all using data PHP has provided.
 
If you know how to POST data to a page and use the variables then you can just use

Code:
echo $foo;
to print out a variable.

So perhaps:

Code:
<?php
$name = $_POST['name'];
echo "Name: $name";
And so on.

Also you want to first of all clean up POST variables with mysql_real_escape_string() before you insert them into the database, and you should also use htmlentities() on any variables you're printing to the screen :)

www.php.net/[function name] is your daddy :cool:
 
use Javascript to create the pop-up.

Code:
<html>
<script language="JavaScript">

function popup (id)
{
    window.open('http://www.yourdomain.com/popup.php?id=' + id, 'popup', 'height=200,width=200,toolbar=no,left=200,top=200');

}

</script>
<body>
<a href="#" onClick="popup(123);">Linky linky</a>
</body>
</html>

as a starting example.. untested.
 
Last edited:
infact I'm bored at work so made a working example:

page.html:
Code:
<html>
<script language="JavaScript">

function popup (id)
{
    if (id == null || id == '') { id = 'default'; }
    window.open('popup.html?id=' + id, 'popup', 'height=200,width=200,toolbar=no,left=200,top=200');        

}

</script>
<body>
<form method="post" onSubmit="popup(document.getElementById('id').value);">
<input type="text" name="id">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

popup.html:
Code:
<html>
<body>
<script language="JavaScript">

var search = window.location.search;
var string = search.substr(search.indexOf('=') + 1);

document.write('Do something on this page with the ID: ' + string);
</script>
</body>
</html>

Now obviously you will want to use PHP on the popup page, so you can use $_GET['id'] for example to use in your MySQL quesry to extract relevant data.

HTH :)
 
Last edited:
Hehe

Thanks guys. Massive help as usual.

Right I need some more help. I have this code

Code:
<form action="do_editmodel.php" method="post">
<input name="model" type="text" value="$model" />
<select name="active" value="$active">
  <option value="Yes">Yes</option>
  <option value="No">No</option>
  </select>
  <input name="sumbit" type="submit" value="Save Changes" /></form>
  <form action="do_deletemodel.php" method="post">
  <input name="id" type="hidden" value="$id" /><input name="delete" type="submit" value="Delete Record"/></form>

I want to use that code and loop it for every record in the DB. I know how to get the data out of the DB but I am not sure how to loop int. And also how that code needs to be formatted for use from within a chunk of php.

Thanks again
Aaron
 
Code:
<?php

$link = mysql_connect('host', 'user', 'pass') or die('Connection error');
mysql_select_db('db', $link) or die('DB selection error');
$result = mysql_query('SELECT * FROM `table`') or die('query error');

while ($row = mysql_fetch_assoc($result)) {
    echo $row['col1'];
}

@mysql_close($link);

?>

as a db iteration example :)
 
if you are doing text boxes per item (row) then the while() loop becomes something like:

Code:
while ($row = mysql_fetch_assoc($result) {
    echo "<input type=\"text\" name=\"text[]\" value=\"{$row['column']}\" /><br />\n";
}

That will output a new textbox for each row that is returned from your query :) Swap 'column' for the name of the field you wish to insert.

e.g.

Code:
<input type="text" name="text[]" value="1" /><br />
<input type="text" name="text[]" value="2" /><br />
<input type="text" name="text[]" value="3" /><br />
<input type="text" name="text[]" value="4" /><br />
<input type="text" name="text[]" value="5" /><br />
<input type="text" name="text[]" value="6" /><br />
<input type="text" name="text[]" value="7" /><br />
<input type="text" name="text[]" value="8" /><br />
<input type="text" name="text[]" value="9" /><br />
<input type="text" name="text[]" value="10" /><br />
 
Back
Top Bottom