Jump to content

Link won't add into database. MySQL error.


Chiaki

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/238287-link-wont-add-into-database-mysql-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.