Jump to content

[SOLVED] form to insert info into db


ohdang888

Recommended Posts

i want to create a form to insert data into a table.

i'm getting this error:

 

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\create.php on line 15

 

also, that was just a test to insert the same name of the column into that field. But i want to insert $title , etc. how would i do that???

 

heres my code:

 

<?php
  $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", "----", "-----") or die(mysql_error());
  mysql_select_db("games") or die(mysql_error());

  mysql_query(INSERT INTO `games`.`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'))

  
?>


<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>

 

and i haven't even used the form yet.

Link to comment
Share on other sites

mysql_query(INSERT INTO `games`.`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'))

 

Link to comment
Share on other sites

this is line 15

mysql_query(INSERT INTO `games`.`game` (`title`, `type`, `author`, `author_url`, `game_picture_url`, `instructions`,

 

but i don't know if its including the whole query, which is

mysql_query(INSERT INTO `games`.`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'));

Link to comment
Share on other sites

Try this:

 

mysql_query("INSERT INTO `games`.`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')");

 

I believe you need the quotes

Link to comment
Share on other sites

<?php
if ($_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", "----", "-----") 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());
}
else {
?>


<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>

<?php
}
?>

 

And post any errors

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.