medaswho Posted February 17, 2009 Share Posted February 17, 2009 in my app, i have a page that inserts rows into mysql db, and then i have been trying to make the page(s) that will retrieve. but so far my efforts at retrieval have fallen short. after lots of testing i realized that the rows i put in directly using phpMyAdmin come out in the retrieval scripts just fine, but the rows i have added to the db programmatically do not do what is expected of them. y'all still with me? LOL i have tried my insert code two ways and niehter way works. here is the code: first try: mysql_connect($host,$user,$password); mysql_select_db($dbname); $add_member = "INSERT INTO members(screenname,pass_word,date_created,member_firstname, member_lastname, genre, is_group, stage_name, my_email) VALUES(' ".$_POST["user_name"]." ', ' ".$_POST["password"]." ', now(), ' ".$_POST["first_name"]." ', ' ".$_POST["last_name"]." ', ' ".$_POST["genre"]." ', ' ".$_POST["group"]." ', ' ".$_POST["stage_name"]." ', ' ".$_POST["email"]." ')"; $result = mysql_query($add_member); // try number two i added code to escape to real characters: mysql_connect($host,$user,$password); mysql_select_db($dbname); $add_member = "INSERT INTO members(screenname,pass_word,date_created,member_firstname, member_lastname, genre, is_group, stage_name, my_email) VALUES(' ".mysql_real_escape_string($_POST["user_name"])." ', ' ".mysql_real_escape_string($_POST["password"])." ', now(), ' ".mysql_real_escape_string($_POST["first_name"])." ', ' ".mysql_real_escape_string($_POST["last_name"])." ', ' ".mysql_real_escape_string($_POST["genre"])." ', ' ".mysql_real_escape_string($_POST["group"])." ', ' ".mysql_real_escape_string($_POST["stage_name"])." ', ' ".mysql_real_escape_string($_POST["email"])." ')"; $result = mysql_query($add_member); ...now the thing is that they both work to add rows, but either way i can't get correct results from the db with my other code. Quote Link to comment Share on other sites More sharing options...
Brian W Posted February 17, 2009 Share Posted February 17, 2009 you'll get more expert replies if you use code tags around your code [ code ]code[ /code ] without spaces in code tags code Quote Link to comment Share on other sites More sharing options...
Cal Posted February 17, 2009 Share Posted February 17, 2009 you say they both add rows but they're not right when you print them? show me the code that shows the rows, that might be the problem Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 17, 2009 Share Posted February 17, 2009 Is there a reason for $result, in this INSERT statement? You shouldn't be getting anything back, as you would with a SELECT statement. Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted February 17, 2009 Share Posted February 17, 2009 Most people just use the result to check for success or not. At least from what I have seen. Quote Link to comment Share on other sites More sharing options...
Cal Posted February 17, 2009 Share Posted February 17, 2009 Yeah as I remember it returns a true of false (1 or 0) Quote Link to comment Share on other sites More sharing options...
medaswho Posted February 17, 2009 Author Share Posted February 17, 2009 for those who asked, the result() in the above code goes on and does something else in the app...i guess i just coppied and pasted too much, didn't think it would cause confusion...and as for Cal's question...here it is $result = mysql_query("SELECT * FROM members WHERE screenname = '".$sname."'") or die(mysql_error()); if($result) { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $pass_check = $row['pass_word']; $sname_check = $row['screenname']; echo $pass_check."<br>"; echo $sname_check."<br>"; } } and nothing prints if its one that i added programmatically, but if i add a row right in phpMyAdmin , the echo prints something. Quote Link to comment Share on other sites More sharing options...
samshel Posted February 17, 2009 Share Posted February 17, 2009 do u see the rows added programatically in phpmyadmin ? also try $result = mysql_query($add_member) or die(mysql_error()); //easiest way to debug db transactions....mysql_error() echo mysql_insert_id(); // this shows auto increment id of record inserted, if this comes properly, record is inserted ok. Quote Link to comment Share on other sites More sharing options...
Cal Posted February 17, 2009 Share Posted February 17, 2009 Ok then maybe it's the form that sends the data to the script? Quote Link to comment Share on other sites More sharing options...
medaswho Posted February 17, 2009 Author Share Posted February 17, 2009 sends to the insert script or the retrieval script? Quote Link to comment Share on other sites More sharing options...
Cal Posted February 17, 2009 Share Posted February 17, 2009 insert script Quote Link to comment Share on other sites More sharing options...
medaswho Posted February 18, 2009 Author Share Posted February 18, 2009 but i posted the insert script.!! what do YOU see wrong with it? is there some sort of "type" identifier for storing data i don't know about or what? Quote Link to comment Share on other sites More sharing options...
shlumph Posted February 18, 2009 Share Posted February 18, 2009 Try this and tell us what you get for an error: <?php $conn = mysql_connect($host,$user,$password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $add_member = "INSERT INTO members(screenname,pass_word,date_created,member_firstname, member_lastname, genre, is_group, stage_name, my_email) VALUES(' ".mysql_real_escape_string($_POST["user_name"])." ', ' ".mysql_real_escape_string($_POST["password"])." ', now(), ' ".mysql_real_escape_string($_POST["first_name"])." ', ' ".mysql_real_escape_string($_POST["last_name"])." ', ' ".mysql_real_escape_string($_POST["genre"])." ', ' ".mysql_real_escape_string($_POST["group"])." ', ' ".mysql_real_escape_string($_POST["stage_name"])." ', ' ".mysql_real_escape_string($_POST["email"])." ')"; mysql_query($add_member, $conn) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.