christophe Posted February 6, 2007 Share Posted February 6, 2007 Hi i have this script but it will not let me insert the data into mysql can anyone see were i am going wrong <html> <head> </head> <body> <?php if (!isset($_POST['submit'])) { // form not submitted ?> <table width="700" border="0" cellspacing="5"> <tr> <td align="right"> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Name:</td> <td><input type="text" name="name" size="30"></td> </tr> <tr> <td align="right">Surname:</td> <td><input type="text" name="surname" size="30"></td> </tr> <tr> <td align="right">Username:</td> <td><input type="text" name="userrname" size="30"></td> </tr> <tr> <td align="right">Headline:</td> <td><input type="text" name="headline" size="30"></td> </tr> <tr> <td align="right">About Me:</td> <td><input type="text" name="aboutme" height="30" size="30"></td> </tr> <tr> <td align="right">i'd like to meet:</td> <td><input type="text" name="meet" size="30"></td> </tr> <tr> <td align="right">Music:</td> <td><input type="text" name="music" size="30"></td> </tr> <tr> <td align="right">Films:</td> <td><input type="text" name="films" size="30"></td> </tr> <tr> <td align="right">T.V:</td> <td><input type="text" name="tv" size="30"></td> </tr> <tr> <td align="right">Books</td> <td><input type="text" name="books" size="30"></td> </tr> <tr> <td align="right">Heroes:</td> <td><input type="text" name="heroes" size="30"></td> </tr> <tr> <td></td> <td><input type='submit' value='Submit'></td> </tr> </form> </table> <?php } else{ // form submitted // set server access variables $host = "*********"; $user = "**********"; $pass = "**********"; $db = "**********"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "INSERT INTO members_profile (name, surname, username, headline, aboutme, meet, music, films, tv, books, heroes) VALUES ('$name', '$surname', '$username', '$headline', '$aboutme', '$meet', '$music', '$films', '$tv', '$books', '$heroes')"; // execute query $result = mysql_query($query)or die("Error in query: $query. ".mysql_error()); // print message with ID of inserted record echo "New record inserted with ID ".mysql_insert_id(); echo "<br><br><a href='#' onClick='history.go(-1)'>Back</a>"; // close connection mysql_close($connection); } ?> </body> </html> I have the exact same script on another program and it works fine. The only thing different is I have put the html form into a table. Thanks Alex Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 6, 2007 Share Posted February 6, 2007 You never defined your $_POST variables from the form. Your other server may not have required you to call the variables from the $_POST action. What errors are you getting, or what is happening? Quote Link to comment Share on other sites More sharing options...
christophe Posted February 6, 2007 Author Share Posted February 6, 2007 Hi thanks for your reply Im not getting any errors but when i submit the form it just goes blank and says nothing and nothing happens Regards Alex Quote Link to comment Share on other sites More sharing options...
christophe Posted February 7, 2007 Author Share Posted February 7, 2007 Im also using the same database as the original form Quote Link to comment Share on other sites More sharing options...
trq Posted February 7, 2007 Share Posted February 7, 2007 Im also using the same database as the original form Forms don't have databases, so I'm not sure what you mean exactly. Have you changed all the variables within your query to corilate with the fact they are comming from the $_POST array? ie; Instead of $name you need $_POST['name']. Also, place this at the very top of the script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> Quote Link to comment Share on other sites More sharing options...
richardw Posted February 7, 2007 Share Posted February 7, 2007 Add the "name" variable to your submit button: <input name="submit" type='submit' value='Submit'> This should work. best Quote Link to comment 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.