hi and help with script layout an isset()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

hi and help with script layout an isset()

Post by dflow »

how should i arrange the layout of this script

i want to update 2 tables, the POST works fine as well as the the query
the problem is that:
1. the isset() is not working
2. also when i refresh the page from the address bar the values are (0 probably related to the isset() )
3. where should i put the header()?(i want it to submit and return to the same page but need to POST the form variables to run the form action.)

Code: Select all

 
<?php require_once('../Connections/international.php'); ?>
<head></head>
<body>
<form action="<?php echo $update_tables_action; ?>" method="post" enctype="multipart/form-data" name="form2">
  <label>StatusID
  <input name="StatusID" type="text" id="StatusID" value="">
  </label>
  <?php echo $row_RsProposal['StatusID']; ?>
  <p>
    <label>RequestID
    <input name="RequestID" type="text" id="RequestID" value="">
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="button" value="Submit">
    </label>
  </p>
</form>
 
</body>
<?php
$StatusID = $_POST['StatusID'];
$ProposalID = $_GET['PropID'];
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("international", $con);
$query="UPDATE proposals, contact_form
     SET contact_form.StatusID = '$StatusID', proposals.StatusID= '$StatusID'
        WHERE proposals.RequestID = contact_form.RequestID
        AND proposals.ProposalID = '$ProposalID'";
print($query); 
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);
 
if (isset($_POST['submit'])) {
header("Location update_2tables.php?'.$ProposalID.'"); 
 
}
else {
 
print ("no value entered");
 
};
 
mysql_close($con);
 
?>
 
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: hi and help with script layout an isset()

Post by Robert07 »

Hello,
It appears to me that this section is should be changed from:

Code: Select all

 
if (isset($_POST['submit'])) {
  header("Location update_2tables.php?'.$ProposalID.'");
 
to:

Code: Select all

 
if (isset($_POST['submit'])) {
  header("Location update_2tables.php?PropID='.$ProposalID.'");
 
Also, redirecting using the header function will not preserve the POST array.

To check whether the submit button is causing the $_POST['submit'] to be set, you can add this to the top of your file:
echo "POST: <BR>";
print_r($_POST);

Regards,
Robert
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: hi and help with script layout an isset()

Post by jackpf »

Also, I'm not sure if it makes a difference...but header('Location blah') should be header('Location: blah') (notice the semi-colon).
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

i tried both suggestions didnt solve it
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

dflow wrote:i tried both suggestions didnt solve it
anyone have a solution?
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: hi and help with script layout an isset()

Post by Robert07 »

If you would explain what happens when you tried the suggestions above, that would help others to help you.
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

Robert07 wrote:If you would explain what happens when you tried the suggestions above, that would help others to help you.
this is the response i get
UPDATE proposals, contact_form SET contact_form.StatusID = '0097097', proposals.StatusID= '0097097' WHERE proposals.RequestID = contact_form.RequestID AND proposals.ProposalID = '3'
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\lanirltdcom\backoffice\update_2tables.php:4) in C:\wamp\www\com\backoffice\update_2tables.php on line 40
POST:
Array ( [StatusID] => 0097097 [RequestID] => [submit] => Submit )
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: hi and help with script layout an isset()

Post by jackpf »

You have to send headers before output.
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

jackpf wrote:You have to send headers before output.
so what should be the correct layout?
i where should i put the header?

if iyt is before the form then the POST will be with empty values
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: hi and help with script layout an isset()

Post by jackpf »

I don't know, you haven't posted your whole script.

But you need to put the header() function before anything is output.
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

jackpf wrote:I don't know, you haven't posted your whole script.

But you need to put the header() function before anything is output.
i did at the first post

Code: Select all

 
<?php require_once('../Connections/international.php'); ?>
<head></head>
<body>
<form action="<?php echo $update_tables_action; ?>" method="post" enctype="multipart/form-data" name="form2">
  <label>StatusID
  <input name="StatusID" type="text" id="StatusID" value="">
  </label>
  <?php echo $row_RsProposal['StatusID']; ?>
  <p>
    <label>RequestID
    <input name="RequestID" type="text" id="RequestID" value="">
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="button" value="Submit">
    </label>
  </p>
</form>
 
</body>
<?php
$StatusID = $_POST['StatusID'];
$ProposalID = $_GET['PropID'];
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("international", $con);
$query="UPDATE proposals, contact_form
     SET contact_form.StatusID = '$StatusID', proposals.StatusID= '$StatusID'
        WHERE proposals.RequestID = contact_form.RequestID
        AND proposals.ProposalID = '$ProposalID'";
print($query);
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);
 
if (isset($_POST['submit'])) {
header("Location update_2tables.php?'.$ProposalID.'");
 
}
else {
 
print ("no value entered");
 
};
 
mysql_close($con);
 
?>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: hi and help with script layout an isset()

Post by jackpf »

Oh, so you did. My bad. I was looking at your second post.

But yeah, look at your own script...you've got all that HTML before the header() function. Put the whole thing in an if() condition checking to see if the form has been submitted....either by checking to see if one of your form elements exists in the post array, or sizeof($_POST), or $_SERVER['REQUEST_METHOD'] == 'POST'...

Or you could just use output buffering.
dflow
Forum Newbie
Posts: 8
Joined: Sun Sep 06, 2009 6:53 am

Re: hi and help with script layout an isset()

Post by dflow »

jackpf wrote:Oh, so you did. My bad. I was looking at your second post.

But yeah, look at your own script...you've got all that HTML before the header() function. Put the whole thing in an if() condition checking to see if the form has been submitted....either by checking to see if one of your form elements exists in the post array, or sizeof($_POST), or $_SERVER['REQUEST_METHOD'] == 'POST'...

Or you could just use output buffering.

an example could help,
this is exactly the layout problem i have
thanks
Post Reply