Jump to content

ok all you experts, this is a wierd one


medaswho

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.