TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-06-2008, 07:58 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default how to insert html or php code into a table?

im trying to insert some html or some php code into a databasese table but im getting errors. how do i do this?

i'm trying to insert this

Code:
<li>NaviDoor School Application Service (Excluding Mandatory School Application Fee 'Application Requirement')</li>
<li>NaviDoor Immigration Application Service (Excluding SEVIS 'Immigration Requirement')</li>
<li>NaviDoor Host Family / Apartment Application Service. Include Free Registration value of $100</li>
<li>NaviDoor Support ('Counseling & Guidance' before departure and in Los Angeles for one week.)</li>
<li>NaviDoor Airport Pick-Up</li>
<li>FREE Essay Editing</li>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-06-2008, 08:08 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

And what errors are you getting? Perhaps you want to escape your single quotes before sending that to the database first?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 09-06-2008, 08:22 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

yea i think it has to do with symbols but if i did use the htmlspecialchars function to insert the data how would i convert it back to html to preview it.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-06-2008, 08:54 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Run the HTML string through mysql_real_escape_string() to prevent the HTML causing problems with the SQL query syntax (and for a basic, much needed security boost) if you're not already.

Do not transform the data (i.e. using htmlspecialchars, etc.) where it's not necessary. That's a basic rule of thumb and an important one to learn.
Salathe is offline  
Reply With Quote
Old 09-06-2008, 09:13 PM   #5 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

why didnt i think of that salathe :D thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-07-2008, 03:57 AM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

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 '' at line 1
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-07-2008, 10:18 AM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

In order for me to debug that message, I need to see your query.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 09-07-2008, 12:23 PM   #8 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

here is the code

Code:
<?php
include("includes/config.php");
if(isset($_POST['submit'])) { 

$title = mysql_real_escape_string($_POST['title']);
$desc = mysql_real_escape_string($_POST['desc']);
$price = mysql_real_escape_string($_POST['price']);

$query = mysql_query("insert into tbl_package values(null, '$title','$desc','$price'") or die(mysql_error());




}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

Title: <input type="text" name="title" /><br />
Desc: <textarea name="desc" cols="60" rows="10"></textarea>
<br />
Price: <input type="text" name="price" /><br />
<br />
<input type="submit" name="submit" value="submit" />




</form>
</body>
</html>

here is the content that went into the text boxes


Code:
title: Promo Package
desc: 
<ul>
<li>NaviDoor School Application Service (Excluding Mandatory School Application Fee 'Application Requirement')</li>
<li>NaviDoor Immigration Application Service (Excluding SEVIS 'Immigration Requirement')</li>
<li>NaviDoor Host Family / Apartment Application Service. Include Free Registration value of $100</li>
<li>NaviDoor Support ('Counseling & Guidance' before departure and in Los Angeles for one week.)</li>
<li>NaviDoor Airport Pick-Up</li>
<li>FREE Essay Editing</li>
</ul>

price: 100
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:06 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design