I am using php for the first time. I understand that creating a HTML form initilizes variable like $_POST, $_GET, $_REQUEST
etc.
I have the following code in my AddItem.php:
<?php require_once('../get-common/keys.php') ?>
<?php require_once('../get-common/eBaySession.php') ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>AddItem</TITLE>
</HEAD>
<BODY>
<FORM action="AddItem.php" method="post">
<TABLE cellpadding="2" border="0">
<TR>
<TD>listingType</TD>
<TD>
<select name="listingType">
<option value="Chinese">Chinese</option>
<option value="Dutch">Dutch</option>
<option value="FixedPriceItem">Fixed Price Item</option>
<option value="StoresFixedPrice">Stores Fixed Price</option>
</select>
</TD>
</TR>
<TR>
<TD>primaryCategory</TD>
<TD>
<select name="primaryCategory">
<option value="14111">Test Category</option>
<option value="57889">Boys Athletic Pants</option>
<option value="57890">Boys Corduroys Pants</option>
<option value="57891">Boys Jeans Pants</option>
<option value="57892">Boys Khakis Pants</option>
</select>
</TD>
</TR>
<TR>
<TD>itemTitle</TD>
<TD><INPUT type="text" name="itemTitle" value="TEST IN SANDBOX BEFORE PROD - DO NOT BID" size=30></TD>
</TR>
<TR>
<TD>itemDescription</TD>
<TD><INPUT type="text" name="itemDescription" value="TEST IN SANDBOX BEFORE PROD - DO NOT BID - This will incur prod listing fees" size=30></TD>
</TR>
<TR>
<TD>listingDuration</TD>
<TD>
<select name="listingDuration">
<option value="Days_1">1 day</option>
<option value="Days_3">3 days</option>
<option value="Days_5">5 days</option>
<option value="Days_7">7 days</option>
</select>
(defaults to GTC = 30 days for Store)
</TD>
</TR>
<TR>
<TD>startPrice</TD>
<TD><INPUT type="text" name="startPrice" value="<?php echo rand(1,200) / 100 ?>"></TD>
</TR>
<TR>
<TD>buyItNowPrice</TD>
<TD><INPUT type="text" name="buyItNowPrice" value="<?php echo rand(299,599) / 100; ?>"> (set to 0.0 for Store)</TD>
</TR>
<TR>
<TD>quantity</TD>
<TD><INPUT type="text" name="quantity" value="1"> (must be 1 for Chinese)</TD>
</TR>
<TR>
<TD colspan="2" align="right"><INPUT type="submit" name="submit" value="AddItem"></TD>
</TR>
</TABLE>
</FORM>
<?php
if(isset($_POST['listingType']))
//....some more code
?>
On running the file using php -f AddItem.php
only the HTML gets printed. Nothing inside the <?php ?>
gets executed. This is because $_POST is not initialized (prints Array
on echo).
Could someone please point out what I'm doing wrong here. Why is the $_POST not getting initialized?
Thanks
There is no HTTP call in php command line execution in your case, its pretty normal that $_POST will be empty.
As a work around, i would suggest doing something like the following:
The following code snippet will clarify my claims:
<?php
require_once('/path/to/your_command_line_php_script.php');
// Now inside your_command_line_php_script.php you will have $_POST available and initialized.
Hope this helps.
If you run php in the way you do. You are executing the script. But not actually posting the form. You will have to submit the form through a browser to populate the $_POST
vars