Jump to content

Recommended Posts

Posted

I really appreciate the patience everyone here has for us beginners.

 

I'm getting closer, I think. I can connect using the script below.

 

<?php

$DBHOST = "localhost";

$DBUSER = "sales_bob";

$DBPASS = "abcd";

$DBNAME = "sales_newdatabase";

echo("work");

//

// lets show any errors we get in PHP

//

 

ini_set ('display_errors', 1);

error_reporting (E_ALL & ~E_NOTICE);

 

//

// Now we connect to the MySQL server and select the database

//

 

if ($dbc = @mysql_connect ($DBHOST, $DBUSER , $DBPASS ))

{

if (!@mysql_select_db ($DBNAME))

{

die ('<p>Could not select the database because: <b>'.mysql_error().'</b></p>');

}

}

else

{

die ('<p>Could not connect to MySQL because: <b>'.mysql_error().'</b></p>');

}

 

echo ("<h4>Successfully connected to your MySQL server and database</h4>");

?>

 

But the next script gives me a blank screen when I run it.

Not even the echo("test "); prints.

 

<?php

$dbhost = "localhost";

$dbuser = "sales_bob";

$dbpass = "abcd";

$dbname = "sales_newdatabase";

$dbtable = "feedback";

echo("test ");

 

 

$conn = mysql_connect"($dbhost,$dbuser,$dbpass);

mysql_select_db($dbname);

$sql = "select * from $dbtable";

$result = mysql_query($sql,$conn);

$number_of_rows = mysql_numrows($result);

echo "the number of rows is $number_of_rows";

?>

 

No errors are listed or anything for that matter. Just a blank screen.

Through the Cpanel tools I have the DB and Table and sample data.

What am I missing?

I am trying to get the hang of mysql/php one step at a time.

Is there something I need to configure at the php/mysql admin level?

 

Thanks again

Posted

I'll take a stab at this.

 

1) You created the database through cPanel

2) You created a user for the database

3) You added the user to the database

 

To access this database the variables should be as follows.

 

The DBNAME will be yourcpanelname_databasename-you-created

The DBUSER will be yourcpanelname_username-you-created

The DBPASS will be password-you-created

The HOST will be localhost

 

Hope that hepls

Posted

If the second script does not output the word 'test'

 

then I have to ask:

 

did you upload the file as text?

does it have the extension of .php?

what text editor are you using?

Did you save it some where in or below your public_html folder?

 

I know you probably did all this, but we have to start some where.

Posted
$conn = mysql_connect"($dbhost,$dbuser,$dbpass);

mysql_select_db($dbname);

 

Try taking out the quotation mark in the first line I quoted; it shouldn't be there.

 

In the second line, I have found that I sometimes have to assign it to a variable:

 

$db1 = mysql_select_db($dbname);

 

I don't know why, but every once in a while a script gets picky on me. See if it works after taking out that quotation mark, though.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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