简体   繁体   中英

pulling data from SQL DB, Saving in browser and displaying as a value on separate page

im am trying to get my head around " pulling data from SQL DB, Saving in browser and displaying as a value on separate page "

in a nutshell I am working on a project that requires you to enter customers details, the initial page (new_job.php) has a basic form which allows you to search the Clients DB for the corresponding client if no client is found it redirects you to create the client, however I would like It when a client is found, to be selected and the value to be held wether it be using Post and Get to port the data to the next page so I can automatically populate data based on the value ported over.

so far it have:

new_job.php

Head

if (isset($_POST['clientsubmit'])) {

            $ClientName = $_POST['ClientName'];

            echo "<script type='text/javascript'> document.location = 'new_job_create.php?createjob=<?php echo $result->ClientName;?>'; </script>";
        } else {
            echo "<script>alert('Invalid Client Name');</script>";
        }

Body

<form method="post" class="form-horizontal">

    <div class="modal-body">
        <label for="clientname">Client Name</label>
        <input type="text" name="ClientName" id="ClientName" Value="clientsubmit" class="form-control" placeholder="Search Clients" />
        <div id="clientList"></div>
    </div>

    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" name="clientsubmit" class="btn btn-primary">Create Job</button>
    </div>
</form>

The key areas are I'm struggling with are storing the ClientName to the browser

I have set the next page up to:

    if(isset($_GET['createjob']))
    {
        $CreateClient=$_GET['createjob'];
    }

but for some reason I cannot figure it out.

any help is appreciated.

You are assigning the form variable to a PHP var called $ClientName , but when you echo that out to create your JS redirect, you are echoing something called $result->ClientName . Where has the $result-> come from?

Also keep in mind that you need to url-encode the client name if you're going to pass it in the way that you seem to want to, if it's likely to contain anything that might confuse the parser, like a space.

Why doesn't the form directly post to new_job_create instead of going through new_job ? You could do all the validation and verification in a single script instead of adding to the job by passing data multiple times. If it already exists, that code could throw it back to the form, or to some code to display the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM