Jump to content

How would you process a form that is echo'd using php instead of HTML?????


Modernvox

Recommended Posts

I have this form I am trying to process, but it won't work?

if($count==0){

 

echo "That Bidder Number is NOT logged in, ";
echo "would you like to set this bidder as active?";
echo " Enter 1 for NO or 2 for YES";
echo "<form action= \"process.php\" method= \"POST\">";
echo "<input type =\"text\" name= \"logUser\"/>";
echo "<input type= \"submit\" value = \"Submit\"/>";
$logUser= isset($_POST['logUser']) ? $_POST['logUser'] : '';
header("Location: process.php");
exit();
}

 

All I want to do is process the users input and either input data into the database or simply redirect the user.

Why the hell is this so complicated for??

 

I am processing the form on the same page it is displayed.

 

Here's my procressing

if ($logUser= 1) {
header("Location: inprogress.php");
exit();
}

else if ($logUser= 2){
// Add $biddersId and redirect to anypage
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");



mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) 
VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')")
or die(mysql_error());   
header("Location: inprogress.php");
exit();
   }

Link to comment
Share on other sites

I guess this is advanced programinng?

Not at all.

 

The problem is variables do not get carried over to other php pages. You need to pass $logUser to process.php. Eg

header("Location: process.php?loguser=$logUser");

 

Now in process.php you'd use

$logUser = $_GET['loguser'];

Link to comment
Share on other sites

That first block of code is invalid anyway. You can't use a header function after you have output other content to the browser (e.g. an echo statement). You would get errors if that code was run. I would assume that the condition for that code block is never true.

 

I'm not sure what the intent of that code is. But, it wouldn't make sense to create a form then immediately redirect the user to another page. They would never have an opportunity to enter any data.

 

Can you supply more code from the page in the correctr sequence and/or provide details on the expected flow of the script?

Link to comment
Share on other sites

That first block of code is invalid anyway. You can't use a header function after you have output other content to the browser (e.g. an echo statement). You would get errors if that code was run. I would assume that the condition for that code block is never true.

 

I'm not sure what the intent of that code is. But, it wouldn't make sense to create a form then immediately redirect the user to another page. They would never have an opportunity to enter any data.

 

Can you supply more code from the page in the correctr sequence and/or provide details on the expected flow of the script?

 

 

 

Welp, here is the complete page. I just posted this on vworker for $20. That's how tired I am getting trying to get this working.

 

All I want to do is allow the client to enter the number 1 or 2. (1 = NO and 2 = YES) If they choose 1 then nothing needs to be done, but if they enter 2, I need to add the info to the database tables (bidders and transactions respectively.

 

This is for bidder's Id's that are not pre-logged into the system. Before we can log them we need to make sure the Auctioneer has called out the correct bidder Id that is why we need to issue a warning before ading the data which will allow the secretary to confirm the NON-Logged bidder ID

 

Anyhow here i the complete script

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$host= "";
$db_name= "";
$db_user= "";
$db_password= "";

ob_start();
$logUser = $_GET['loguser'];

if ($logUser= 1) {
header("Location: inprogress.php");
exit();
}

else if ($logUser= 2){
// Add $biddersId and redirect to anypage
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");



mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) 
VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')")
or die(mysql_error());   
header("Location: inprogress.php");
exit();
   }

if(isset($_POST['newBidder'])) {
$newBidder= isset($_POST['newBidder']) ? $_POST['newBidder'] : '';


mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM bidders WHERE biddersId='$newBidder'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==0){

echo "That Bidder Number is NOT logged in, ";
echo "would you like to set this bidder as active?";
echo " Enter 1 for NO or 2 for YES";
echo "<form action= \"process.php\" method= \"POST\">";
echo "<input type =\"text\" name= \"logUser\"/>";
echo "<input type= \"submit\" value = \"Submit\"/>";
$logUser= isset($_POST['logUser']) ? $_POST['logUser'] : '';
header("Location: process.php?loguser=$logUser");
exit();
}
mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");
header("Location: index.php");
exit();
  }


if(isset($_POST['deleteBidder']))
{
$deleteBidder= isset($_POST['deleteBidder']) ? $_POST['deleteBidder'] : '';
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_query("DELETE FROM bidders WHERE biddersId='$deleteBidder'");
header("Location: index.php");
exit();
}

if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty']))
{
$itemDescription= isset($_POST['itemDescription']) ? $_POST['itemDescription'] : '';
$itemPrice= isset($_POST['itemPrice']) ? $_POST['itemPrice'] : '';
$winningBidder= isset($_POST['winningBidder']) ? $_POST['winningBidder'] : '';
$itemQty= isset($_POST['itemQty']) ? $_POST['itemQty'] : '';

mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM transactions WHERE bidderIds='$winningBidder'";  
$result=mysql_query($sql);

$count=mysql_num_rows($result);
// If result matched, table row must be 1 row



}

echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>";


ob_end_flush();

?>

Link to comment
Share on other sites

Your code is all over the place, there is no logical flow to your code so I'm not surprised it doesn't work.

 

Boy that helps, thanks a bunch man!  It's all over the place because it's been edited 100 different times..

 

It may not be helpful in providing a "quick-fix" to your problem, but it does explain why you are having a difficult time in getting it to work. There are times when I think something is simple and just start writing code only to get myself boxed into corners and spend too much time debugging and find out that I have a logical error in the program flow and have to rewrite it. It is always a good idea to write out the logical flow of the code before you start coding. It takes a little more time up front but, ultimately, you will get done faster and have better, less buggy code in the end.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.