/    Sign up×
Community /Pin to ProfileBookmark

Unsure how to go about making this script

I need help. I am highly unsure how to do what I am in need of. So let me explain.

I need to make a edit form for this: [URL=”http://coders-anonymous.com/phptesting/admineventsdisplay.php”]here[/URL]

The form Im wanting to make needs to know what its editing without the user specifying, like click a link and it gets you to a edit form that knows its editing that specific row. and I need to make my admindisplay.php automatically list a edit as a new event is made.

Can anyone help me out on this?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@sstalderAug 21.2008 — If you are asking someone to do work for you, maybe check out a freelance forum?
Copy linkTweet thisAlerts:
@OctoberWindAug 21.2008 — I'm building a CMS right now, and one of the admin features I'm coding as a part of the events page, is a 2 page solution. search-event.php and edit-event.php.

search-event.php queries the DB and just spits out a full list of everything in the table that I need (basically just the name and id, and currentEvent (bool)).

[code=php]
while ($eventList = mysql_fetch_assoc($result)) {
$id = $eventList['eventID'];
$current = $eventList['currentEvent'];
$event = $eventList['eventTitle'];

if ($current == '1') {
print "<li><strong><a href="/admin/edit-event.php?id=$id">$event</a></strong></li>";}
else {
print "<li><a href="/admin/edit-event.php?id=$id">$event</a></li>";
}
}
[/code]


The links send to edit-event.php (which would correspond with your event form) with a [B]?id=$id[/B]

From the edit-events.php i use:

[code=php]
$id = $_GET['id'];

if (isset ($id)){
[/code]


I use [B]mysql_fetch_assoc($result)[/B] from another query [B]WHERE eventID = $id[/B] to fill an array. I then just dump inline PHP to auto-fill the form with whatever is in the database for said-GET'd event.

[code=html]
<input class="textfield" type="text" size="75" name="eventTitle" value="<?php echo $title; ?>" />
[/code]


If [B]isset($_GET['id'])[/B] returns false (because either an ID was not sent or an ID was sent that isn't an event in your table, the form returns blank through another set of [B]$title = '';[/B]

Once the form is submitted, you can check [B]isset($_POST['submit-button-name'])[/B] and check your $id value against the DB. If it exists in the table, use an [B]$query = "UPDATE table WHERE id = $id ..."[/B] or [B]$query = "INSERT INTO table ..."[/B]

Hope this helps you figure out which way to go. I would take this with about 90% certainty, as I'm still learning more of the advanced PHP/MySQL as I do this project. It's been working for me so far, so I must be doing something right.
Copy linkTweet thisAlerts:
@CA-TaylorauthorAug 22.2008 — I have looked over your post quite a bit, but I can not seem to understand how to use it. I think its cause your variables are different. That may be why it confuses me.
Copy linkTweet thisAlerts:
@OctoberWindAug 25.2008 — Yes, In the above example one of the variables change. That's because edit-event.php (the second page, originally under a different name) was written first (without auto-filling the form) and the search-event.php was written probably 2-3 weeks later, using "recycled code" from the search-members.php page (which was written just days before).

Basically $event == $title, but because it's on two different database queries on two separate pages, the name is irrelevant. I could have used $elephant and $pineapple if I wanted to.

Also, i neglected to include every line of code, because (quite frankly) you don't learn anything by copy/pasting code from somewhere else. I feel I did a pretty good job explaining whats happening where I didn't paste my code, but if you're still confused, let me know where, and I'll try and re-explain it.
×

Success!

Help @CA-Taylor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...