Jump to content


Photo

MySQL Error


  • Please log in to reply
8 replies to this topic

#1 awesty

awesty
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 July 2006 - 10:04 AM

i have just started learning mySQL and i am getting this error :(

Fatal error: Call to undefined function: mysql_select() in /home/awesty/domains/flashuser.frih.net/public_html/stuff/asd.php on line 42


and this is the code i am using:

<?php
$con = mysql_connect("localhost","awesty_data","********");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("awesty_data",$con);

mysql_query("CREATE TABLE `persons` (`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`FirstName` VARCHAR( 15 ) NOT NULL ,`LastName` VARCHAR( 15 ) NOT NULL ,`Age` INT( 10 ) NOT NULL) ENGINE = MYISAM ;) or die(mysql_error()"); 

mysql_query("INSERT INTO `persons`
(FirstName, LastName, Age)
VALUES
('Peter', 'Griffen', '35')");

mysql_query("INSERT INTO `persons`
(FirstName, LastName, Age)
VALUES
('Glenn', 'Quagmire', '33')");

mysql_query("INSERT INTO 'persons'
(FirstName, LastName, Age)
VAlUES
('$_POST[firstname]', '$_POST[lastname]', '$_POST[age]')");
/*if (!mysql_query($isql, $con))
{
die('Error: ' . mysql_query());
}
echo "Success";*/

mysql_close();
?>

<?php
$con = mysql_connect("localhost", "awesty_data", "*******");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select("awesty_data", $con);

$result = mysql_query("SELECT * FROM persons");

while($row = mysql_fetch_array($result));
{
echo $row['FirstName'];
echo "<br />";
echo $row['LastName'];
echo "<br />";
}
?>

any help would be appreciated.

thanks :)

#2 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 10:38 AM

The answer is in the error, there is no php function for mysql_select

You have infact put it in there though, most likely instead of mysql_select_db.

#3 awesty

awesty
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 July 2006 - 10:56 AM

do you mean i should change mysql_selct to mysql_select_db?

okay, im fairly new to this so i dont quite understand what you are saying. ???

thanks :)

#4 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 11:04 AM

Yes, sorry - yeah.
If you look at the top you'll see in the first part you have:
mysql_select_db("awesty_data", $con);

But lower down its just:
mysql_select("awesty_data", $con);

Looks like a typo to me, missing a _db from it is all.

#5 awesty

awesty
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 July 2006 - 11:33 AM

that solved that problem.

but now i am getting this message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/awesty/domains/flashuser.frih.net/public_html/stuff/asd.php on line 46


i should i do?

thanks alot for all your help :)

#6 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 01:07 PM

while($row = mysql_fetch_array($result));
{
echo $row['FirstName'];
echo "<br />";
echo $row['LastName'];
echo "<br />";
}

You've got a ; after the while line, it should look like this:
while($row = mysql_fetch_array($result)){
echo $row['FirstName'];
echo "<br />";
echo $row['LastName'];
echo "<br />";
}
(i think).

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 July 2006 - 04:53 PM

That, or your query is failing...
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#8 awesty

awesty
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 July 2006 - 06:49 AM

That, or your query is failing...


yea, the code probably doesnt make any sense at all ::)

i tried taking out the semi colon but it still had the same error. :(

i think ill just try to learn how to use phpMyAdmin. ::)

#9 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 12 July 2006 - 01:16 PM

mysql_query("CREATE TABLE `persons` (`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`FirstName` VARCHAR( 15 ) NOT NULL ,`LastName` VARCHAR( 15 ) NOT NULL ,`Age` INT( 10 ) NOT NULL) ENGINE = MYISAM ;) or die(mysql_error()"); 

Upon further inspection, there is both bracket and " mismatch in here.

mysql_query("CREATE TABLE `persons` (`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`FirstName` VARCHAR( 15 ) NOT NULL ,`LastName` VARCHAR( 15 ) NOT NULL ,`Age` INT( 10 ) NOT NULL) ENGINE = MYISAM;") or die(mysql_error());
I think that line is corrected, statements should be:
query("query in here") or die("error here");
or
query("query in here") or die(mysql_error());






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users