Jump to content

Please help, radiobuttons - mysql and variables


BillyJim

Recommended Posts

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>

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?

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());

          }

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);
          }
?>

 

Archived

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

×
×
  • 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.