Jump to content

[SOLVED] database inserts all blank


illuz1on

Recommended Posts

Hey, I try to add a record with the action "script.php?action=add" ... and then I try to insert it with the action "script.php?action=insert"..

 

The problem is it inserts a row into the database, but of empty fields, just blanks?

 

Can anyone see the problem?

 

if( $_GET["action"] == "insert" ){ // INSERT ACTION ///////////////////////////////////

$sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$_GET[picture]', '$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Beach added to database! - Check to see if it is valid!";

} elseif( $_GET["action"] == "add" ){ // ADD ACTION ///////////////////////////////////
echo "<b>Beach Administration - Add Beach</b><br>";
echo "<br>";
echo "<br>";
echo "<form action=\"?action=insert\" method=\"post\">
      Name:<INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=30><br>
      Picture:<INPUT TYPE=\"TEXT\" NAME=\"picture\" SIZE=30><br>
      Rating:<INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=30><br>
      Short Desc:<TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Long Desc:<TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Ocean:<INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=30><br>
      Surfing Info:<INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=30><br>   
      Directions:<INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=30><br>
    <input type=\"submit\" value=\"Add Beach\" />
    </p>
</form>";

Link to comment
Share on other sites

here try this

<?php

if( $_GET["action"] == "insert" ){ // INSERT ACTION ///////////////////////////////////
$name = $_POST['name'];
$picture = $_POST['picture'];
$rating = $_POST['rating'];
$sdesc = $_POST['sdesc'];
$ldesc = $_POST['ldesc'];
$ocean = $_POST['ocean'];
$surfing = $_POST['surfing'];
$directions = $_POST['directions'];
$sql = mysql_query("INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('".$picture."', '".$rating."','".$name."', '".$sdesc."', '".$ldesc."', '".$ocean."', '".$surfing."', '".$directions."')");
if (!$sql)
  {
  die('Error: ' . mysql_error());
  }
echo "Beach added to database! - Check to see if it is valid!";
} else ( $_GET["action"] == "add" ){ // ADD ACTION ///////////////////////////////////
echo "<b>Beach Administration - Add Beach</b><br>";
echo "<br>";
echo "<br>";
echo "<form action=\"?action=insert\" method=\"post\">
      Name:<INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=30><br>
      Picture:<INPUT TYPE=\"TEXT\" NAME=\"picture\" SIZE=30><br>
      Rating:<INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=30><br>
      Short Desc:<TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Long Desc:<TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Ocean:<INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=30><br>
      Surfing Info:<INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=30><br>   
      Directions:<INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=30><br>
    <input type=\"submit\" value=\"Add Beach\" />
    </p>
</form>";
}
?>

Link to comment
Share on other sites

<?php

if( $_GET["action"] == "insert" ){ // INSERT ACTION ///////////////////////////////////
$name = $_POST['name'];
$picture = $_POST['picture'];
$rating = $_POST['rating'];
$sdesc = $_POST['sdesc'];
$ldesc = $_POST['ldesc'];
$ocean = $_POST['ocean'];
$surfing = $_POST['surfing'];
$directions = $_POST['directions'];
$sql = mysql_query("INSERT INTO beaches (`picture`, `rating`, `name`, `sdesc`, `ldesc`, `ocean`, `surfing`, `directions`) VALUES ('$picture', '$rating','$name', '$sdesc', '$ldesc', '$ocean', '$surfing', '$directions')");
if (!$sql)
  {
  die('Error: ' . mysql_error());
  }
echo "Beach added to database! - Check to see if it is valid!";
} else ( $_GET["action"] == "add" ){ // ADD ACTION ///////////////////////////////////
echo "<b>Beach Administration - Add Beach</b><br>";
echo "<br>";
echo "<br>";
echo "<form action=\"?action=insert\" method=\"post\">
      Name:<INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=30><br>
      Picture:<INPUT TYPE=\"TEXT\" NAME=\"picture\" SIZE=30><br>
      Rating:<INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=30><br>
      Short Desc:<TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Long Desc:<TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA><br>
      Ocean:<INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=30><br>
      Surfing Info:<INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=30><br>   
      Directions:<INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=30><br>
    <input type=\"submit\" value=\"Add Beach\" />
    </p>
</form>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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