oh hey guys, i got this little issue where i can read from the database. but i cannot write to it..

here be my full code. live site at http://downloadavirus.net

<?php
  $params = $_SERVER['QUERY_STRING'];
  $url = $_POST["url"];
  
  $username = "--------";
  $password = "--------";
  $database = "--------";
  mysql_connect(localhost, $username, $password);
  @mysql_select_db($database) or die("Unable to select database");
  
  
  
  
  
  
  
  if ($params == "") {
      if ($url == "") {
          echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Download A Virus | URL Redirection</title>
<style type=\"text/css\">
<!--
body {
  background-image: url(bg.png);
}
body,td,th {
  font-family: Arial, Helvetica, sans-serif;
  color: #FFF;
  font-size: 24px;
}

-->
</style></head>

<body>
<div style=\"position:absolute; left:50%; top:50%; margin-left:-335px; margin-top:-204px; background:url(window.png); height:408px; width:671px;\">
<div style=\"position:absolute; left:50%; top:50%; margin-top:-70px; width:547px; margin-left:-273px; text-align: center; vertical-align:middle\">
  <p><span style=\"font-size:xx-large; font-weight:600\">Download A Virus</span><br />
    <span style=\"font-size:small; color:#CCC\">url redirection</span>
    <br />
  </p>
  <p><form method=\"post\">
    <label>
      <input name=\"url\" type=\"text\" id=\"url\" size=\"50\" />
    </label>
    <label>
      <br />
      <input type=\"submit\" name=\"button\" id=\"button\" value=\"GO\" />
    </label></form>
  </p>
</div>
</div>


</body>
</html>";
      } else {
          mysql_query("INSERT INTO main VALUES NULL, '$url')");
          
          $result = mysql_query("SELECT * FROM main");
          $num = mysql_numrows($result);
          
          
          echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Download A Virus | URL Redirection</title>
<style type=\"text/css\">
<!--
body {
  background-image: url(bg.png);
}
body,td,th {
  font-family: Arial, Helvetica, sans-serif;
  color: #FFF;
  font-size: 24px;
-->
</style></head>

<body>
<div style=\"position:absolute; left:50%; top:50%; margin-left:-335px; margin-top:-204px; background:url(window.png); height:408px; width:671px;\">
<div style=\"position:absolute; left:50%; top:50%; margin-top:-70px; width:547px; margin-left:-273px; text-align: center; vertical-align:middle\">
  <p><span style=\"font-size:xx-large; font-weight:600\">Download A Virus</span><br />
    <span style=\"font-size:small; color:#CCC\">url redirection</span>
    <br />
  </p>
  <p>
    <label>
      <input name=\"url\" type=\"text\" id=\"url\" size=\"50\" value=\"http://downloadavirus.net/?" . $num . "\" />
    </label>
  </p>
</div>
</div>


</body>
</html>";
      }
  } else {
      $lol = mysql_query("SELECT * FROM main WHERE id=$params");
      if ($lol != "") {
          $ur = mysql_result($lol, 0, "url");
      }
      
      
      
      
      header("Location: $ur");
  }
?>

Hi,

I assume that the problem is with this line:

mysql_query("INSERT INTO main VALUES NULL, '$url')");

The syntax is for an SQL insert is:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

You should change it to:

mysql_query("INSERT INTO main VALUES (NULL, '$url')");

OH
You didn't put the '(' after VALUES.

Hope this helps
Kieran :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.