Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL won't connect for any apparent reason. 2

Status
Not open for further replies.

Zilch

Programmer
Nov 24, 2003
10
0
0
US
Okay, I've checked, re-checked, and looked over my code what feels like a few hundred times now. I know it's connecting to the Database, but it won't add information!

Anyways, here's my code:

$sql = "INSERT INTO pm (from,to,subject,message,date) VALUES ('$from','$to','$subject','$message','$date')";
$result = mysql_query($sql,$conn) or die ("Couldn't connect to send information.");

I have defined all the variables, no idea why it's not working.
 
have u printed this query on browser? what error dose it give ?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I get the error "Couldn't connect to send information."

If you'd like the rest of the code sorrounding that bit, please tell me.
 
and the query looks alright ?
what if you cut and paste the query thru mysql command prompt..?does it work ?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
try this:

$result = mysql_query($sql,$conn) or die (&quot;Couldn't connect to send information.!<br>Reason: &quot; . mysql_error()));

That will tell you the exact problem.

Hope it helps

Skute

&quot;There are 10 types of people in this World, those that understand binary, and those that don't!&quot;
 
General observation:

Stay away from reserved words in MySQL. Don't name databases, tables, columns using reserved words. Although you can enclose them in backticks abstinence is best.

You have a column 'from'. I'd rename that to something else. Just imagine this query:
&quot;SELECT FROM myTable WHERE from =.....&quot;
 
Okay, thank you everyone. The problem was the fact that I was using to and from, I changed them, and everything worked fine... just a few bugs I still need to work out though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top