4 Replies - 1166 Views - Last Post: 24 July 2002 - 08:03 PM Rate Topic: -----

#1 Dr. Tim  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 993
  • Joined: 20-March 02

Mysql Errors

Posted 24 July 2002 - 07:24 AM

This is a strange scenario. Look at the code below.
<?
$conn = mysql_connect("mysql.guardianhosting.net", "coconuttim", "s*******");
$selected = mysql_select_db("articles", $conn);
$sql = "SELECT author FROM newmovies";
$result = mysql_query($sql, $conn);
if ($result) {
$title = mysql_result($result, 1, 'author');
$movie = mysql_result($result, 1, 'movie');
$datetime = mysql_result($result, 1, 'datetime');
$body = mysql_result($result, 1, 'body');
$rating = mysql_result($result, 1, 'rating');
echo ("Author : $title");
echo ("Movie : $movie<BR>");
echo ("Date : $datetime<BR>");
echo ("Body : $body<BR>");
echo ("Rating : $rating<BR>");
} else {
echo ("Query failed: $sql.");
}
?>


Now click here. It comes up with :\

Is This A Good Question/Topic? 0
  • +

Replies To: Mysql Errors

#2 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Mysql Errors

Posted 24 July 2002 - 08:01 AM

ok buddy, you've got some serious problems with what you're doing...

you never want this
$conn = mysql_connect("mysql.guardianhosting.net", "coconuttim", "********");
$selected = mysql_select_db("articles", $conn);


in your main file, people can hack that, you're now gonna have to change your password/username

you should make a config file, in a config folder with a .htaccess file that will deny access to anyone trying to get into that folder

ok, now for your select statement

$sql_result = mysql_query(" SELECT * FROM newmovies")
	or die("Couldn't execute query to get info from newmovies table.");
$row = mysql_fetch_array($sql_result);
extract($row);



extract($row) will put everything in the table into proper variables according to whatever you named them in the table, doing that eliminates the need for all this:
$title = mysql_result($result, 1, 'author');
$movie = mysql_result($result, 1, 'movie');
$datetime = mysql_result($result, 1, 'datetime');
$body = mysql_result($result, 1, 'body');
$rating = mysql_result($result, 1, 'rating');



i hope this helps you in some way.
Was This Post Helpful? 0
  • +
  • -

#3 Dr. Tim  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 993
  • Joined: 20-March 02

Re: Mysql Errors

Posted 24 July 2002 - 09:16 AM

CALLING ALL ADMINS!!! FYRESTORM NEEDS CONTRIBUTION POINTS! THAT WAS A BIG OLE HELP! PLEASE REWARD HER!
Was This Post Helpful? 0
  • +
  • -

#4 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1876
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Mysql Errors

Posted 24 July 2002 - 04:04 PM

Done... 25 points awarded, thanks for helping fyrestorm, and thanks for noticing FlashAges.
Was This Post Helpful? 0
  • +
  • -

#5 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Mysql Errors

Posted 24 July 2002 - 08:03 PM

thanks for the points, i was just doing what this is for...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1