Jump to content

Recommended Posts

my problem is that when i upload any php to my server it doesn't work, with this simple test code it comes out blank on the page when i upload it to the server maybe it's my login information that's wrong or maybe the code or maybe i'm putting the code in the wrong location when i upload it. or maybe my database is wrong. any help will be appreciated

 

i have two bits of code one called dbconncect.php

 

dbtest.php

<?php
   DEFINE ('HOST', 'jasongold.org');
   DEFINE ('USER', 'user');
   DEFINE ('PASS', 'example');
   DEFINE ('MYDB', 'jason_gold');
?>

 

and another one just a test

 

dbconnect.php

<?php
   require_once('../../dbconnect.php');
    error_reporting(E_ALL);
   $dbc = mysql_connect(HOST, USER, PASS) OR die("Unable to connect to database: " . mysql_error());
   mysql_select_db(MYDB) OR die("Unable to select database: " . mysql_error($dbc))
  
   $query = "INSERT INTO jason_gold (name, email_address) VALUES ('Kevin', 'kevin@gmail.com')";
   $result = mysql_query($query);

   if(mysql_affected_rows() == 1)
   {
      echo "Insert successful!";
   }
   else
   {
      echo "Something went wrong!";
   }
?>

 

image of database

800515_database.JPG

Link to comment
https://forums.phpfreaks.com/topic/126994-uploading-to-a-server/
Share on other sites

Try:

 

<?php
   error_reporting(E_ALL);
   require_once('../../dbconnect.php');
   $dbc = mysql_connect(HOST, USER, PASS) OR die("Unable to connect to database: " . mysql_error());
   mysql_select_db(MYDB) OR die("Unable to select database: " . mysql_error($dbc))
  
   $query = "INSERT INTO jason_gold (name, email_address) VALUES ('Kevin', 'kevin@gmail.com')";
   $result = mysql_query($query);

   if(mysql_affected_rows() == 1)
   {
      echo "Insert successful!";
   }
   else
   {
      echo "Something went wrong!";
   }
?>

still getting a blank screen, when i type in a filename i haven't uploaded i get the message

 

Not Found

 

The requested URL /fthth.php was not found on this server.

 

which means it must recognise it at it comes up blank?

 

also when i type in another bit of php i've done i get the message

 

Database connection failed: Access denied for user 'root'@'localhost' (using password: YES)

 

so again it recognises it but doesn't work either

Put both of the following lines immediately after your first <?php tag (display_errors is probably and should be OFF on a live server) -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Also, have you tested this code first on a local development system so that you know it is free of parse errors?

i hadn't actually tested it on a local server yet which was silly.

 

i got this error for it

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\test\dbtest.php on line 7

 

i had also changed my code back to how it was originally so this is what it was, i think the error message has something to do with my database.

<?php
   require_once('../../dbconnect.php');

   $dbc = mysql_connect(HOST, USER, PASS) OR die("Unable to connect to database: " . mysql_error());
   mysql_select_db(MYDB) OR die("Unable to select database: " . mysql_error($dbc))
   
   $query = "INSERT INTO jason_gold (name, email_address) VALUES ('Kevin', 'kevin@gmail.com')";
   $result = mysql_query($query);

   if(mysql_affected_rows() == 1)
   {
      echo "Insert successful!";
   }
   else
   {
      echo "Something went wrong!";
   }
?>

i now get this error

 

 

Warning: require_once(../../dbconnect.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\test\dbtest.php on line 2

 

Fatal error: require_once() [function.require]: Failed opening required '../../dbconnect.php' (include_path='.;C:\php5\pear') in C:\wamp\www\test\dbtest.php on line 2

 

is it saying the dbconnect file doesn't exsist?

i'm now using a different bit of code to upload and i get this message

 

Database selection failed: Unknown database 'widget_corp'

 

i know the database definately exsists because i used it on the local machine and it worked fine but when i upload it to the server it says it doesn't recognise it.

 

www.jasongold.org/index.php

still can't get it to work the error message being

 

Database selection failed: Unknown database ' widget_corp'

 

the database definately exsists

 

here's the code

 

constants.php

<?php

// Database Constants
define("DB_SERVER", 'localhost');
define("DB_USER", 'root);
define("DB_PASS", 'example');
define("DB_NAME", 'widget_corp');

?>

 

connection.php

<?php
require("constants.php");

// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}

// 2. Select a database to use 
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
?>

 

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.