Page 1 of 1
hi and help with script layout an isset()
Posted: Sun Sep 06, 2009 7:02 am
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);
?>
Re: hi and help with script layout an isset()
Posted: Sun Sep 06, 2009 12:18 pm
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
Re: hi and help with script layout an isset()
Posted: Sun Sep 06, 2009 12:54 pm
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).
Re: hi and help with script layout an isset()
Posted: Sun Sep 06, 2009 5:51 pm
by dflow
i tried both suggestions didnt solve it
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 7:41 am
by dflow
dflow wrote:i tried both suggestions didnt solve it
anyone have a solution?
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 8:51 am
by Robert07
If you would explain what happens when you tried the suggestions above, that would help others to help you.
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 9:54 am
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 )
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 10:18 am
by jackpf
You have to send headers before output.
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 12:39 pm
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
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 12:46 pm
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.
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 1:06 pm
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);
?>
Re: hi and help with script layout an isset()
Posted: Mon Sep 07, 2009 2:27 pm
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.
Re: hi and help with script layout an isset()
Posted: Tue Sep 08, 2009 8:39 am
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