Jump to content

Recommended Posts

Hey guys, I've got a quick question for you all.  I don't want you to write my code for me; I want to learn it myself.  However, what I'm trying to do I have no clue how to define or even where to look.  My problem is this:

 

I am trying to make a multi-page system which queries a database based upon two values, directory_id and company_name.  The first page displays the two fields in a table and I would like to make the company_name field a hyperlink to a second page, in which you can update/insert the information based upon which company you clicked.  Would this be using sessions, cookies, etc?

 

However, I am unsure of how to do this or what it would be called in a tutorial.  ???

 

Perhaps it has something to do with the URL I would be using to link the next .php page? ie.

 

http://www.mysite.com/pagetwo.php?=company_name=costco&id=2

 

If anyone could direct me to a tutorial or even link one here I would be eternally grateful.

OK

steps

#1, Query the database and echo all company names

#1.1, modify to echo as hyperlinks ie

<a href="edit.php?cid="..$row['id']">$row['cname']</a>

#1.2 NOTE: i used cid= id (this will be UID)

 

2.0 (the edit.php side)

2.1 create a 2nd file called edit.php design as a form (this will be for updating)

2.2 use $_GET['cid'] you get the id from 1.1 and select * from table where id = $_GET['cid'],

this returns the record you selected.

2.3 now edit your edit.php form to set the default values to the data from the database

2.3.1 remember to add a hidden field and set the default to the $_GET['cid'].

2.4 now add a button called update and a extra block of code

if(isset($_POST['update']))
{
//update table set cname =$_POST['cname'] etc etc  WHERE id = $_POST['cid']
}

 

thats the basic build any questions ? (please use ref numbers)

 

 

EDIT updated id to cid

OK

steps

#1, Query the database and echo all company names

#1.1, modify to echo as hyperlinks ie

<a href="edit.php?cid="..$row['id']">$row['cname']</a>

#1.2 NOTE: i used cid= id (this will be UID)

 

2.0 (the edit.php side)

2.1 create a 2nd file called edit.php design as a form (this will be for updating)

2.2 use $_GET['cid'] you get the id from 1.1 and select * from table where id = $_GET['cid'],

this returns the record you selected.

2.3 now edit your edit.php form to set the default values to the data from the database

2.3.1 remember to add a hidden field and set the default to the $_GET['cid'].

2.4 now add a button called update and a extra block of code

if(isset($_POST['update']))
{
//update table set cname =$_POST['cname'] etc etc  WHERE id = $_POST['cid']
}

 

thats the basic build any questions ? (please use ref numbers)

 

 

EDIT updated id to cid

 

Ok, so I've gotten my second page to reflect the choices from the first (ie. the name of the company/id via the $_GET command).  This is displayed at the top of the page along with a stripslashes command to ignore apostrophes.  When I get to your step 2.3 where you say to add a hidden input field, I decided to try changing the field momentarily to a text field.  It displays nothing more than the text "$_GET['id']" etc. how would I go about making this string?

 

I have:

 

<input type="text" name="idnum" value=$_GET["id"]>

<input type="text" name="conam" value=$_GET["cid"]>

 

(type was changed to text to check if I am inserting it properly.  I have tried using quotes around the $_GET field already)

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.