Improve company productivity with a Business Account.Sign Up

x
?
Solved

PHP MySQL SQLi at Go Daddy 2011

Posted on 2011-09-08
19
Medium Priority
?
910 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 600 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
 

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 600 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article, we’ll look at how to deploy ProxySQL.
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

588 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