nick_whitmarsh Posted February 22, 2007 Share Posted February 22, 2007 Hey guys really new at this, blah blah blah. Anyway I am trying to run a mini form that alows the user to enter a new database. It gets a blank page when I try this, however i tried all the lines of code and the error I believe lies in this line of code below :- $rs1 = @mysql_create_db( $_REQUEST['db'] ) if anyone could help me with this i would be grateful. Cheers guys. Nick Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 22, 2007 Share Posted February 22, 2007 Well, this is just a stab in the dark, but you don't have a semicolon on that line. You need to give us the error and/or what you are expecting and more than just one line of code. Quote Link to comment Share on other sites More sharing options...
jcbarr Posted February 22, 2007 Share Posted February 22, 2007 You should really be doing it this way; mysql_connect ("localhost","$user","$password") $soru = 'CREATE DATABASE '.$dbname; mysql_query($soru); Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 Yeah sorry. Nah the semi-colon didnt fix anything. The problem is that I just get a blank page, guess I should have said that sorry. Anyway the code is :- <?php $user = "nick"; $conn = @mysql_connect( "localhost",$user,"reading") or die ("Sorry - could not connect to MySQL"); $rs1 = @mysql_create_db( $_REQUEST['db'] ); $rs2 = @mysql_list_dbs ( $conn ); for( $row = 0; $row < mysql_num_rows ( $rs2 ); $row++ ) { $list .= mysql_tablename( $rs2, $row) . " | "; } ?> <html><head><title>Creating Databases</title></head> <body> <form action = "<?php echo( $_SERVER['PHP_SELF'] ); ?>" method="post">Current databases: <?php echo( $list ); ?> <hr>Name:<input type = "text" name = "db"> <input type = "submit" value = "Create database"> </form></body></html> As I said I went through the code and it all works until I used the line of code i already stated. cheers Nick Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2007 Share Posted February 22, 2007 Take out all the @ so you can get some errors. Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 I took out all the @, but i still get no errors, all I get is a blank page Nick Quote Link to comment Share on other sites More sharing options...
jcbarr Posted February 22, 2007 Share Posted February 22, 2007 Try this; $rs1 = @mysql_create_db( {$_REQUEST['db']} ); Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 Hi, cheers I tried that line also but it still did not work. It baffles me because I got the code from a book and it is exactly the same. Just very annoying as it is one of my first things I have done. Cheers, Nick Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 22, 2007 Share Posted February 22, 2007 Are you sure that $_REQUEST['db'] has a value? Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 What do you mean by does it have a value? If it does not how do I have to fix this problem. Cheers. Nick Quote Link to comment Share on other sites More sharing options...
corbin Posted February 22, 2007 Share Posted February 22, 2007 As jcbarr said, I suggest using mysql_connect ("localhost","$user","$password") $soru = 'CREATE DATABASE '.$_REQUEST['db']; mysql_query($soru); since I have heard mysql_create_db is deprecated. If you hard code the database name in, will it create it? The mysql name does have access to create databases, correct? Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 Yes it does have access, do I just replace this code, with the line that i am having problems with? Nick Quote Link to comment Share on other sites More sharing options...
nick_whitmarsh Posted February 22, 2007 Author Share Posted February 22, 2007 I just tried it and it works, cheers guys. Is it just that the line of code is bugged then Quote Link to comment Share on other sites More sharing options...
corbin Posted February 23, 2007 Share Posted February 23, 2007 Hmm maybe MySQL 5 discontinued the use of mysql_create_db... Or maybe something else was wrong entirely... I don't know either way. Quote Link to comment Share on other sites More sharing options...
jcbarr Posted February 23, 2007 Share Posted February 23, 2007 My guess is that the $_REQUEST['db'] wasn't populated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.