awesty Posted July 11, 2006 Share Posted July 11, 2006 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 https://forums.phpfreaks.com/topic/14274-mysql-error/ Share on other sites More sharing options...
Chips Posted July 11, 2006 Share Posted July 11, 2006 The answer is in the error, there is no php function for mysql_selectYou have infact put it in there though, most likely instead of mysql_select_db. Link to comment https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56094 Share on other sites More sharing options...
awesty Posted July 11, 2006 Author Share Posted July 11, 2006 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 :) Link to comment https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56104 Share on other sites More sharing options...
Chips Posted July 11, 2006 Share Posted July 11, 2006 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 https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56108 Share on other sites More sharing options...
awesty Posted July 11, 2006 Author Share Posted July 11, 2006 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 https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56121 Share on other sites More sharing options...
Chips Posted July 11, 2006 Share Posted July 11, 2006 [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 https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56155 Share on other sites More sharing options...
fenway Posted July 11, 2006 Share Posted July 11, 2006 That, or your query is failing... Link to comment https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56310 Share on other sites More sharing options...
awesty Posted July 12, 2006 Author Share Posted July 12, 2006 [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 https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56625 Share on other sites More sharing options...
Chips Posted July 12, 2006 Share Posted July 12, 2006 [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");orquery("query in here") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/14274-mysql-error/#findComment-56747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.