| | |
Insert HMTL Code into MySQL Database through a Form with PHP
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
Hello,
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).
The Error reads as follows:
Below is the code for the 'add' which contains the form and 'added' which sends to the database.
add.php
added.php
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).
MySQL Syntax (Toggle Plain Text)
<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:
MySQL Syntax (Toggle Plain Text)
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.
add.php
MySQL Syntax (Toggle Plain Text)
<form method="post" action="added.php"> <b>Please enter the catalog item information:</b><br> <table> <tr> <td> <label for="link"><b>Link:</b></label> </td> <td> <input id="link" name="link" size="100" /> </td> </tr> </table> <input type="submit" name="submit" value="Add" /> </form>
added.php
MySQL Syntax (Toggle Plain Text)
<?php include("connect.php"); mysql_select_db("dbase", $con); $sql="INSERT INTO catalog (link) VALUES('$_POST[link]')"; if (!mysql_query($sql,$con)) { die('ERROR: '. mysql_error()); } if(isset($_POST['submit'])) { echo "<h1>Success!</h1><br>Catalog item has been entered into database.<br><br>"; } ELSE { header("Location: add.php", 301); } mysql_close($con) ?>
You should escape ' before adding it to the database.
Use,
You got that error because, the opening ' in your query is terminated when it encounters
Use,
php Syntax (Toggle Plain Text)
$link = mysql_real_escape_string($_POST['link']); $sql="INSERT INTO catalog (link) VALUES ('$link')";
•
•
•
•
<a target='
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Dear friend
Use the insert code like this
THanks and Regards
Use the insert code like this
sql Syntax (Toggle Plain Text)
INSERT INTO `tablename` (`id`, `name`) VALUES (30, '<a href=ww.yahoo.com>Yahoo</a>');
THanks and Regards
Last edited by peter_budo; Jul 15th, 2009 at 7:33 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- How do I pass values with a link into mySQL database using PHP? (PHP)
- Resize Image + retain quality + upload to mysql database (PHP)
- Help! my script couldn't submit form data to mysql database (PHP)
- help indeed!!! inserting html data in mysql column (MySQL)
- PHP auto-save code (PHP)
- update the rows in the database using the same form (PHP)
- store HTML is a text field in a table on a MySQL Database (MySQL)
- Displaying images from mysql database (PHP)
- Using php and html forms to update a mysql database (PHP)
- Using php and html forms to update a mysql database (Community Introductions)
Other Threads in the MySQL Forum
- Previous Thread: Display daily totals for previous weeks
- Next Thread: simple question - small database
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency






