View Full Version : aarggghhhh...mysql_connect on F2S is really annoying...help!!
Magic2K2
July 20th, 2001, 21:12
Here is the code, which does not work...all table names, table fields are correct:
$db = mysql_connect("db.hoopsavenue.f2s.com:3306", $username, $password);
mysql_select_db($username, $db);
$sql = "INSERT INTO news (news_headline, news_url, news_story, news_author, news_date, news_time, discuss_link) VALUES ('$news_headline', '$news_url', '$news_story', '$news_author', '$news_date', '$news_time', '')";
mysql_query($sql);
niv
July 21st, 2001, 10:23
try this:
$db = mysql_connect("db.hoopsavenue.f2s.com:3306", $username, $password);
mysql_select_db($username, $db);
$sql = "INSERT INTO news (news_headline, news_url, news_story, news_author, news_date, news_time, discuss_link) VALUES ('$news_headline', '$news_url', '$news_story', '$news_author', '$news_date', '$news_time', '')";
if(mysql_query($sql)) echo "ok";
Magic2K2
July 21st, 2001, 13:54
Okay, I fixed the problem. Here's what happened:
I had been trying to input a news story that was longer than the database space I had allotted. So, I submitted a story just using "test" as the headline and article text and it worked. I was really confused then, but checked the database, and fixed the problem. Thanks for the code you gave, though, that can be very helpful to me on scripts.
niv
July 21st, 2001, 21:11
there's also a "die" feature as in:
$sql = mysql_query("SELECT blah from blah");
$sql2 = mysql_fetch_array($sql)) or die ("mysql query failed");
if mysql_fetch_arrray returns 0 as in a failure, $sql2 will equal mysql query failed and the script will terminate.
Magic2K2
July 21st, 2001, 21:57
My original diagosis was wrong. I discovered the actual problem was that the database field containing the news story couldn't accept a single quotation (or ", \, 0) without an escape character.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.