Jump to content

Splitting Cookies from a Post Form


smatt454

Recommended Posts

Hello.  I have a question I believe should be fairly straight forward.  Here's a little of my code, I believe seeing it first should help make my question more understandable.

$vendor[$x] = $_COOKIE["vendor$x"];

if ($vendor[$x] == "")
  $vendor[$x] = "Vendor name:\nAddress:\nCity:\nState:\nZip:";

<form name="request" action="./request.php" method="POST">
  <textarea name="vendor'.$x.'" rows="4" cols="30">'.$vendor[$x].'</textarea>
  <input type="submit" name="submit" value="Submit">
</form>

 

So basically, in request.php I want to split the $_POST value of vendor.  I want to look for the \n, and separate the values into Name, Address, City, State, and Zip.  I've never had to split cookies in an application, so any help would be greatly appreciated.

Link to comment
Share on other sites

Well I tried this

 

    $vendor[$x] = $_POST["vendor$x"];
    $vendorsplit = explode ("\n",$vendor[1]);
    setcookie("vendorname$x",$vendorplit[0]);

 

Just to clear it up, there is obviously a loop in both of these instances, but for simplicity sake I just tried to explode the first varriable.  Please note that I am currently getting the value of $_POST["vendor$x"] and putting it into a cookie called vendor$x.  In the above code, the program does run through the loop, and gets the POST values correctly.  However, when I try exploding vendor[1] (which contains the name, address, etc of the first vendor) and then setting the cookie vendorname$x as the first value in the array, the cookie is not set.

 

Any ideas?

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.