Jump to content

EriRyoutan

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

EriRyoutan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. byeh... i figured it out, and it wasn't a problem with the syntax. lets just say i was stupid, and didn't know how to program php. (i had the bright idea of making a query() function to do mysql_query with the or die() every time, but the problem was that i coded -that- wrong, so... yeah. ) note to others: make sure the problem is the one it tells you to look at...
  2. That's the first one I tried, actually, before i started messing with the syntax. It still pukes with the same error, [code]...check syntax near 'WHERE `day` =  '2006-08-07'' at line 1[/code]
  3. :-\ for some reason, i can't get a select from a date field to work. it always pukes up with an error and says [code]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE day = 20060807' at line 1[/code] ... gee, thanks mr. error message... anyway, here's a summary of what i've got... and i've got the errors actually trapped, it just takes up a lot of code room... [code]mysql_query("CREATE TABLE table ( `id` INT NOT NULL AUTO_INCREMENT , `day` DATE, `stuff` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MYISAM; //add fake data to table here... //none of these work, though... mysql_query("SELECT * FROM table WHERE day = 20060807;"); mysql_query("SELECT * FROM table WHERE day = '20060807';"); mysql_query("SELECT * FROM table WHERE `day` = '20060807';"); mysql_query("SELECT * FROM table WHERE day = 2006-08-07;"); mysql_query("SELECT * FROM table WHERE `day` = '2006-08-07';"); mysql_query("SELECT * FROM table WHERE `day` = '06-08-07';"); mysql_query("SELECT stuff FROM table WHERE day = 20060807;");[/code] ... glurgh... any ideas? thank you for reading this, by the way. ^^
  4. erk. too many languages, can't keep the stupid operators straight. x.x; anyway, thanks. ... now i feel stupid... x.x;
  5. okay. what i'm trying to do is something like [code]foreach ($suits as $b) { foreach($types as $a) { global $names; $names = $names + array($a . " of " . $b); } }[/code] so I could make a deck of cards. But for some reason, when I spit it out at the end, $names has the same value as it did when it started. ... any ideas?
  6. Okay, I have a working source code (sorry for the lack of comments) That's SUPPOSED to make just about any MySQL database editable with only a bit of information. Problem being: It dosen't like to add anything to an empty table. (aka only headers, no rows...) It works pretty well otherwise... ... But... Won't do anything unless there's at least one row. Any ideas? And I apologize AGAIN for the lack of comments.... If I can help explain any of it, let me know... [code] <?php //MySQL Settings... $host   = " "; $user   = " "; $pass   = " "; $dbname = " "; $table  = $_GET['table']; $pathto = " "; //Absolute path to this file... Allows saving of page and updating later. (Backup ability) ?> <?php mysql_connect ($host, $user, $pass); mysql_select_db ($dbname); if(isset($_POST["newc0"])) {     $numrows = 0;     $numcols = 0;     while(isset($_POST["r" . ++$numrows . "c" . $numcols])){;}     $numrowsb = $numrows - 1;     while(isset($_POST["r" . $numrowsb . "c" . ++$numcols])){;}     $looprow = -1;     while(++$looprow != $numrows)     {         $loopcol = 0;         $ortest = false;         while($loopcol != $numcols)         {             if($_POST["r" . $looprow . "c" . $loopcol] != $_POST["oldr" . $looprow . "c" . $loopcol++])             {                 $ortest = true;             }         }         if($ortest)         {             $query = "UPDATE $table SET ";             $loopcol = -1;             while(++$loopcol != $numcols)             {                 $query = $query . "`" . $_POST["c" . $loopcol] . "` = '"                 . html_entity_decode($_POST["r" . $looprow . "c" . $loopcol]) . "'";                 if($loopcol != $numcols - 1)                 {                     $query = $query . ", ";                 }                 else                 {                     $query = $query . " WHERE ";                 }             }             $loopcol = -1;             while(++$loopcol != $numcols)             {                 $query = $query . "`" . $_POST["c" . $loopcol] . "` = '"                 . html_entity_decode($_POST["oldr" . $looprow . "c" . $loopcol]) . "'";                 if($loopcol != $numcols - 1)                 {                     $query = $query . " AND ";                 }                 else                 {                     $query = $query . " LIMIT 1;";                 }             }             mysql_query($query);         }     if(isset($_POST["delr$looprow"]))     {       $query = "DELETE FROM `$table` WHERE ";       $loopcol = 0;             while(++$loopcol != $numcols)             {                 $query = $query . "`" . $_POST["c" . $loopcol] . "` = '"                 . html_entity_decode($_POST["r" . $looprow . "c" . $loopcol]) . "'";                 if($loopcol != $numcols - 1)                 {                     $query = $query . " AND ";                 }                 else                 {                     $query = $query . " LIMIT 1;";                 }             }             mysql_query($query);     }     }     $loopcol = 0;     $ortest = false;     while($loopcol != $numcols)     {         if($_POST["newc" . $loopcol++] != "")         {             $ortest = true;         }     }     if($ortest)     {         $query = "INSERT INTO $table VALUES ('";         $loopcol = -1;         while(++$loopcol != $numcols)         {             $query = $query . html_entity_decode($_POST["newc" . $loopcol]);             if($loopcol != $numcols - 1)             {                 $query = $query . "','";             }             else             {                 $query = $query . "');";             }         }         mysql_query($query);     }     echo "Database Updated...<br>\n"; } ?>Input Data:<br> <form action="<?php echo $pathto . "?table=" . $table ?>" method="post"><table border=1> <tr><?php $query = "SELECT * FROM $table"; $data = mysql_query($query); mysql_close(); $numcols = mysql_num_fields($data); $numrows = mysql_num_rows($data); $loopcol = -1; while(++$loopcol != $numcols) {     echo "<td>\""     . mysql_field_name($data, $loopcol)     . "\" "     . mysql_field_type($data, $loopcol)     . ' ('     . mysql_field_len($data, $loopcol)     . ')<br>'     . mysql_field_flags($data, $loopcol)     . "</td>\n<input type=\"hidden\" name=\"c"     . $loopcol . "\" value=\""     . mysql_field_name($data, $loopcol)     . "\">\n"; } echo "<td>Del</td></tr>\n\n"; $looprow = -1; while(++$looprow != $numrows) {     echo "<tr>\n";     $loopcol = -1;     while(++$loopcol != $numcols)     {         echo "<td><input name=\"r{$looprow}c{$loopcol}\" maxlength="         . mysql_field_len($data, $loopcol)         . " value=\""         . htmlentities(mysql_result($data, $looprow, mysql_field_name($data, $loopcol)))         . "\"></td>\n"         . "<input type=\"hidden\" name=\"oldr{$looprow}c{$loopcol}\" value=\""         . htmlentities(mysql_result($data, $looprow, mysql_field_name($data, $loopcol)))         . "\">\n";     }   echo "<td><input type=\"checkbox\" name=\"delr$looprow\"></td>";     echo "</tr>\n\n"; } echo"<tr><td colspan={$numcols}><hr>New Data:</td></tr>\n<tr>\n"; $loopcol = -1; while(++$loopcol != $numcols) {     echo "<td><input name=\"newc{$loopcol}\" maxlength="     . mysql_field_len($data, $loopcol)     . "></td>\n"; } ?></tr> </table><input type="submit" value="Update Database"></form> [/code]
  7. Finished! ^^ See if you guys can guess what it's supposed to do. Oh, and proofreading would be appreciated, cause... uh... I don't trust myself. >>; all I know is that it works. ^^ [code]<?php //MySQL Settings... $host   = " "; $user   = " "; $pass   = " "; $dbname = " "; $table  = " "; ?> <?php mysql_connect ($host, $user, $pass); mysql_select_db ($dbname); if(isset($_POST["r0c0"])) {     $numrows = 0;     $numcols = 0;     while(isset($_POST["r" . ++$numrows . "c" . $numcols])){;}     $numrowsb = $numrows - 1;     while(isset($_POST["r" . $numrowsb . "c" . ++$numcols])){;}     echo "r$numrows c$numcols <br>";     $looprow = -1;     while(++$looprow != $numrows)     {         $loopcol = 0;         $ortest = false;         while($loopcol != $numcols)         {             if($_POST["r" . $looprow . "c" . $loopcol] != $_POST["oldr" . $looprow . "c" . $loopcol++])             {                 $ortest = true;             }         }         if($ortest)         {             $query = "UPDATE $table SET ";             $loopcol = -1;             while(++$loopcol != $numcols)             {                 $query = $query . "`" . $_POST["c" . $loopcol] . "` = '"                 . html_entity_decode($_POST["r" . $looprow . "c" . $loopcol]) . "'";                 if($loopcol != $numcols - 1)                 {                     $query = $query . ", ";                 }                 else                 {                     $query = $query . " WHERE ";                 }             }             $loopcol = -1;             while(++$loopcol != $numcols)             {                 $query = $query . "`" . $_POST["c" . $loopcol] . "` = '"                 . html_entity_decode($_POST["oldr" . $looprow . "c" . $loopcol]) . "'";                 if($loopcol != $numcols - 1)                 {                     $query = $query . " AND ";                 }                 else                 {                     $query = $query . " LIMIT 1;";                 }             }             mysql_query($query);         }     }     $loopcol = 0;     $ortest = false;     while($loopcol != $numcols)     {         if($_POST["newc" . $loopcol++] != "")         {             $ortest = true;         }     }     if($ortest)     {         $query = "INSERT INTO $table VALUES ('";         $loopcol = -1;         while(++$loopcol != $numcols)         {             $query = $query . html_entity_decode($_POST["newc" . $loopcol]);             if($loopcol != $numcols - 1)             {                 $query = $query . "','";             }             else             {                 $query = $query . "');";             }         }         mysql_query($query);     }     echo "Database Updated...<br>\n"; } ?>Input Data:<br> <form action="./dbedit.php" method="post"><table border=1> <tr><?php $query = "SELECT * FROM $table"; $data = mysql_query($query); mysql_close(); $numcols = mysql_num_fields($data); $numrows = mysql_num_rows($data); $loopcol = -1; while(++$loopcol != $numcols) {     echo "<td>\""     . mysql_field_name($data, $loopcol)     . "\" "     . mysql_field_type($data, $loopcol)     . ' ('     . mysql_field_len($data, $loopcol)     . ')<br>'     . mysql_field_flags($data, $loopcol)     . "</td>\n<input type=\"hidden\" name=\"c"     . $loopcol . "\" value=\""     . mysql_field_name($data, $loopcol)     . "\">\n"; } echo "</tr>\n\n"; $looprow = -1; while(++$looprow != $numrows) {     echo "<tr>\n";     $loopcol = -1;     while(++$loopcol != $numcols)     {         echo "<td><input name=\"r{$looprow}c{$loopcol}\" maxlength="         . mysql_field_len($data, $loopcol)         . " value=\""         . htmlentities(mysql_result($data, $looprow, mysql_field_name($data, $loopcol)))         . "\"></td>\n"         . "<input type=\"hidden\" name=\"oldr{$looprow}c{$loopcol}\" value=\""         . htmlentities(mysql_result($data, $looprow, mysql_field_name($data, $loopcol)))         . "\">\n";     }     echo "</tr>\n\n"; } echo"<tr><td colspan={$numcols}><hr>New Data:</td></tr>\n<tr>\n"; $loopcol = -1; while(++$loopcol != $numcols) {     echo "<td><input name=\"newc{$loopcol}\" maxlength="     . mysql_field_len($data, $loopcol)     . "></td>\n"; } ?></tr> </table><input type="submit" value="Update Database"></form>[/code]
  8. Hey... I only got a chance to glance at you guys's code before I got dragged around to places (namely school) but while i was there I managed to come up with something more or less what I was looking for. Thanks for the help, 'cause even though it's not your code, it still took ideas from it. ^^; [code]$numelements = 5; //or whatever... $counter = 0; $ortest = false; while($counter != $numelements) { if($_POST[{"stuff" . $counter}] != $_POST[{"other" . $counter++}]) {$ortest = true;} } if($ortest){echo "Do stuff...";}[/code] is the code in general terms... [code]//CONNECT //numcols and numrows already set $looprow = -1; while(++$looprow != $numrows) { $loopcol = 0; $ortest = false; while($loopcol != $numcols)   {if($_POST[{"r" . $looprow . "c" . $loopcol}] != $_POST[{"oldr" . $looprow . "c" . $loopcol++}])    {$ortest = true;}   } if($ortest){echo "Do update stuff...";} } $loopcol = 0; $ortest = false; while($loopcol != $numcols) {if($_POST[{"newc" . $loopcol++}] != ""}])   {$ortest = true;} } if($ortest){echo "Do insert stuff...";} //other code... post the freaking field names... mysql_close();[/code] The top half takes care of the part I was asking you guys about, while the bottom part is basically the same problem with a different application. With any luck, I'll be able to post the full source code here in... well, before tonite. ... ... PS, my luck sucks. -.-;; EDIT: Syntax error ><;; Replace every [{ with [ and }] with ] ... -cough- ... Sorry.
  9. What I'm trying to do is check a big list of things. ... The problem is, the number of things in the list changes. sometimes it'll be as short as [code]if($a == $a2 || $b == $b2)[/code] Sometimes it'll have ten elements, sometimes up to like twenty. (I hope not ><; ) I'm trying to keep it dynamic, tho. AKA, if I only put in 20 spots, and I try and use 21 later... (sample testing)[code]if( $_POST["oldr0c0"] != $_POST["r0c0"] ||  $_POST["oldr0c1"] != $_POST["r0c1"] ||  $_POST["oldr0c2"] != $_POST["r0c2"] ||  $_POST["oldr0c3"] != $_POST["r0c3"] ||  $_POST["oldr0c4"] != $_POST["r0c4"] ||  $_POST["oldr0c5"] != $_POST["r0c5"] ) {echo "Do Stuff...";} if( $_POST["oldr1c0"] != $_POST["r1c0"] ||  $_POST["oldr1c1"] != $_POST["r1c1"] ||  $_POST["oldr1c2"] != $_POST["r1c2"] ||  $_POST["oldr1c3"] != $_POST["r1c3"] ||  $_POST["oldr1c4"] != $_POST["r1c4"] ||  $_POST["oldr1c5"] != $_POST["r1c5"] ) {echo "Do Other Stuff...";}[/code] I've already got the old and the new set up, but that way, if ANY of it changes, then it will do it. but if it's ALL the same, it just stays...
  10. Okay. What I'm trying to do is come up with a way to make an infinite (?) number of OR's in an if statement. ex:[code]if($a == $a2 || $b == $b2 || $c == $c2 [...])[/code] I was thinking about using arrays, but that seems like it would end up being like an AND statement.[code]if(array1[] == array2[])[/code] Hm... any ideas? Thanks for reading. ^^
  11. I was working on a php script, and I came across a problem. ... I can't tell what type this variable is. Does anybody know any easy ways to tell what type a variable is, without just trial and error? Thanks -Eri.
  12. Hi again. I'm working on writing a page that keeps getting new content added to it like every few minutes, and i would like it to be either streaming or auto-refreshing. I've heard of it possible with PERL but I'd like to do it using only PHP and/or JavaScript (or HTML, but that's kind of a given) Thanks for reading, and hope somebody out there has a (simple?) answer. EDIT: Oh! and does anybody know if $_SESSION[''] $_GET[''] etc, etc. have to be capitalized?
  13. I'm pretty sure register globals is on... I've done the rest of the php on my site using the same way (declare it in url, use it in code)... so... what's wrong with session_register() and _is_registered() ? ... What do you suggest using otherwise? I glanced at the manual (didn't have much time to -read- it...) and on an absolute sidenote, thank you for this much, and i bless you for dipping into the noob zone...
  14. Guess I missed explaining something. This is in a file called index.php if you follow the tracing, if it dosen't find a resolution, it reloads the page, with the link being [code]index.php?res=1024x768[/code] or whatever, hopefully passing in the resolution. ... the link looks okay (the resolution is there in the link) but for some reason it isn't being passed into the mysql db.
  15. For some reason this logger isn't working. It correctly logs Time, IP, and Agent, but it almost always refuses to log resolution. (out of like 10 logs, 1 had a resolution.) [code]<?php session_start(); if ($log=="false"){session_register("counted");} if (!session_is_registered("counted")){ if($res==""){ ?>   <script type="text/javascript"><!--   var res = window.screen.width + 'x' + window.screen.height;   location = 'index.php?res=' + res   --></script> <?php } $agent = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $time = date('m/j/y h:i'); $query = "INSERT INTO `log` ( `Time` , `IP` , `Agent` , `Resolution` ) VALUES ( '$time', '$ip', '$agent', '$res');"; mysql_connect("host","user","pass"); mysql_select_db("dbname"); mysql_query($query); mysql_close(); session_register("counted"); } ?> <!-- rest of page here... -->[/code] Tried adding a [code]$res = $_GET['res'];[/code] but it didn't work... Any help would be appreciated, as well as any suggestions for making it a better logger. Thanks. ^^
×
×
  • 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.