Jump to content

[SOLVED] form "submit" problem


ohdang888

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.