BillyJim Posted March 28, 2008 Share Posted March 28, 2008 Hello! The code below does not create database and yields no error.. I am sure it is a really stupid error, I am very sorry for this. <html> <head> <title>dynamiske webapplikasjoner</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="dynamisk.css" type="text/CSS" rel="stylesheet"> </head> <body> <div id="content1"> <img src="Fredrik.gif"> </div> <div id="content2"> </div> <div id="content3"> </div> <div id="content4"> <h3><a href="kurs.html">kursinformasjon</a></h3> <h3><a href="phpoppgaver.html">oppgaver</a></h3> <h3><a href="blog.html">blogg</a></h3> <h3><a href="info.html">info</a></h3> </div> <div id="content6"> </div> <div id="content5"> <h3><i></i></h3> <h3> <form action="createdb.php" metod="post"> Database navn:<input type="text" name="dbname"></br> <input type="radio" name="radio" value="create" checked><label>CREATE</label><br/> <input type="radio" name="radio" value="delete" /><label>DROP</label><br/> <input type="submit" name="submit" value="Run query"> </h3> <?php $tilkobling = mysql_connect("localhost","username","passwd"); mysql_select_db("db",$tilkobling)or die(mysql_error()); if(isset($_POST["submit"])) { $x = $_POST["dbname"]; $x = mysql_real_escape_string($x); $radioknapp = $_POST["radio"]; if($radioknapp=="create") { $sql = "CREATE database" . $x . ";"; mysql_query($sql,$tilkobling)or die(mysql_error()); } elseif($radioknapp == "delete") { $sql = "DROP database '$x'"; mysql_query($sql,$tilkobling)or die(mysql_error()); } mysql_close($tilkobling); } ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/ Share on other sites More sharing options...
benjaminbeazy Posted March 28, 2008 Share Posted March 28, 2008 this line $sql = "CREATE database" . $x . ";"; should be this $sql = "CREATE database " . $x; (take out the semicolon) Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502788 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks mate. I tried but no luck.. the database is not created. I have also tried other variations of that line without luck. If the MySQL syntax was wrong it should have outputted the error in any case I believe. Does not seem to get that far. Any other suggestion? Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502795 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Author Share Posted March 28, 2008 Just an update.. I also tried: if($radioknapp == "create") And other variations of that I tried stuff like ?true:false in the form and if($radioknapp == true) and tried using $_POST in the "if" etc. Still no luck. Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502814 Share on other sites More sharing options...
benjaminbeazy Posted March 28, 2008 Share Posted March 28, 2008 put a little echo statement inside your conditional to make sure that it's working if($radioknapp=="create") { echo 'it works'; $sql = "CREATE database" . $x . ";"; mysql_query($sql,$tilkobling)or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502823 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Author Share Posted March 28, 2008 Did that before, it neither yields error or echo. It does not pass the if (not the else either for that sake..) Nothing is echoed. Updated code below: <h3> <form action="" metod="post"> Database navn:<input type="text" name="dbname"></br> <input type="radio" name="radio" value="create" checked><label>CREATE</label><br/> <input type="radio" name="radio" value="delete" /><label>DROP</label><br/> <input type="submit" name="submit" value="Run query"> </h3> <?php $tilkobling = mysql_connect("localhost","ase-thea","dynweb_v0844db"); mysql_select_db("dynweb_v0844",$tilkobling)or die(mysql_error()); if(isset($_POST["submit"])) { echo "submit it works"; $x = $_POST["dbname"]; $x = mysql_real_escape_string($x); $radioknapp = $_POST["radio"]; if($radioknapp == "create") { echo "create it works"; $sql = "CREATE database" . $x; mysql_query($sql,$tilkobling)or die(mysql_error()); } elseif($radioknapp == "delete") { echo "delete it works"; $sql = "DROP database '$x'"; mysql_query($sql,$tilkobling)or die(mysql_error()); } mysql_close($tilkobling); } ?> Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502828 Share on other sites More sharing options...
benjaminbeazy Posted March 28, 2008 Share Posted March 28, 2008 take your db login info off... u don't really want everyone here to know that stuff... Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502831 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Author Share Posted March 28, 2008 Seriously..with localhost, good luck logging in to "that" host Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502834 Share on other sites More sharing options...
benjaminbeazy Posted March 28, 2008 Share Posted March 28, 2008 whatever man... your form method has a typo... Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502839 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks for the heads up on user/pass, but as I mentioned, this isnt exactly a reachable box The typo solved all my headaches! See what an extra pair of eyes does.. Thanks man! Link to comment https://forums.phpfreaks.com/topic/98265-please-help-radiobuttons-mysql-and-variables/#findComment-502842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.