Chiaki Posted June 3, 2011 Share Posted June 3, 2011 Hello. I am trying to make an admin page for my site. I created a form to input links into my database, but I am running into an error. Here is the run-down of my code and errors. <form name="links" action="addlink.php" method="post"> <b>Title:</b><br><input type="text" name="title" size="50"><br> <b>URL:</b><br><input type="text" name="url" size="50"><br> <b>Description</b>:<br/> <textarea wrap="physical" name="desc" rows="3" cols="40"></textarea><br> <b>Type</b>:<br/> <input type="radio" name="type" value="1">Resource (Wikia, forum, etc.)<br> <input type="radio" name="type" value="2">Media (Youtube, Blogspot, etc.)<br> <input type="radio" name="type" value="3">Other<br> <input type="submit" value="Add Link"/> <input type="reset" value="Clear"/> </form> <? ob_start(); session_start(); include("dbconnect.php"); $name = mysql_real_escape_string($_POST["title"]); $title = ucwords($name); $url = mysql_real_escape_string($_POST["url"]); $desc = mysql_real_escape_string($_POST["desc"]); $type = $_POST["type"]; $date = date("l, F j, Y"); $time = date("g:i A"); $dt = $date . " at " . $time; $lname = $_SESSION['username']; $username = ucwords($lname); $query = "INSERT INTO adminlinks (name,url,desc,type,date,username) VALUES ('$title', '$url', '$desc', '$type', '$dt', '$username')"; $menu = mysql_query($query) or die( "<br>Query: $query<br>Failed with error: " . mysql_error() ); ob_end_clean(); header('Location: http://www.site.com/admin/index.php'); echo "Link for $title added! You will be redirected to the main page shortly. If you are not, click <a href='index.php'>here</a>."; ?> Query: INSERT INTO adminlinks (name,url,desc,type,date,username) VALUES ('Test', 'test', 'test', '1', 'Friday, June 3, 2011 at 2:00 AM', 'Chiaki') Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc,type,date,username) VALUES ('Test', 'test', 'test', '1', 'Friday, June 3, 2' at line 1 I'm still learning PHP and MySQL things, so I apologize if this looks amateurish. Quote Link to comment https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/ Share on other sites More sharing options...
revraz Posted June 3, 2011 Share Posted June 3, 2011 Possible you ran into a reserved word for MySQL. Use backticks around your column names, ie `name`, `url`, etc Quote Link to comment https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/#findComment-1224510 Share on other sites More sharing options...
Chiaki Posted June 3, 2011 Author Share Posted June 3, 2011 Possible you ran into a reserved word for MySQL. Use backticks around your column names, ie `name`, `url`, etc It looks like that doesn't work. I just tried it. Quote Link to comment https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/#findComment-1224512 Share on other sites More sharing options...
Chiaki Posted June 3, 2011 Author Share Posted June 3, 2011 Possible you ran into a reserved word for MySQL. Use backticks around your column names, ie `name`, `url`, etc It looks like that doesn't work. I just tried it. Actually.. it was a different error this time. I may know how to fix that. Quote Link to comment https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/#findComment-1224513 Share on other sites More sharing options...
Chiaki Posted June 3, 2011 Author Share Posted June 3, 2011 Everything works now! This topic can be closed. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/#findComment-1224514 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.