Solved

PHP MySQL SQLi at Go Daddy 2011

Posted on 2011-09-08
19
818 Views
Last Modified: 2013-12-13
The code below works well, thanks to Experts-Exchange, on my PC but not at Go Daddy.  I created a new DB  at Go Daddy, checked it but this code does not work on my site.  
What do I need to do to correct his problem? (passwords and hosts have been changed
for security reasons in this code below)

 function fnAddRecSeletRecs($hostName1, $userName3, $password3, $databaseName3 ) {
            // Add one record and display all records in the Prospect table.
            
      try {
            $conn1 = new mysqli($hostName1, $userName3, $password3, $databaseName3) ;
      /* check connection */
      if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
             
            exit(); // <==///========
            }
      echo ' database ' . $databaseName3 . ' is now connected to program. ' ;
        
      // Create SQL code to insert a record into the Prospect table.
      $SQL1 = "INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) ";
      $SQL1 .= " VALUES('N', 'Y', 'John', 'Hammer', 'John@HammondTrees.com', 'Test only in 2011' )";
                
      $conn1->query($SQL1); // run the query
      printf (" |  New Record has id %d.\n", $conn1->insert_id);
      echo ' \  Prospect table ' ;
      // this works OK
            
      // use a Select to show current records
      $SQL2 = "SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile " ;
      $SQL2 .= " FROM Prospect " ;
      $result2 = $conn1->query($SQL2) ;
      $K1 = 0 ;

      while($row22 = $result2->fetch_array(MYSQLI_ASSOC)) {
            $K1 = $K1 + 1 ;
      echo $K1 . "  ";      
      echo "CustomerYN = ".$row22["CustomerYN"].", ActiveYN = ".$row22["ActiveYN"].", ";
      echo "FirstName = ".$row22["FirstName"].", LastName = ".$row22["LastName"].", ";
      echo "EmailMain = ".$row22["EmailMain"].", CoProfile = ".$row22["CoProfile"]."<br>";
      } // == end of while
      
      /* close connection */
      $conn1->close();
      return true ; // <===///==========
 } // === end of try

 catch ( Exception $e1) {
      echo "  error in database and table operations-- " . $e1 . " | " ;
                return false ; // <===///==========
  }
 } // === end of function ======================
      
      
    try
    {
    // Create DB connection to MySQL DB in MySQLi'
    $hostName1 = "localhost";
    $userName1 = "root";
    $password1 = "kxxx";
   
    $hostName2 =  "mktgdb.db.12345.hostedresource.com"; // host at GoDaddy
    // $userName2 = "Saaaaa"; // for Local DB on Dell 460
      $userName2 = "mktgdb";
    $password2 = "kxxxx";
    $databaseName1 = "mktgdb";
          $completedTF1 = false;
   
    $completedTF1 = fnAddRecSeletRecs($hostName2, $userName2, $password2, $databaseName1) ;// <---
    if ($completedTF1 = true) {
            echo " | function completed OK. | " ;
    }    
   
    } // == end of try
   
    catch ( Exception $e1)   {
          echo " Error in database operation.  Error:  " . $e1 . " | " ;
    } // === end of catch ==========
   
    ?>
    </p>

The error msg in Firefox follows:  Fatal error: Call to a member function fetch_array() on a non-object in D:\Hosting\7296466\html\Database-ops.php on line 119
0
Comment
Question by:KennethSumerford1
  • 13
  • 4
  • 2
19 Comments
 
LVL 3

Assisted Solution

by:evedder
evedder earned 150 total points
ID: 36505716
it seems your query is not returning data, can you check your table to see if you have rows there? depending on that could be a problem on the query or in the insert
0
 

Author Comment

by:KennethSumerford1
ID: 36506110
There is data in the table.  I checked it with PhpMyAdmin at Go Daddy yesterday.
0
 

Author Comment

by:KennethSumerford1
ID: 36507704
I tried SQL instead of SQLi and it did Not work either.

function fnAddRecSeletRecs($hostName1, $userName3, $password3, $databaseName3 ) {
            // Add one record and display all records in the Prospect table.
            // Use SQL instead of SQLi at Go Daddy.
            
      try {
            //  $conn1 = new mysqli($hostName1, $userName3, $password3, $databaseName3) ;
      $conn1 =  mysql_connect($hostName1, $userName3, $password3) ;      
      /* check connection */
      /* if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());            
            exit(); // <==///========
            } */
      // select the DB
      mysql_select_db( $databaseName3, $conn1 ) ;      
      echo ' database ' . $databaseName3 . ' is now connected to program. ' ;
        
      // Create SQL code to insert a record into the Prospect table.
      // example of protecting entry from a Form
      $firstName1 = "Duke";
      $firstName1 = trim( strip_tags($firstName1));
      $firstName1 = mysql_real_escape_string($firstName1, $conn1);
      
      $SQL1 = "INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) ";
      $SQL1 .= " VALUES('N', 'Y', '" . $firstName1 . "', 'Stout', 'S@HammondTrees.com', 'Test only in 2011' )";
      print " query 1 = " . $SQL1 . "  | ";
                
      // $conn1->query($SQL1); // run the query
      mysql_query($SQL1, $conn1);
      // printf (" |  New Record has id %d.\n", $conn1->insert_id);
      echo ' \  Prospect table ' ;
      // this works OK
            
      // use a Select to show current records
      $SQL2 = "SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile " ;
      $SQL2 .= " FROM Prospect " ;
       print " query 2 = " . $SQL2 . "  | ";
      // $result2 = $conn1->query($SQL2) ;
      $r1 = mysql_query($SQL2, $conn1) ;
      $K1 = 0 ;

      while ($row = mysql_fetch_array($r1)) {
            print "<p> " . $row[''] . " ";
            print $row['CustomerYN'] . " ";
            print $row['ActiveYN'] . " ";
            print $row['FirstName'] . " ";
            print $row['LastName'] . " ";
            print $row['EmailMain'] . " -----CoProfile:  ";
            print $row['CoProfile'] . " ";
            // print $row[''] . " ";
             print "</p> \n" ;
      }
      
      /* close connection */
      // $conn1->close();
      mysql_close($conn1);
      return true ; // <===///==========
 } // === end of try

The SQL queries and error is below.

query 1 = INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) VALUES('N', 'Y', 'Duke', 'Hammer', 'John@HammondTrees.com', 'Test only in 2011' ) | \ Prospect table query 2 = SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile FROM Prospect |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7296466\html\Database-ops-SQL.php on line 132

Here is line 132:
while ($row = mysql_fetch_array($r1)) {
 
0
 
LVL 2

Expert Comment

by:team2005
ID: 36510311
Hi!

Do you get any error message ?
0
 
LVL 2

Expert Comment

by:team2005
ID: 36510346
Hi!

Try this

while ($row[] = mysql_fetch_array($r1)) {

0
 

Author Comment

by:KennethSumerford1
ID: 36512165
I tried it and below is what I got, including the SQL and the error msg.

database mktgdb is now connected to program. query 1 = INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) VALUES('N', 'Y', 'Duke', 'Stout', 'S@HammondTrees.com', 'Test only in 2011' ) | \ Prospect table query 2 = SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile FROM Prospect |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7296466\html\Database-ops-SQL.php on line 133
0
 

Author Comment

by:KennethSumerford1
ID: 36512230
I need to check with Go Daddy about the Username and password.  There could be a problem with how they want to see a few items.  I will also check about the Host name being in the correct format.
0
 

Author Comment

by:KennethSumerford1
ID: 36514096
I talked to Go Daddy and things seem to be OK.  I even created a new DB and get the same error msg below.

 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7296466\html\Database-ops-SQL.php on line 132

Here is the code that I tried:
  while ($row = mysql_fetch_array($r1)) {
and also--
  while ($row[] = mysql_fetch_array($r1)) {
0
 

Author Comment

by:KennethSumerford1
ID: 36514183
Below is some code and print from the PHP page.

// use a Select to show current records
      $SQL2 = "SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile " ;
      $SQL2 .= " FROM Prospect " ;
       print " query 2 = " . $SQL2 . "  | ";
      // $result2 = $conn1->query($SQL2) ;
      $r1 = mysql_query($SQL2) ;
      $K1 = 0 ;

      if ($r1) {
            while ($row = mysql_fetch_array($r1)) {
            // while ($row[] = mysql_fetch_array($r1)) {
                  print "<p> " . $row[''] . " ";
                  print $row['CustomerYN'] . " ";
                  print $row['ActiveYN'] . " ";
                  print $row['FirstName'] . " ";
                  print $row['LastName'] . " ";
                  print $row['EmailMain'] . " -----CoProfile:  ";
                  print $row['CoProfile'] . " ";
                  // print $row[''] . " ";
                   print "</p>  " ;
            }
      }
      else {
            echo " |  ==result== did Not work for mysql_query() | ";
      }

  =======
 
database mktgdb2 is now connected to program. query 1 = INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) VALUES('N', 'Y', 'Duke', 'Stout', 'S@HammondTrees.com', 'Test only in 2011' ) | \ Prospect table query 2 = SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile FROM Prospect |

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7296466\html\Database-ops-SQL.php on line 132
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:KennethSumerford1
ID: 36514222
Here is the new print from the Web page.

database mktgdb2 is now connected to program. query 1 = INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) VALUES('N', 'Y', 'Duke', 'Stout', 'S@HammondTrees.com', 'Test only in 2011' ) | \ Prospect table query 2 = SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile FROM Prospect |

| ==result== did Not work for mysql_query() | | function completed OK. |

So the problem is probably here:

// $conn1->query($SQL1); // run the query
      mysql_query($SQL1, $conn1);
      // printf (" |  New Record has id %d.\n", $conn1->insert_id);
      echo ' \  Prospect table ' ;
      
            
      // use a Select to show current records
      $SQL2 = "SELECT CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile " ;
      $SQL2 .= " FROM Prospect " ;
       print " query 2 = " . $SQL2 . "  | ";
      // $result2 = $conn1->query($SQL2) ;
      $r1 = mysql_query($SQL2) ;
0
 

Author Comment

by:KennethSumerford1
ID: 36514250
Is any body there?
0
 
LVL 3

Assisted Solution

by:evedder
evedder earned 150 total points
ID: 36514705
your code looks right, can you try your select like SELECT * FROM Prospect, just to be sure there's no error in how you are naming the columns in the instruction?

:S
0
 

Author Comment

by:KennethSumerford1
ID: 36515072
I will try Select * .
0
 

Author Comment

by:KennethSumerford1
ID: 36515079
Below is the new result, which is not correct.

database mktgdb2 is now connected to program. query 1 = INSERT INTO Prospect (CustomerYN, ActiveYN, FirstName, LastName, EmailMain, CoProfile) VALUES('N', 'Y', 'Duke', 'Stout', 'S@HammondTrees.com', 'Test only in 2011' ) | \ Prospect table
query 2 = SELECT * FROM Prospect |  
| ==result r1== did Not work for mysql_query() | | function completed OK. |
0
 

Author Comment

by:KennethSumerford1
ID: 36515116
It is 11 PM here in Texas.  I will work on this problem tomorrow around 2 PM.
0
 
LVL 2

Assisted Solution

by:team2005
team2005 earned 50 total points
ID: 36515822
Hi!

Change this line:
  $r1 = mysql_query($SQL2) ;

To

 $r1 = mysql_query($SQL2)  or die(mysql_error());

This wil print out what error in mysql you have.

 
0
 

Accepted Solution

by:
KennethSumerford1 earned 0 total points
ID: 36516975
OK, I called Go Daddy and I figured out the problem.

The task is now finished.
0
 

Author Closing Comment

by:KennethSumerford1
ID: 36541412
Go Daddy and MySQL have some peculiar ways it seems, but it could be my lack of understanding of MySQL.
0
 
LVL 2

Expert Comment

by:team2005
ID: 36517025
Hi!

Happy that you solve the problem :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now