I'm having an issue with a MySQL/PHP site I'm working on. I'm new to both. I've seen several posts that were similar or same but was unable to derive a solution based on my code.

I have a form that will submit HTML code to a database. I know the form/php/database works since I've test it with non-code text and it works fine.

An example of the HTML code I'd like to submit is as follows; it will be for a link within an image (the image located on the web).

<a target='new' href='http://www.destination.com><IMG alt='ALT TAG' border='0' src='http://www.imagelocation.com></a><IMG border='0' width='1' height='1' src='http://www.image sourece.com>

The Error reads as follows:

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 'new' href='http://www.destination.com>ALT TAG

Below is the code for the 'add' which contains the form and 'added' which sends to the database.


<form method="post" action="added.php">
<b>Please enter the catalog item information:</b><br>

		<label for="link"><b>Link:</b></label>
		<input id="link" name="link"  size="100" />

<input type="submit" name="submit" value="Add" />



mysql_select_db("dbase", $con);
	$sql="INSERT INTO catalog (link)

	if (!mysql_query($sql,$con))
	die('ERROR: '. mysql_error());

	echo "<h1>Success!</h1><br>Catalog item has been entered into database.<br><br>";
  header("Location: add.php", 301);

Recommended Answers

All 2 Replies

You should escape ' before adding it to the database.

$link = mysql_real_escape_string($_POST['link']);
	$sql="INSERT INTO catalog (link)
	VALUES ('$link')";

You got that error because, the opening ' in your query is terminated when it encounters

<a target='

Dear friend

Use the insert code like this

INSERT INTO `tablename` (`id`, `name`) VALUES
(30, '<a href=ww.yahoo.com>Yahoo</a>');

THanks and Regards

commented: Its a 2 months old thread. Is it really necessary to bring it up ? -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.