Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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