Jump to content

Archived

This topic is now archived and is closed to further replies.

awesty

MySQL Error

Recommended Posts

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

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

and this is the code i am using:

[code]<?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 />";
}
?>[/code]

any help would be appreciated.

thanks :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Yes, sorry - yeah.
If you look at the top you'll see in the first part you have:
[code]
mysql_select_db("awesty_data", $con);
[/code]

But lower down its just:
[code]
mysql_select("awesty_data", $con);
[/code]

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

Share this post


Link to post
Share on other sites
that solved that problem.

but now i am getting this message:
[quote]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
[/quote]

i should i do?

thanks alot for all your help :)

Share this post


Link to post
Share on other sites
[code]while($row = mysql_fetch_array($result));
{
echo $row['FirstName'];
echo "<br />";
echo $row['LastName'];
echo "<br />";
}[/code]

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

Share this post


Link to post
Share on other sites
That, or your query is failing...

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=100169.msg395265#msg395265 date=1152636794]
That, or your query is failing...
[/quote]

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. ::)

Share this post


Link to post
Share on other sites
[code]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()");
[/code]

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

[code]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());[/code]
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());

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.