Unholy Prayer Posted November 16, 2006 Share Posted November 16, 2006 Ok, I can't figure out what's wrong with this php form to add information into the database. This is my table structure:[IMG]http://img119.imageshack.us/img119/5787/phptablewe9.gif[/img]This is my script:[code]<?php require_once('config.php');if(isset($_POST['submit'])){ $name = $_POST['name']; $url = $_POST['message']; mysql_query("INSERT INTO menu_links (name,url) values ('$name', '$url')"); echo "The link was successfully added."; } echo "<table align='center' width='50%' cellspacing='1' cellpadding='1' border='0'> <form action='addlink.php' method='POST'> <tr> <td align='center' colspan='2'><b>Add a Menu Link</b></td> </tr><tr> <td align='right'>Link Name:</td> <td align='left'><input type='text' name='name' size='20'></td> </tr><tr> <td align='right'>Link URL:</td> <td align='left'><input type='text' name='url' size='20'></td> </tr><tr> <td align='center' colspan='2'><input type='submit' value='submit'></td> </tr> </form> </table>";?>[/code]I'm not getting any error messages, but the message that should come up with the submit button is hit doesn't come up and nothing is inserted into the database. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 16, 2006 Share Posted November 16, 2006 Of course you are not getting any error messages. You didn't ask for them. Plus "name" may be a reserved name in mySQL. Try enclosing it withing back quotes.Change your query line to this to see any possible errors:[code]mysql_query("INSERT INTO menu_links (name,url) values ('$name', '$url')") or die(mysql_error()); [/code] Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted November 16, 2006 Author Share Posted November 16, 2006 Nothing happened. It just reset the form. Quote Link to comment Share on other sites More sharing options...
Seraskier Posted November 16, 2006 Share Posted November 16, 2006 OK in order to do this you would want to use:[code]<?phpecho "<form method='post' action='?do=do'>";echo "<table cellspacing='5' cellpadding='0'>";echo "<td><font color='#FF0000'>All Fields Required</font></td>";echo "<tr><td>Name:</td><td><input type='text' name='name' value='$_name'></td></tr>";echo "<tr><td>Url:</td><td><input type='text' name='url' value='$_url'></td></tr>";echo "<tr><td></td><td><div align='right'><input type='submit' value='Submit'></div></td></tr>";echo "</table></form>";if($_GET['do'] == 'do'){$_name = $_POST['name'];$_url = $_POST['url'];srand((double)microtime()*99999999); $_id = rand(100000,99999999);mysql_query ("insert into menu_links (id, url, name) values ('$_id', '$_url', '$_name')");}?>[/code]That should work please let me know how it comes out, works or not. Taken from my own script, modified though. Thanks. Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted November 16, 2006 Author Share Posted November 16, 2006 That worked. Thanks alot. Quote Link to comment Share on other sites More sharing options...
Seraskier Posted November 16, 2006 Share Posted November 16, 2006 OK great. I can make it do a lot more as in if the name is already taken and it must be filled in, a lot more just message me if you want anything. Thanks.You can email me to: seraskier@urbanaftermath.com 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.