PDA

View Full Version : Help with simple php script


ferrarispider95
10-26-2005, 04:24 PM
Whats wrong with this simple php code. I have not coded much in php mysql, but working a script that I am going to run as a cron job.

When I navigate to the script it does nothing. My configure is setup correctly, because other parts of the site can connect, it just doesnt do anything. I check table names, field names, everything is correct. What I am missing. Here is the entire file.


Do I need something to start the script or what, because it is not doing anything, no errors either.,


<?php




// Include configure file for mysql info
require('includes/configure.php');


//connect to database

function connect_to_db() {
mysql_connect(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD)
or die("Can't connect to server");
mysql_select_db(DB_DATABASE)
or die("Can't open database");
$sql="UPDATE `orders` SET `cc_number`='1' WHERE `orders_status`= '3');";
mysql_query($sql) or die(mysql_error());


}
?>

Traveller
10-27-2005, 06:45 PM
I'm assuming that your variables: DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD are defined in your included file. They are not in scope within the function.

Use the global command like:

global DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD;

to place the vars in scope.

do you have access to the MyPHPAdmin? Does you're SQL statement work?

I'd try the variable scope first.