help with php mysql connection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sublevel4
Forum Commoner
Posts: 33
Joined: Wed May 29, 2002 2:14 pm
Contact:

help with php mysql connection

Post by sublevel4 »

I am having a problem with the following code. I am moving servers and it worked on the old one but dies on the new one. Anyone have any ideas as to why this might be?

Code: Select all

if ($username != ""){
	if ($username == "xxx" && $password == "xxx"){
		
		mysql_pconnect ("localhost", "username", "password");
		mysql_select_db ("database");
		
		$query = "INSERT  INTO blog_entries (date,title,entry) VALUES (NOW(), '" . $title . "', '" . $entry . "')";
		$result = mysql_query($query) or die("query failure  ----- $query");
		$status = "Entry has been made";
	}else{
		$status = "Entry has failed";
	}
}
Last edited by sublevel4 on Wed Feb 07, 2007 8:28 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
I would bet that register_globals is turned off (and rightly so) on the "new" server.
sublevel4
Forum Commoner
Posts: 33
Joined: Wed May 29, 2002 2:14 pm
Contact:

Post by sublevel4 »

You are correct i should have been more clear.

the code in the page

Code: Select all

<?php

$status = "";
$username = $_POST['username'];
$password = $_POST['password'];
$title = $_POST['title'];
$entry = $_POST['entry'];

if ($username != ""){
	if ($username == "xxx" && $password == "xxx"){
		
		mysql_pconnect ("localhost", "username", "pw");
		mysql_select_db ("database");
		
		$query = "INSERT  INTO blog_entries (date,title,entry) VALUES (NOW(), '" . $title . "', '" . $entry . "')";
		$result = mysql_query($query) or die("query failure  ----- $query");
		$status = "Entry has been made";
	}else{
		$status = "Entry has failed";
	}
}
?>

the resulting page is

query failure ----- INSERT INTO blog_entries (date,title,entry) VALUES (NOW(), 'new server', 'this is a test of the new server. this is only a test')

so i am getting the variables from the form it is just not working.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Without seeing the output from mysql_error() I would have to guess that "date" is being rejected as it is a reserved word. It is recommended to never use reserved words for column, table or database names.

http://dev.mysql.com/doc/refman/5.1/en/ ... words.html
sublevel4
Forum Commoner
Posts: 33
Joined: Wed May 29, 2002 2:14 pm
Contact:

Post by sublevel4 »

Feyd, i appoligize. I am a moron. I had two letters in the database name transposed. I have not coded is so long i am making stupid mistakes.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sublevel4 wrote:Feyd, i appoligize. I am a moron. I had two letters in the database name transposed. I have not coded is so long i am making stupid mistakes.
Forty lashes for sublevel4!

Imagesublevel4Image
Post Reply