ohdang888 Posted December 31, 2007 Share Posted December 31, 2007 every time i load the page, it insets a blank row of data, then i fill in the fields and it makes a new useful row of data how do i only make the php code work if submit is clicked??? <?php if (isset($_POST['submit'])) { $title= $_POST["title"]; $type = $_POST["type"]; $author = $_POST["author"]; $author_url = $_POST["author_url"]; $game_picture_url = $_POST["game_picture_url"]; $instructions = $_POST["instructions"]; $game_file_name = $_POST["game_file_name"]; $counter = $_POST["counter"]; $flash = $_POST["flash"]; mysql_connect("localhost", "root", "pancakes1") or die(mysql_error()); mysql_select_db("games") or die(mysql_error()); $sql="INSERT INTO `game` (`title`, `type`, `author`, `author_url`, `game_picture_url`, `instructions`, `game_file_name`, `counter`, `flash`) VALUES ('$title', '$type', '$author', '$author_url', '$game_picture_url', '$instructions', '$game_file_name', '$counter', '$flash')"; $result=mysql_query($sql) or die ("Error in query: $result. " . mysql_error()); } ?> <form method="post" > Title of game: <input type="text" size="80" maxlength="300" name="title"/><br> Type: <input type="text" size="80" maxlength="300" name="type"/><br> author: <input type="text" size="80" maxlength="300" name="author"/><br> author url: <input type="text" size="80" maxlength="300" name="author_url"/><br> game picture name:<input type="text" size="80" maxlength="300" name="game_picture_url"/><br> instructions:<input type="text" size="80" maxlength="300" name="instructions"/><br> Game file name(add .swf):<input type="text" size="80" maxlength="300" name="game_file_name"/><br> Counter start number:<input type="text" size="80" maxlength="300" name="counter"/><br> Flash markup of game: (add the file src with gamefile): <textarea rows="30" cols="80" name="flash"></textarea> <br> <input type="submit" name="submit" value="submit"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/ Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 The only way this code would post is if there's a variable $_POST['submit']. How does this page load, does it load from a page posting to it? In other words, if you type in the exact url to this page it still posts data into the database? Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426962 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 yes. all you have to do is type in the url localhost/create.php and when it uploads, it automatically creates a blank row of data, as if it clicks submit automatically. then i type data in the fields, abd click submit, and it craetes a useful row of data. what about "$_POST['submit']. "????? the code already works, i've tested it. but its doing what i'm describing above and i need it to stop. Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426976 Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 Alright let's try something simple like this: <?php if (isset($_POST['name'])) { $title= $_POST["title"]; $type = $_POST["type"]; $author = $_POST["author"]; $author_url = $_POST["author_url"]; $game_picture_url = $_POST["game_picture_url"]; $instructions = $_POST["instructions"]; $game_file_name = $_POST["game_file_name"]; $counter = $_POST["counter"]; $flash = $_POST["flash"]; mysql_connect("localhost", "root", "pancakes1") or die(mysql_error()); mysql_select_db("games") or die(mysql_error()); $sql="INSERT INTO `game` (`title`, `type`, `author`, `author_url`, `game_picture_url`, `instructions`, `game_file_name`, `counter`, `flash`) VALUES ('$title', '$type', '$author', '$author_url', '$game_picture_url', '$instructions', '$game_file_name', '$counter', '$flash')"; $result=mysql_query($sql) or die ("Error in query: $result. " . mysql_error()); } ?> <form name="testform" id="testform" action="pagename.php" method="post" enctype="multipart/form-data"> Title of game: <input type="text" size="80" maxlength="300" name="title"/><br /> Type: <input type="text" size="80" maxlength="300" name="type"/><br /> author: <input type="text" size="80" maxlength="300" name="author"/><br /> author url: <input type="text" size="80" maxlength="300" name="author_url"/><br /> game picture name:<input type="text" size="80" maxlength="300" name="game_picture_url"/><br /> instructions:<input type="text" size="80" maxlength="300" name="instructions"/><br /> Game file name(add .swf):<input type="text" size="80" maxlength="300" name="game_file_name"/><br /> Counter start number:<input type="text" size="80" maxlength="300" name="counter"/><br /> Flash markup of game: (add the file src with gamefile): <textarea rows="30" cols="80" name="flash"></textarea> <br /> <input type="submit" value="submit"/> </form> Be sure to change the action to your filename. Use this code and let me know if it does the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426981 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 i changed it. dind't solve the problem. i don;'t think i'm explaing this right. it only send the data to the database at the first upload. lets say, for example, i was inserting 5 games. 6 rows would be created. 1 one the page upload, 5 when i clcik submit. no blank data is sent to the db between 5 games. Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426987 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 There is no way they sql statements can be executed without $_POST['submit'] being set. I tried the original code on my server and it works. You need to start debugging the problem. Put <?php echo '<pre>' . print_r($_POST,true) . '</pre>; ?> at the beginning of your script. This will dump the $_POST array when your script starts. See what gets shown when the problem occurs. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426990 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\create.php on line 13 which is line: if (isset($_POST['submit'])) { whats wrogn with that? Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426991 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 Sorry, forgot the closing quote. <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426993 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 its showing a blank array. but the problem stopped......hm...... well, thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/83897-solved-form-submit-problem/#findComment-426997 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.