Jump to content

MySQL Error


awesty

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 :)
Link to comment
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.
Link to comment
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 :)
Link to comment
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).
Link to comment
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. ::)
Link to comment
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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.