Jump to content

[SOLVED] Please help! This is not code begging!


Delaran

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.