my web site is http://gamewars.x10hosting.com/ click xbox button and post wars button and enter in any old info and you will see what is going wrong. Basically im getting an error and im not entering my data base name i guess correctly. plz help
my web site is http://gamewars.x10hosting.com/ click xbox button and post wars button and enter in any old info and you will see what is going wrong. Basically im getting an error and im not entering my data base name i guess correctly. plz help
You have to post all your PHP code related to the error (omitting the SQL user/pass) for us to help you![]()
Not so much all the related code as a minimal test case, along with other pertinent and relevant information, such as the behavior you expect and the behavior you get, including error messages. Don't make us do extra work.
Remember to search the forums and the web at large before posting. If you're dealing with an error message, it makes searching particularly easy.
Last edited by misson; 08-10-2009 at 03:07 AM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
i have searched all over the internet but this problem is not going to be solved by searching the internet i dont know how to enter my database name username and password on my php code but heres the code
<?php
$con = mysql_connect("gamewars_xbox360postedwars","gamewa rs_gamewars","xxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (Game, Gamertag, Time and Date, Number of rounds, Number of players)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[quantity]','$_POST[items]','$_POST[players]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
Last edited by gamewars; 08-10-2009 at 04:27 PM.
Code:$con = mysql_connect( 'localhost', 'gamewars_gamewars' , 'yoursecretpasswd'); mysql_select_db("my_db");
The first term is the location of the mysql server. In your case, it is probably 'localhost'.
If you posted your real password, please change it.
Finally, look at the mysqli interface
Last edited by descalzo; 08-10-2009 at 02:12 PM.
Nothing is always absolutely so.
Whatever ancient tutorials keep screwing up people's code with terrible examples need to be hunted down and shot.
You neglected to post the error. Here it is, for people searching for this error in the future:
You really shouldn't make us wait for the connection to time out to get the error when you could have easily posted it yourself.Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'gamewars_xbox360postedwars' (4) in /home/gamewars/public_html/postwarsxbox360.php on line 2
Could not connect: Can't connect to MySQL server on 'gamewars_xbox360postedwars' (4)
The server name (the first argument to mysql_connect) should be "localhost". "gamewars_xbox360postedwars" looks like the DB name. Rather than looking at the documentation for mysql_connect, instead use PDO (PHP Data Objects). The mysql driver was been succeeded by mysqli, which has been succeeded in turn by PDO.
Your script is also vulnerable to SQL injection ([2], [3]). Prepared statements (available with PDO and mysqli) mean you don't need to worry about sanitizing.
If you have spaces in a column name, you need to enclose it in backquotes ("`"), otherwise the query will fail with an SQL syntax error.
Don't use die in production code.
Move the DB connection code to another script to isolate the user credentials and prevent typos from causing problems.
PHP Code:# localDB.php defines local_db_connect
include_once('localDB.php')
# the following should be abstracted away into classes
$fields=array_intersect(
array('firstname' => 'Game', 'lastname' => 'Gamertag',
'quantity' => 'Time and Date',
'items' => 'Number of rounds', 'players' => 'Number of players'),
$_POST
);
# define 'validate()' elsewhere and fill out function call here.
$errors = validate($_POST, ...);
if (count($errors)) {
foreach ($errors as $name => $msg) {
# reprint the form, with error messages inlined.
}
} else {
# this code in particular should be refactored into classes
try {
$db = local_db_connect('pdo', array('db' => 'gamewars_xbox360postedwars'));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Note: the following four lines could be done in one, but have been separated
# for readability.
$columnClause = '`' . implode('`, `', $fields) . '`';
$valueClause = ':' . implode(', :', array_keys($fields)) ;
$query = "INSERT INTO Players ($columnClause) VALUES ($valueClause)";
$stmt = $db->prepare($query);
$stmt->execute($_POST);
} catch (PDOException $pdoe) {
# error reporting should be abstracted away into a function or class
$errorMsg = __FILE__ . '@' . __LINE__ . ':' . $pdoe->getMessage();
error_log($errorMsg);
# note: $siteAdmin and $from need to be set somewhere, a strong argument for a class.
mail($siteAdmin, $from, "Script error on $_SERVER[SERVER_NAME]",$errorMsg);
echo "Internal error. It's been logged, ";
}
}
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.