SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help required with HTML and php

    Hi guys and girls.

    First post on here.

    Im not new to coding. Can code more than sufficiently in SQL, SAS, VB and Pascal (many years ago).

    I have a basic form created where someone is required to enter a stock/share code into it.

    I want to take this answer and add that to a website URL.

    For example someone types share code SOL, i want that to feed into the website's URL and when the answer is submitted the formaction is then the modified URL containing the give share code of SOL.

    So the original site is say... www.sharetracker.co.za/quote/

    What I want to do is when someone enters SOL in the form, the formaction URL should read www.sharetracker.co.za/quote/SOL

    But for the life of me I cannot reference the answer given in the form into the formaction URL.

    Read up on php stuff and echo and the $ used to reference answers but I am lost when it comes to HTML and php coding rules.

    Dont laugh here is what I tried.




    <?php
    $Cname = $_POST["Code"];
    ?>

    <form action=""http://www.sharenet.co.za/quote/" method="post">
    <p style="color:rgb(0,0,0)">Stock of Interest (Supply share code): <input type="text" name="Code" ></p><br>
    <input type="submit" formtarget="_blank" value="Submit" echo formaction="http://www.sharenet.co.za/quote/$code.">
    </form>

    See the red parts where I tried to echo and reference.

    Any help would be greatly appreciated
    Last edited by Mittineague; Mar 8, 2014 at 12:51. Reason: delinking example URLs

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    Try:
    PHP Code:
    <form method="post" action="http://www.sharenet.co.za/quote/<?php echo $code?>">
    '
    '
    <input type="submit" value="Submit">
    Your code is a bit mixed up as you are using get for the URL part and post as well.

    You will need to get the code from the URL and it is not a variable; so this will not work.
    PHP Code:
    <?php 
    // get the variable from the URL
     
    $Cname $_GET["code"];
     
    ?>

  3. #3
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    Lets start again - you are submitting your form to a folder called quote and not a php page according to your URL. What is the php page called?

  4. #4
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    Lets start again - you are submitting your form to a folder called quote and not a php page according to your URL. What is the php page called?
    Oh sorry it reads"<form action="c:\site\code.php"

    Now how do I tell the code to go fetch the submitted value from that file into the URL and then running that URL

    As I said I can code in a few languages but html and php is greek to me

  5. #5
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    double post

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,888
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Hi Saffa,

    The only way I can see to solve your problem is:

    test to see if your $_POST['testing'] variable has been set.

    if it is set
    save $_POST['testing'] to $newUrl value.
    reset $_POST['testing']
    redirect page with $newUrl
    else
    fall through and set the $newUrl ($_POST['testing']) parameter
    end


    PHP Code:
    <?php  if(isset($_POST['testing'])):    // $_SERVER['REQUEST_URI'] should be the page URL    // $_SERVER['SCRIPT_NAME'] should ALSO be the page URL
        
    $newUrl 'http://' .$_SERVER['SERVER_NAME'] .'/' .$_SERVER['REQUEST_URI'] .$_POST['testing'];    $newUrl str_replace(' ''-'$newUrl); // replace spaces with dashes    $_POST['testing'] = NULL;                 // reset to prevent loop
        
    header('Location: ' .$newUrl); // recall this page or send to another page  endif;  ?><!doctype html><head></head><body>
        <h4>Cosmetic to display $_POST and/or $_SERVER parameters</h4>    <pre style="background-color:#cff">      <br />      <?php print_r($_POST);?>      <?php # print_r($_SERVER); // shows all parameters?>      <br />    </pre>  
        <form action="?" method="post">      <p style="background-color:#cfc">        <br />        Set your URL parameter here: &nbsp;        <input type="text" name="testing" value="parameter_goes_here" />        <input type="submit" formtarget="_blank" value="Submit" />        <?php // echo formaction="http://www.sharenet.co.za/quote/$code." ?>        <br />      </p>    </form></body></html>
    Last edited by John_Betong; Mar 8, 2014 at 10:24. Reason: spelling: not my fortay
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •