PDA

View Full Version : Changing the contents of $_POST['vars']


VxJasonxV
06-01-2003, 10:35 AM
Ok then, next issue.
I found out in PHP that if you assign a name to a checkbox then the value is either on or off.
(make a checkbox, name="check", echo $check; should read "on" or nothing)

So what I'm doing, is my form posts the data to itself.
I have this big 'ol section:
if(isset($_POST['spa']))
{
$spa = 1;
}
if(isset($_POST['dpa']))
{
$dpa = 1;
}
if(isset($_POST['fs']))
{
$fs = 1;
}
if(isset($_POST['dc']))
{
$dc = 1;
}

and then in my MySQL query, I just insert:
'" . $spa . "'
single-quote -> double-quote -> dot var dot -> double-quote -> single-quote.

Shouldn't this look like:
'1'
to the query?

(did that make sense?? I have an odd talent of not making sense lately...)


Over a year of C++, and this is best I come up with? A double equals when trying to assign a value??? AUGH!!!
Well, if it works, I'll re-edit it, and Steven or any other mod of this forum can delete it. (Lemme check and make sure first though!!!

Sardtok
06-02-2003, 09:03 AM
Hehe,
well what I hate even worse is when I manage to use the assignment operator instead of the comparison operator in an if clause or something,
that really makes me feel like a dumbbutt... ;)

Well I guess it should,
if you really want to be sure then escape the single quote even,
if you are checking against an int that you are using for a boolean,
then you don't need the single quotes, at least I don't think so...


Let me rephrase that,
if you are checking against an int that you are using for a boolean,
then you don't need the single quotes, and I am damn sure you don't...

Just checked the mysql docs and there are no quotes for integer operations...

VxJasonxV
06-02-2003, 09:23 AM
Heh, I hear you about the assignment operator in the if statements...that's always a fun one -_-, especially teaching other students that...

But thanks Sard.
Kinda funny, I was in bed at about 10PM (early night for me!). And I Was laying there listening to music and I pulled one of those:

*open eyes wide*
OH MY GOD, THAT'S THE PROBLEM!!!
*Get up, fix*
*Lay down, sleep*

:D


Oh, one last question. Since I've been testing this, my autonumber index has been growing, is there anyway to reset that? Or would I have to export the table structure and then re-import it?

Sardtok
06-02-2003, 11:08 AM
Are you adding something to the tables then removing them later on?

If that's the case there's an optimize query in sql (at least in mysql), that should fix this, you can access it by the phpmyadmin pages,
but I suppose you would want to run it sometime after you are done with your script or something like that so I am looking it up now...

Well didn't find it quickly in the docs,
but the command is:

OPTIMIZE TABLE 'table_name'

Not sure if you can do something like OPTIMIZE TABLE *

[edit]
Well I searched the mysql docs,
and it was in the administration part of the docs so no wonder I didn't find it in the language reference...
Any way...

OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name]...

For BDB tables, OPTIMIZE TABLE is currently mapped to ANALYZE TABLE

(Just in case you don't use MyISAM or something else)...

OPTIMIZE TABLE works the following way:

If the table has deleted or split rows, repair the table.
If the index pages are not sorted, sort them.
If the statistics are not up to date (and the repair couldn't be done by sorting the index), update them.

That's right from the docs, it should fix any problem of yours... ;)

[edit number 2]
Wild chars doesn't work with this command... *sniff*

VxJasonxV
06-02-2003, 02:21 PM
Yeah, it's just one table I'm testing users with, then I delete them as soon as I'm done. (Until this morning they were all messed up anyways.)
So just an 'OPTIMIZE TABLE swsd;' will reset the index in the table if there's no other records?
Sweet, thanks Sard :).

VxJasonxV
06-02-2003, 11:42 PM
Saaaaaaaaaaaaaard (or...anyone that can help ^_^).
OPTIMIZE TABLE swsd; didn't reset the index value.
Help anyone else? I'll poke around the MySQL docs, but assistance would be appreciated.

Sardtok
06-03-2003, 11:11 AM
Ok I think I've got the magic solution...
This will however completely reset the auto index...

ALTER TABLE swsd AUTO_INCREMENT=1

Or maybe it should be set to 0, but I don't think so...
I haven't tried this myself, but it's in the create table/alter table documentation...

I don't know how it will affect existing rows if any...
for instance if you still have rows with the autoindices 4 6 and 10
I'm not sure what will happen when it gets to those indices, but I think it will just skip them...

VxJasonxV
06-03-2003, 11:31 AM
I wound up accidentally clicking PRIMARY and having two 'num' Primary key fields. So I exported the structure, dropped the table, rebuilt it (modified) to have the one key. And the auto_increment reset :D.
That's probably a safer way to do it anyways.
But yes, you want to alter auto_increment to 1, not 0. It'll assign the auto_increment number when necessary. So you want it to assign a 1 (in most cases anyways).

:D.

Sardtok
06-03-2003, 11:56 AM
I thought you could only have ONE primary key, if you change the other one will no longer be the primary key...
Doesn't matter anyway, you have the magic command now,
in case you'd end up with lots of new members that you delete.... ;)

VxJasonxV
06-03-2003, 12:27 PM
Yeah, I didn't think you could have more than one primary key either.

Ah well.

If you wanna test out my form:
Registration Form (http://swsd.zenenet.com/reg.php)
Anybody is free to test it out, just be kind to my server please ^^;.
Lemme know if something goes wrong.

Sardtok
06-03-2003, 12:34 PM
Next time don't use the http:// link button up there, you entered the url as desc and desc as url so the url is now http://registration form/

VxJasonxV
06-03-2003, 03:20 PM
That's the first time I've done that...
Thank you for reporting that problem Sard -.-
(Wow, I'm on my feet today!!!)