illuz1on Posted May 15, 2007 Share Posted May 15, 2007 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/51559-solved-database-inserts-all-blank/ Share on other sites More sharing options...
calabiyau Posted May 15, 2007 Share Posted May 15, 2007 Your form method is POST but you are inserting GET. Change the GET'S to POST's and i'm sure it will work. Quote Link to comment https://forums.phpfreaks.com/topic/51559-solved-database-inserts-all-blank/#findComment-253901 Share on other sites More sharing options...
chriscloyd Posted May 15, 2007 Share Posted May 15, 2007 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51559-solved-database-inserts-all-blank/#findComment-253902 Share on other sites More sharing options...
illuz1on Posted May 15, 2007 Author Share Posted May 15, 2007 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/51559-solved-database-inserts-all-blank/#findComment-253916 Share on other sites More sharing options...
chriscloyd Posted May 15, 2007 Share Posted May 15, 2007 <?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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51559-solved-database-inserts-all-blank/#findComment-253921 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.