ataria Posted October 11, 2006 Share Posted October 11, 2006 the code is..[code]<?phpinclude ("global.php");$chari = @mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `charid`"));if ($chari == 1) { echo "TEST.";}else {$sql = @mysql_query("INSERT INTO `characters` ( `id`, `username` ) VALUES ('', '{$_COOKIE['uid']}')" );echo "<center><table cellspacing=3 cellpadding=3 width=300><tr><td class=bar colspan=2><center><font class=white><b>Uh-Oh</b></font></center></td></tr><tr><td>You don't have a character! In order to play the site, you need one... so, we gave you one! <br><br><img src=><br><br>This is your <b>one</b> and <b>only</b> character. You will be able to make it go to school and become smarter, get it a job, change it's appearance, and, much more! Remember; treat it as you treat yourself, hence, lay off the drugs...<br><br><br><br><br><br><br><br></td></tr></table></center>";}?><link rel="stylesheet" type="text/css"href="mystyle.css" />[/code]it inserts 2 rows..When i limit it to '1', it doesn't insert a row...help!!!*global connects to the DB. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/ Share on other sites More sharing options...
Jocka Posted October 11, 2006 Share Posted October 11, 2006 well for one you didn't finish your SQL.You have:$chari = @mysql_num_rows(mysql_query([b]"SELECT * FROM `users` WHERE `charid`"[/b]));it should be something like:$chari = @mysql_num_rows(mysql_query([b]"SELECT * FROM users WHERE charid[i]='SOMETHING'[/i]"[/b])); Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107633 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 yeah.but, i just want to retrieve /that/ information.I'm not trying to make it equal anything. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107635 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 i have no idea what you mean about just wanting to retrieve that information. when placing an equal sign in a WHERE clause, you're not assigning charid to a value, you're comparing it to one.[code]SELECT * FROM `users` WHERE `charid`[/code]will do the exact same as[code]SELECT * FROM `users`[/code]because the WHERE clause always evaluates to true.next, get out of the habit of placing @ in front of all of your mysql_ function calls. it suppresses errors that might arise, and errors are key in debugging your scripts. try:[code]$sql = mysql_query("INSERT INTO `characters` ( `id`, `username` ) VALUES ('', '{$_COOKIE['uid']}')" ) or die(mysql_error());[/code]finally, if your `id` column is an auto_increment primary key, you don't need to specify it in INSERT commands since MySQL will define it itself:[code]INSERT INTO `characters` ( `username` ) VALUES ('{$_COOKIE['uid']}')[/code]as for why it's inserting two rows exactly, i don't know. i have a feeling you may be running the page twice somehow, or are mistaken as to it inserting two rows on this page. are you running this query elsewhere? Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107637 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 About the 'where' thing..the charid, is only 0 or 1..so, if it equals 1 it shows test..if it equals 0, it shows the else..it works... (yes, i jsut did a test)--the query is not run elsewhere... =/ Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107640 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 ok, well that explains why the WHERE clause is working then.have you actually attempted my suggestions on the INSERT command (die clause and removing id)? Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107644 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 yeah. I tried it..it still doubles. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107649 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 in that case, perhaps try getting more information on each insert that is happening by inserting runtime information (if your data type will allow it):[code]"INSERT INTO `characters` ( `username` ) VALUES ('{$_SERVER['PHP_SELF']}".time()."')"[/code]look at the rows and check whether the path and the timestamp show up for both, and if so, whether either of the values differ. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107657 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 they don't show up..and, i added ');' to the end to make it work... Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107660 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 what is your PHP code for the INSERT command as it stands right now? Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107662 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 Well... they show a '0'. (your insert) I am gonna try something..here it what i am gonna do.(the site is measured in days...)in the global, i have the time thing which is... [code]$time = time();$day = date("z", $time) -252;[/code]and, i'm gonna make it insert the day... alright.it just inserted the same day. (31) Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107665 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 Wtf. Now it's creating 4.... ugh. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107667 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 Here is the code as it stands right now..[code]<?phpinclude ("global.php");$chari = @mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `charid`"));if ($chari == 1) { echo "TEST.";}else {$sql = mysql_query("INSERT INTO `characters` ( `username` ) VALUES ('{$_SERVER['PHP_SELF']}".time()."')");echo "<center><table cellspacing=3 cellpadding=3 width=300><tr><td class=bar colspan=2><center><font class=white><b>Uh-Oh</b></font></center></td></tr><tr><td>You don't have a character! In order to play the site, you need one... so, we gave you one! <br><br><img src=><br><br>This is your <b>one</b> and <b>only</b> character. You will be able to make it go to school and become smarter, get it a job, change it's appearance, and, much more! Remember; treat it as you treat yourself, hence, lay off the drugs...<br><br><br><br><br><br><br><br></td></tr></table></center>";}?><link rel="stylesheet" type="text/css"href="mystyle.css" />[/code] Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107669 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 first of all, are you getting the "we created one for you" message? second, how are you using this page? does it post to itself, do you run it manually, or what? third, try changing your insert line to the following two lines:[code]$value = 'something@'.time();$sql = mysql_query("INSERT INTO `characters` ( `username` ) VALUES ('$value')") or die(mysql_error());[/code]the problem is likely just something simple that i've missed, but i guess we'll do it the long way. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107671 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 Alright.the page is supposed to be..'If user has a character (charid=1), display the stats. (didn't get that far),else, automatically create one, then change the 'charid to 1', (didn't get that far, b//c it would be annoying to have to keep changing the charid to '0' to do tests)..and, since the character won't create properly, it's messing me up... big time. ----I changed it to the code you just posted, and, it didn't even create a row. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107674 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 alright, try this:[code]$sql = mysql_query("INSERT INTO `characters` ( `username` ) VALUES ('{$_COOKIE['uid']}')") or die(mysql_error());exit(mysql_affected_rows());[/code]we'll tackle your check to see if the charid is there or not after we've sussed this multiple insertion out. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107678 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 WOW. It only did one row.. but, it made the page go white :( Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107679 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 that's what it's meant to do - it is supposed to exit immediately after the query is run, echoing how many rows were inserted. did you see a '1' in the browser (probably the only thing on the page)?now try changing the exit(mysql_affected_rows()) to:[code]echo 'rows inserted so far: '.mysql_affected_rows().'<br>';[/code]see if you get multiple lines saying "rows inserted so far". Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107681 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 It shows..."rows inserted so far: 1"then my crap on the page.any way to hide that? Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107682 Share on other sites More sharing options...
ataria Posted October 11, 2006 Author Share Posted October 11, 2006 ugh. It is still inserting 2 rows.... Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107685 Share on other sites More sharing options...
akitchin Posted October 11, 2006 Share Posted October 11, 2006 if it is still inserting two rows, but only echoes "rows inserted so far: 1" once, you are running the query somewhere else on the page. let's see the entire page.to get rid of it saying "rows inserted so far: 1", just remove the echo line beneath the INSERT statement. Link to comment https://forums.phpfreaks.com/topic/23708-making-it-only-make-1-row-in-the-database/#findComment-107687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.