Author Topic: How would you process a form that is echo'd using php instead of HTML?????  (Read 524 times)

0 Members and 1 Guest are viewing this topic.

Offline ModernvoxTopic starter

  • Enthusiast
  • Posts: 411
  • Gender: Male
    • View Profile
I have this form I am trying to process, but it won't work?
if($count==0){

Code: [Select]
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
Code: [Select]
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();
   }
« Last Edit: September 02, 2010, 02:30:24 PM by Modernvox »
If I wanted any shit out of you i'd squeeze your fuckin head!
JustHost Sucks!

Offline ModernvoxTopic starter

  • Enthusiast
  • Posts: 411
  • Gender: Male
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #1 on: September 02, 2010, 02:45:45 PM »
Seems as if no one at phpfreaks echo's forms. I guess this is advanced programinng?
If I wanted any shit out of you i'd squeeze your fuckin head!
JustHost Sucks!

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #2 on: September 02, 2010, 03:02:41 PM »
Quote
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'];

Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,751
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #3 on: September 02, 2010, 03:25:45 PM »
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?
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline ModernvoxTopic starter

  • Enthusiast
  • Posts: 411
  • Gender: Male
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #4 on: September 02, 2010, 03:41:29 PM »
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
Code: [Select]
<?php
error_reporting
(E_ALL);
ini_set("display_errors"1);

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

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

if (
$logUser1) {
header("Location: inprogress.php");
exit();
}

else if (
$logUser2){
// 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();

?>
If I wanted any shit out of you i'd squeeze your fuckin head!
JustHost Sucks!

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #5 on: September 02, 2010, 04:14:49 PM »
Your code is all over the place, there is no logical flow to your code so I'm not surprised it doesn't work.

Offline ModernvoxTopic starter

  • Enthusiast
  • Posts: 411
  • Gender: Male
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #6 on: September 02, 2010, 04:20:03 PM »
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..
« Last Edit: September 02, 2010, 04:21:08 PM by Modernvox »
If I wanted any shit out of you i'd squeeze your fuckin head!
JustHost Sucks!

Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,751
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #7 on: September 02, 2010, 04:52:47 PM »
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.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,751
    • View Profile
Re: How would you process a form that is echo'd using php instead of HTML?????
« Reply #8 on: September 02, 2010, 04:54:39 PM »
Hmm... here are some problems right off the top!
if ($logUser1)
else if ($logUser2)

Need to use double equal signs for comparison. I also see that the variables used in most of your queries don't seem to be defined.
« Last Edit: September 02, 2010, 05:02:18 PM by mjdamato »
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net