Jump to content

Recommended Posts

Can anyone tell me the problem with this code I am a newbie.

<?php

$link=mysql_connect("localhost","root","");

 

if(!$link)

  {die("couldn't connect to database".mysql_error());}

 

mysql_select_db("domains");

  or die("Could not select the database".mysql_error())

 

$result = mysql_query("SELECT * FROM test_acc");

if ( empty($result) )

  die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at  $webmaster_email attaching this error missage.");

 

echo "<table border='2'>";

echo"<tr>

  <th>User ID</th>

</tr>";

 

while( $row = mysql_fetch_array( $result))

{

  echo "<tr><td>";

echo $row['domain'] ;

echo"</td>";

  echo "</tr>";

}

echo "</table>";

?>

Link to comment
https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/
Share on other sites

Is this the whole script you are showing us..

 

 

die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at  $webmaster_email attaching this error missage.");

 

 

I cant see the red vars given any values in your script... maybe why your die message is not showing anything.

Is this the whole script you are showing us..

 

 

die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at  $webmaster_email attaching this error missage.");

 

 

I cant see the red vars given any values in your script... maybe why your die message is not showing anything.

 

If u remove the above script also then also it is not showing any output.

Try this instead and let us know what you get.

 

<?php

  mysql_connect("localhost","root","") of die("couldn't connect to database".mysql_error());
  mysql_select_db("domains") or die("Could not select the database".mysql_error())
    
  $sql = "SELECT * FROM test_acc";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      echo "<table border='2'>";
      echo"<tr><th>User ID</th></tr>";
      while ($row = mysql_fetch_assoc( $result)) {
        echo "<tr><td>";
        echo $row['domain'] ;
        echo"</td>";
        echo "</tr>"; 
      }
      echo "</table>";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />$sql<br />" . mysql_error();
  }

?>

 

ps: This is probably a better example of the logic for a SELECT query.

Which suggests you are not making a connection to the db successfully - try just

 

die("DB ERROR : ".mysql_error();

 

And see if that returns anything of use...

 

Do you have error messages turned on in you php.ini file?

 

check out the error_reporting() function to do something like this

 

// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

 

Just in case it is not set in you PHP.INI

 

HTH

Dave

 

 

Hi

 

you have a syntax error near the beggining to do with the semi-colon

 

<?php
//....
mysql_select_db("domains"); // should not be here
     or die("Could not select the database".mysql_error()) // should be here
    

 

should be

 

<?php
//....
mysql_select_db("domains")
     or die("Could not select the database".mysql_error());
    

 

as php_dave said, turn on error reporting and you will see this

 

cheers,

tdw

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.