ohdang888 Posted December 31, 2007 Share Posted December 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/ Share on other sites More sharing options...
revraz Posted December 31, 2007 Share Posted December 31, 2007 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')) Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426898 Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 Don't forget the semicolon at the end of the query Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426900 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 thanks. but its still saying: Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\create.php on line 15 what does that even mean? Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426903 Share on other sites More sharing options...
revraz Posted December 31, 2007 Share Posted December 31, 2007 It was the last line of the code, so a ; really isn't required. Don't forget the semicolon at the end of the query Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426904 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 any thoughts about that error???? Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426906 Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 It's always good practice to put the semi-colons in. What's with the `games`.`game`? That's probably where the syntax issue is. Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426907 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 `games` means the database "games" `game` means the table "game" at least that whats i think it is. Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426909 Share on other sites More sharing options...
revraz Posted December 31, 2007 Share Posted December 31, 2007 Good practice or not, it's still not required. dbname.tablename, its allowed but not required, would be ok to just make it game. What is line 15? Remove the extra " here <form method="post" " > <----- Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426911 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 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')); Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426913 Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426914 Share on other sites More sharing options...
revraz Posted December 31, 2007 Share Posted December 31, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426919 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 iit works! Quote Link to comment https://forums.phpfreaks.com/topic/83887-solved-form-to-insert-info-into-db/#findComment-426945 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.