Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it,
follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given
their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!
[HTML/PHP] Pop-ups & forms
Posts
EDIT Before I even hit reply: I think I misunderstood, you if blocks are in PHP right? That's another way you can do it, such as index.php?action=add or action=update and then in the page itself you echo/print/etc a bunch of stuff for that page.
What you're moving into is basic CRUD operations (create/read/update/delete). The page you've been working on so far is Read.
Think about it this way - if you want to update an entry, that form needs to know which entry it is updating, and you actually need to read in its data first so that you can see what was there.
As for having multiple pages you can do this a few ways - on that "Read" page you can have links that go to Update/Delete which can display forms that were hidden on that page itself to do what you want for Update, or just a delete link.
Create could go at the bottom of the page with all the form elements required to create a new entry.
ed: I'd prefer not to have separate pages, which is why I brought it up.
It will do what you want - a popup containing whatever html you want, and in this case form elements.
add.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <form action="add.php" method="post"> <LABEL for="name">Name: </LABEL> <INPUT type="text" id="name" size="10" maxlength="127"> <p /> <LABEL for="comment">Comment: </LABEL> <INPUT type="text" id="comment" size="10" maxlength="255"> <p /> <input type="radio" id="status" value="u">Unfinished <br /> <input type="radio" id="status" value="b">Beaten <br /> <input type="radio" id="status" value="c">Completed <br /> <input type="radio" id="status" value="w">Wishlist <p /> <input type="submit" value="Add"> </form> </body> </html> [/CODE] [SIZE=4][B]add.php[/B][/SIZE] [CODE] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <?php $link = mysql_connect('localhost', 'root', '110185'); $db = mysql_select_db('backlog'); mysql_query("INSERT INTO ds (name, comment, status) VALUES ($name, $comment, $status)"); mysql_close($link); ?> </body> </html> [/CODE] Again, I'd like to not have separate pages, but this seemed like the easiest method. I'd prefer to keep all code in index.php[CODE]
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="css/css.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form action="add.php" method="post">
<LABEL for="name">Name: </LABEL>
<INPUT type="text" id="name" size="10" maxlength="127"> <p />
<LABEL for="comment">Comment: </LABEL>
<INPUT type="text" id="comment" size="10" maxlength="255"> <p />
<input type="radio" id="status" value="u">Unfinished <br />
<input type="radio" id="status" value="b">Beaten <br />
<input type="radio" id="status" value="c">Completed <br />
<input type="radio" id="status" value="w">Wishlist <p />
<input type="submit" value="Add">
</form>
</body>
</html>
[/CODE]
add.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <?php $link = mysql_connect('localhost', 'root', '110185'); $db = mysql_select_db('backlog'); mysql_query("INSERT INTO ds (name, comment, status) VALUES ($name, $comment, $status)"); mysql_close($link); ?> </body> </html> [/CODE] Again, I'd like to not have separate pages, but this seemed like the easiest method. I'd prefer to keep all code in index.php[CODE]
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="css/css.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<?php
$link = mysql_connect('localhost', 'root', '110185');
$db = mysql_select_db('backlog');
mysql_query("INSERT INTO ds (name, comment, status) VALUES ($name, $comment, $status)");
mysql_close($link);
?>
</body>
</html>
[/CODE]
Again, I'd like to not have separate pages, but this seemed like the easiest method. I'd prefer to keep all code in index.php
But if you're determined to do it, you can direct page rendering by adding variables to the url, and testing for that variable in your script. That is, something like:
http://me.com/index.php
Loads the main page.
http://me.com/index.php?page=form
Loads the submission form. Make branches in your script with an if() statement.
But like I said, it gets messy fast.
mysql_query("INSERT INTO ds (name, comment, status) VALUES ($name, $comment, $status)");to:
$sql = "INSERT INTO ds (name, comment, status) VALUES (". $_POST['name'] .",". $_POST['comment'].",".$_POST['status'])"; mysql_query($sql;);or you can use _REQUEST if you prefer. Is this your first time attempting this sort of thing?
As for your one page / multiple pages I usually seperate things out onto seperate pages. A controller for a database element will consist of a page for adding / editing, one for deleting and one for browsing the contents. I find it's easier for me to maintain a bunch of small pages rather than one massive one.
You could also streamline your code from the previous page by including an switch to check for the form being submitted, and either displaying the form or processing the results, so something like add.php consisting of:
<?php if (isset($_POST['submitter_check')) { // perform db update print "totally saved"; } else { ?> <form action="add.php" method="post"> <input type="hidden" name="submitter_check" value="totallytrue" /> <!-- rest of form gubbins --> </form> <?php } ?>I'm probably not the best at explaining things, but I do this stuff for a living so the knowledge is there, buried under layers of crap.
Please do the world a favor and run all submitted variables through mysql_real_escape_string before putting them in a query.
Bad idea, generally speaking, for security reasons. Use the correct super-global array.
Stack Exchange | http://www.mpdevblog.blogspot.com
<?php if(isset($_POST['submit']) { $link = mysql_connect('localhost', 'root', '110185'); $db = mysql_select_db('backlog'); /* you should check to see if the inputs have values, and if they're legit/properly formed before inserting them into the db. also, for the love of god, use mysql_real_escape_string(). */ mysql_query("INSERT INTO ds (name, comment, status) VALUES ($name, $comment, $status)"); mysql_close($link); // redirect if necessary } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <form action="add.php" method="post"> <LABEL for="name">Name: </LABEL> <INPUT type="text" id="name" size="10" maxlength="127"> <p /> <LABEL for="comment">Comment: </LABEL> <INPUT type="text" id="comment" size="10" maxlength="255"> <p /> <input type="radio" id="status" value="u">Unfinished <br /> <input type="radio" id="status" value="b">Beaten <br /> <input type="radio" id="status" value="c">Completed <br /> <input type="radio" id="status" value="w">Wishlist <p /> <input type="submit" value="Add"> </form> </body> </html>Aside from some logical things, your one file solution should be similar to the code above.
Stack Exchange | http://www.mpdevblog.blogspot.com
I'm trying to do that right now, by checking to see if the comment field is empty. I guess I'm not doing it correctly, as instead of adding an entry with/without a comment, it adds one with no comment and a completely blank entry.
if($_POST[comment] = null) $query = "INSERT INTO ds VALUES ('$_POST[name]', null, '$_POST[status]')"; else $query = "INSERT INTO ds VALUES ('$_POST[name]', '$_POST[comment]', '$_POST[status]')"; [/CODE] Also, why do I need mysql_real_escape_string() ?[CODE]
if($_POST[comment] = null)
$query = "INSERT INTO ds VALUES ('$_POST[name]', null, '$_POST[status]')";
else
$query = "INSERT INTO ds VALUES ('$_POST[name]', '$_POST[comment]', '$_POST[status]')";
[/CODE]
Also, why do I need mysql_real_escape_string() ?
Use "==" when checking to see if something is equal, "=" makes assignments. Right now, that code sets the comment to null, which technically returns true, so it then inserts that blank comment.
As for mysql_real_escape_string, it prevents SQL injection by escaping the data. SQL injection occurs when someone enters SQL into a text box or passes it through post data, and MySQL/any other SQL server executes that query.
Before
mysql> describe ds; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(127) | YES | | NULL | | | comment | varchar(255) | YES | | NULL | | | status | char(1) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ 3 rows in set (0.02 sec) [/CODE] [SIZE=4][B]After[/B][/SIZE] [CODE]mysql> describe ds; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(127) | NO | PRI | NULL | | | comment | varchar(255) | YES | | NULL | | | status | char(1) | NO | | NULL | | +---------+--------------+------+-----+---------+-------+ 3 rows in set (0.02 sec) [/CODE] And here's my add.php code: [CODE] <?php $link = mysql_connect('localhost', 'root', '******'); $db = mysql_select_db('backlog'); $query = null; if($_POST[name] != NULL) { if($_POST[comment] == NULL) $query = sprintf("INSERT INTO ds VALUES ('%s', null, '$_POST[status])')", mysql_real_escape_string($_POST[name])); else $query = sprintf("INSERT INTO ds VALUES ('%s', '%s', '$_POST[status]')", mysql_real_escape_string($_POST[name]), mysql_real_escape_string($_POST[comment])); } if($query != null) mysql_query($query); mysql_close($link); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <form action="add.php" method="post"> Name: <input type="text" name="name" /> <p /> Comment: <input type="text" name="comment" /> <p /> <input type="radio" name="status" value="u" checked />Unfinished <br /> <input type="radio" name="status" value="b" />Beaten <br /> <input type="radio" name="status" value="c" />Completed <br /> <input type="radio" name="status" value="w" />Wishlist <p /> <input type="submit" value="Add" /> </form> </body> </html> [/CODE][CODE]
mysql> describe ds;
+
+
+
+
+
+
+
| Field | Type | Null | Key | Default | Extra |
+
+
+
+
+
+
+
| name | varchar(127) | YES | | NULL | |
| comment | varchar(255) | YES | | NULL | |
| status | char(1) | YES | | NULL | |
+
+
+
+
+
+
+
3 rows in set (0.02 sec)
[/CODE]
After
mysql> describe ds; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(127) | NO | PRI | NULL | | | comment | varchar(255) | YES | | NULL | | | status | char(1) | NO | | NULL | | +---------+--------------+------+-----+---------+-------+ 3 rows in set (0.02 sec) [/CODE] And here's my add.php code: [CODE] <?php $link = mysql_connect('localhost', 'root', '******'); $db = mysql_select_db('backlog'); $query = null; if($_POST[name] != NULL) { if($_POST[comment] == NULL) $query = sprintf("INSERT INTO ds VALUES ('%s', null, '$_POST[status])')", mysql_real_escape_string($_POST[name])); else $query = sprintf("INSERT INTO ds VALUES ('%s', '%s', '$_POST[status]')", mysql_real_escape_string($_POST[name]), mysql_real_escape_string($_POST[comment])); } if($query != null) mysql_query($query); mysql_close($link); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <form action="add.php" method="post"> Name: <input type="text" name="name" /> <p /> Comment: <input type="text" name="comment" /> <p /> <input type="radio" name="status" value="u" checked />Unfinished <br /> <input type="radio" name="status" value="b" />Beaten <br /> <input type="radio" name="status" value="c" />Completed <br /> <input type="radio" name="status" value="w" />Wishlist <p /> <input type="submit" value="Add" /> </form> </body> </html> [/CODE][CODE]mysql> describe ds;
+
+
+
+
+
+
+
| Field | Type | Null | Key | Default | Extra |
+
+
+
+
+
+
+
| name | varchar(127) | NO | PRI | NULL | |
| comment | varchar(255) | YES | | NULL | |
| status | char(1) | NO | | NULL | |
+
+
+
+
+
+
+
3 rows in set (0.02 sec)
[/CODE]
And here's my add.php code:
<?php $link = mysql_connect('localhost', 'root', '******'); $db = mysql_select_db('backlog'); $query = null; if($_POST[name] != NULL) { if($_POST[comment] == NULL) $query = sprintf("INSERT INTO ds VALUES ('%s', null, '$_POST[status])')", mysql_real_escape_string($_POST[name])); else $query = sprintf("INSERT INTO ds VALUES ('%s', '%s', '$_POST[status]')", mysql_real_escape_string($_POST[name]), mysql_real_escape_string($_POST[comment])); } if($query != null) mysql_query($query); mysql_close($link); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> </head> <body> <form action="add.php" method="post"> Name: <input type="text" name="name" /> <p /> Comment: <input type="text" name="comment" /> <p /> <input type="radio" name="status" value="u" checked />Unfinished <br /> <input type="radio" name="status" value="b" />Beaten <br /> <input type="radio" name="status" value="c" />Completed <br /> <input type="radio" name="status" value="w" />Wishlist <p /> <input type="submit" value="Add" /> </form> </body> </html> [/CODE][CODE]
<?php
$link = mysql_connect('localhost', 'root', '******');
$db = mysql_select_db('backlog');
$query = null;
if($_POST[name] != NULL) {
if($_POST[comment] == NULL)
$query = sprintf("INSERT INTO ds VALUES ('%s', null, '$_POST[status])')",
mysql_real_escape_string($_POST[name]));
else
$query = sprintf("INSERT INTO ds VALUES ('%s', '%s', '$_POST[status]')",
mysql_real_escape_string($_POST[name]),
mysql_real_escape_string($_POST[comment]));
}
if($query != null)
mysql_query($query);
mysql_close($link);
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="css/css.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form action="add.php" method="post">
Name:
<input type="text" name="name" /> <p />
Comment:
<input type="text" name="comment" /> <p />
<input type="radio" name="status" value="u" checked />Unfinished <br />
<input type="radio" name="status" value="b" />Beaten <br />
<input type="radio" name="status" value="c" />Completed <br />
<input type="radio" name="status" value="w" />Wishlist <p />
<input type="submit" value="Add" />
</form>
</body>
</html>
[/CODE]
Try simply:
$queryFormat = "INSERT INTO ds VALUES ('%s', '%s', '%s')"; $query = sprintf($queryFormat, mysql_real_escape_string($_POST['name']), mysql_real_escape_string($_POST['comment']), mysql_real_escape_string($_POST['status']));You don't need to check if the comment is null...an empty string will suffice. So, that way, you remove a conditional and make your code that much easier to debug.
Stack Exchange | http://www.mpdevblog.blogspot.com
Edit: And it's always a good idea to read your code before asking for help.
Just a few things guar:
I would use an add.php that has the form and submits (POSTs) to itself, then have code that checks the $_POST super global array to see whether a form submission occured, because you can then report errors or report success directly on the form, with the old data that was submitted.
Accessing stuff from an array (zeeny mentioned this) you have to use a ' or " to escape the literal string, so that something like $_POST[name] becomes $_POST. This is so PHP knows that name is not a function/variable/etc. PHP usually is smart enough to "figure it out", but will tell you what it assumed (if your PHP said nothing I'd check your settings, not sure which unfortunately..)
HTML Labels: If you put the input inside the Label, you don't need to use the for attribute. Useful when the label and input are directly next to each other in the source code.
I think, but I'm not sure, that the Doctype needs to be the very first line that a browser sees, so if you have PHP before it, just end the php (?>) on the same line as the Doctype.
How have you separated out your database tables for the different consoles? Do you have a table for each console? You might want to look at having a single table and an extra column, either enum or just plain-text to describe, such as console_type. Then you just select where console_type = type of console
This would also make it easier to grab related data such as "all my unfinished games". Obviously this only works if the columns are the same in all your tables.
It's been so long since I actually used raw sql to make an update that I forget it every time. Usually propel / Smarty sanitises everything for me.
Different table for each system + columns are the same. I might consider having one table, but I'd need to have 2 primary keys to avoid any duplicates.
Make a sort.inc.php file. Cut/paste the sortBy() function in it and do an
in the start of the php section of both files making use of the routine.
It is usually a good idea to organize all functions by type/relation into separate inc files into separate php include files. Makes it a lot easier to reuse code.
It's even a better idea to make use of PHP's OO capabilities, but probably unnecessary for the size of your project.
You just need an auto-increment id column which is unique - anything else like name/title doesn't need to be?
Also, your javascript popup function should probably add the bolded+underlined parts - not all browsers might treat an anchor object as resolving to its href.
function popup(link, id) { if(!window.focus) return true; if(id == 'add') window.open(link[u][b].href[/b][/u], id, 'width=427, height=336'); else window.open(link[u][b].href[/b][/u], id, 'width=450, height=350'); return false; }No, just the title. If I could figure out how to pass the system name to the pop-up window, I'd stick with my current setup. I don't really need to query the database beyond what I'm doing at this point.
So I have this method:
<script type="text/javascript"> function select() { var i = document.rform.rname.selectedIndex; var selected = document.rform.rname.options[i].text; document.rform.name.value = selected; document.rform.comment.value = ""; } </script> [/CODE] [SPOILER] [SIZE=4][B]remove.php[/B][/SIZE] [CODE] <?php require('sort.inc.php'); $link = mysql_connect('localhost', 'root', '110185'); $db = mysql_select_db('backlog'); $names = sortBy(name, ds); $cmnt = sortBy(comment, ds); $stat = sortBy(status, ds); $n = mysql_num_rows($names); $query = null; //if($_POST[name] != NULL) { //$query = sprintf("DELETE FROM ds WHERE name=''"); //} if($query != null) mysql_query($query); mysql_close($link); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> <script type="text/javascript"> function select() { var i = document.rform.rname.selectedIndex; var selected = document.rform.rname.options[i].text; document.rform.name.value = selected; document.rform.comment.value = ""; } </script> </head> <body> <form name="rform" action="remove.php" method="post"> <select name="rname" onchange="select()"> <?php for($k = 0; $k < $n; $k++) { echo "<option>"; echo mysql_result($names, $k); echo "</option>"; } ?> </select> <p /> Name: <br /> <textarea name="name" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p /> Comment: <br /> <textarea name="comment" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p /> <input type="radio" name="status" value="u" disabled="true" />Unfinished <br /> <input type="radio" name="status" value="b" disabled="true" />Beaten <br /> <input type="radio" name="status" value="c" disabled="true" />Completed <br /> <input type="radio" name="status" value="w" disabled="true" />Wishlist <p /> <input type="submit" value="Remove" /> </form> </body> </html> [/CODE] [/SPOILER] My intent is to have the Name, Comment, and Status fields display the values corresponding to what's selected in the drop down menu. How can I get the comment and status to do this?[CODE]
<script type="text/javascript">
function select() {
var i = document.rform.rname.selectedIndex;
var selected = document.rform.rname.options.text;
document.rform.name.value = selected;
document.rform.comment.value = "";
}
</script>
[/CODE]
<?php require('sort.inc.php'); $link = mysql_connect('localhost', 'root', '110185'); $db = mysql_select_db('backlog'); $names = sortBy(name, ds); $cmnt = sortBy(comment, ds); $stat = sortBy(status, ds); $n = mysql_num_rows($names); $query = null; //if($_POST[name] != NULL) { //$query = sprintf("DELETE FROM ds WHERE name=''"); //} if($query != null) mysql_query($query); mysql_close($link); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link href="css/css.css" rel="Stylesheet" type="text/css" /> <script type="text/javascript"> function select() { var i = document.rform.rname.selectedIndex; var selected = document.rform.rname.options[i].text; document.rform.name.value = selected; document.rform.comment.value = ""; } </script> </head> <body> <form name="rform" action="remove.php" method="post"> <select name="rname" onchange="select()"> <?php for($k = 0; $k < $n; $k++) { echo "<option>"; echo mysql_result($names, $k); echo "</option>"; } ?> </select> <p /> Name: <br /> <textarea name="name" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p /> Comment: <br /> <textarea name="comment" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p /> <input type="radio" name="status" value="u" disabled="true" />Unfinished <br /> <input type="radio" name="status" value="b" disabled="true" />Beaten <br /> <input type="radio" name="status" value="c" disabled="true" />Completed <br /> <input type="radio" name="status" value="w" disabled="true" />Wishlist <p /> <input type="submit" value="Remove" /> </form> </body> </html> [/CODE] [/SPOILER] My intent is to have the Name, Comment, and Status fields display the values corresponding to what's selected in the drop down menu. How can I get the comment and status to do this?[CODE]
<?php
require('sort.inc.php');
$link = mysql_connect('localhost', 'root', '110185');
$db = mysql_select_db('backlog');
$names = sortBy(name, ds);
$cmnt = sortBy(comment, ds);
$stat = sortBy(status, ds);
$n = mysql_num_rows($names);
$query = null;
//if($_POST[name] != NULL) {
//$query = sprintf("DELETE FROM ds WHERE name=''");
//}
if($query != null)
mysql_query($query);
mysql_close($link);
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="css/css.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript">
function select() {
var i = document.rform.rname.selectedIndex;
var selected = document.rform.rname.options.text;
document.rform.name.value = selected;
document.rform.comment.value = "";
}
</script>
</head>
<body>
<form name="rform" action="remove.php" method="post">
<select name="rname" onchange="select()">
<?php
for($k = 0; $k < $n; $k++) {
echo "<option>";
echo mysql_result($names, $k);
echo "</option>";
}
?>
</select> <p />
Name: <br />
<textarea name="name" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p />
Comment: <br />
<textarea name="comment" rows="5" cols="75" wrap="physical" disabled="true"></textarea> <p />
<input type="radio" name="status" value="u" disabled="true" />Unfinished <br />
<input type="radio" name="status" value="b" disabled="true" />Beaten <br />
<input type="radio" name="status" value="c" disabled="true" />Completed <br />
<input type="radio" name="status" value="w" disabled="true" />Wishlist <p />
<input type="submit" value="Remove" />
</form>
</body>
</html>
[/CODE]
My intent is to have the Name, Comment, and Status fields display the values corresponding to what's selected in the drop down menu. How can I get the comment and status to do this?
You need to use an id column. DELETE from where name is a bad idea.
In fact you've gone about this removal form the wrong way; you shouldn't need one at all. On your index page you should just be able to click a link to remove that particular game.
Game Name
Game Description
Edit | Delete
Edit takes you to a form, Delete just deletes (preferably with a javascript confirm at the very least).
The delete link should take you to something like /delete.php?id=6, where id is the id of the game being deleted, which would then just redirect back to index.php
I feel like doing this myself over the weekend now...
EDIT: As for passing the "system name" to the popup window, that is simple - just have the link be different using page.php?systemname=something, or in the case that I really want you to use, page.php?id=id
Just as a side note, ideal database design suggests you never use a column with inherent meaning as a primary key. I would understand not wanting to redo all your work so far, but in the future, an auto-incrementing ID as a primary key would be preferable.
I'm not sure I understand this. Can I pass variables between pages, or are you implying I make a separate page for each id?
You can pass variables between pages. From the '?' on is what's known as a query string. PHP can grab a hold of whatever value(s) is/are in there via the $_GET superglobal array.
So, say you have a query string of page.php?system=23&user=67 - you can simply grab them like so:
Be sure to code defensively, though, as values are being passed to your script from the address bar. Anyone can modify the query string and submit it to your page(s).
Stack Exchange | http://www.mpdevblog.blogspot.com
(2) I've set it up before to have the pop-up window close on submit, but it closes before the data is sent. How can I have it so after hitting the 'Add/Update' button, it closes the window and refreshes index.php ? I have delete.php set up to immediately redirect back to index.php via a meta tag in the header, can I do something similar with this?
You don't want to do this. An ID is just that, it should be unique for the lifetime of your database. The game that was #3 is not the game you are adding, so you don't want to call it #3 in your database.
If I have another table that has a record saying "I completed 56% of game #3" and I don't clean that up when I delete #3 from the game table, then when I add a new game and it's given ID #3 then it's inconsistently marked 56% complete.
That's a trivial example and likely to be cleaned up properly, but only because the database is so simple. The proper way is the way the database is currently working your auto-increment and this is why.
You could do asynchronous submits (AJAX) but the simpler solution for you would probably be to do the redirect yes. Just handle the form submit and then redirect to a closewin.php that just simply closes itself.
Btw, you can do an HTTP redirect instead of an HTML meta refresh, by doing the following instead of sending any HTML back.
header('Location: /mypage.php');The PhalLounge :: Chat board for Phalla discussion and Secret Santas :: PhallAX 2013
Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
You just need to do it before anything (HTML, whitespace, etc...) is sent to the browser, else you'll get a "Headers already sent" error.
Stack Exchange | http://www.mpdevblog.blogspot.com
Right right, it needs to be the only thing sent. Not technically, but as far as you're concerned it's easiest to think of it that way Guar.
The PhalLounge :: Chat board for Phalla discussion and Secret Santas :: PhallAX 2013
Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org