Jump to content

Inserting javascript into MySQL


Bravat

Recommended Posts

I have html page inserted into table, and I need to insert JS that is specific for that page. When I insert it in DB nothing happens, but when I put it into footer.php it works just fine, but I keep getting error until I go to the specific page (JS is searching for specific form to load). I use function

"htmlspecialchars" to insert page into DB. Does this have something to do with this.

This is JS code:

<script type="text/javascript">// <![CDATA[
  var frmvalidator  = new Validator("forma");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();

    frmvalidator.addValidation("ime","req","Please enter your First Name");
    frmvalidator.addValidation("ime","maxlen=20",	"Max length for FirstName is 20");

    frmvalidator.addValidation("email","maxlen=50");
    frmvalidator.addValidation("email","req","Please enter your Email");
// ]]></script>

Link to comment
Share on other sites

Why you would be storing entire html documents including Javascript in the first place is beyond me but anyway, are you escaping your data properly before trying to insert it? What errors exactly are you getting?

Link to comment
Share on other sites

Well I am new to web, PHP and MySQL and it seems good idea to store hole page into DB for easier accesses :D. Into DB is stored body of the page without header and footer.

There is no error when I put page into DB. Everything is putted fine, but JS isn't loaded. However, when I put JS in footer.php it is loaded but I get this error:

Error: couldn't get Form object forma.

Error is on every other page, except on the page where form is located.

Link to comment
Share on other sites

Well I am new to web, PHP and MySQL and it seems good idea to store hole page into DB for easier accesses

 

It's not. You may as well be using simple HTML if your just using your database like a filesystem.

 

Anyway, we need to see some relevant code in order to assist.

Link to comment
Share on other sites

This is the page associated with JS:

<div class="articlesQuote" id="article">
<div class="heading">
<h1 id="newTitle">Get a Free Quote</h1>
</div>
<div class="articletxt">
<p>Please fill out the form below. When you are finished our automated system will calculate the price for your project. Take note that the price is orientative and will vary depending on active discounts and promotions!</p>
<div class="quote"><form id="forma" action="actions/quote.php" method="post" name="forma">
<div class="form_para"><fieldset id="legborder"><legend id="legend">Contact Information</legend>
<div id="fieldset"><label class="labela" for="ime">Your Name *: </label><input id="ime" type="text" name="ime" size="30" /><br />
<div id="forma_ime_errorloc" class="error_strings"> </div>
<script type="text/javascript">// <![CDATA[
                        $(document).ready(function() {
                          if (!("autofocus" in document.createElement("input"))) {
                            $("#ime").focus();
                          }
                        });
// ]]></script>
<label class="labela" for="email">Your Email *: </label><input id="email" type="email" name="email" size="30" /><br />
<div id="forma_email_errorloc" class="error_strings"> </div>
<label class="labela" for="kompanija">Company: </label><input id="kompanija" type="text" name="kompanija" size="30" /></div>
</fieldset></div>
<div class="form_para"><fieldset id="legborder"><legend id="legend">Project Information</legend>
<div id="fieldset"><label class="labela" for="usluga">Type of website services *: </label> <select id="usluga" name="usluga"><option value="Select One...">Select One...</option><option value="Design of an entirely new website">Design of an entirely new website</option><option value="Complete redesign of a website">Complete redesign of a website</option><option value="Maintenance or upgrade to an existing website">Maintenance or upgrade to an existing website</option><option value="eCommerce Website">eCommerce Website</option><option value="Search Engine Optimization">Search Engine Optimization</option><option value="Other">Other</option></select><br /> <label class="labela" for="sajt">If you have a website. please indicate the URL: </label><input id="sajt" type="url" name="sajt" value="http://" size="30" /><br /> <br /> <label class="labela" for="logo">Do you have a logo for your new site?: </label> <select id="logo" name="logo"><option value="Yes">Yes</option><option value="No">No</option></select><br /> <label class="labela" for="budzet">Project Budget *: </label><select id="budzet" name="budzet"><option value="200$-500$">200$-500$</option><option value="500$-1000$">500$-1000$</option><option value="1000$-1500$">1000$-1500$</option><option value="1500$-2000$">1500$-2000$</option><option value="2000$-2500$">2000$-2500$</option><option value="2500$-5000$">2500$-5000$</option><option value="5000$ or more">5000$ or more</option></select><br /> <label class="labela" for="domen">Domain Name Registration: </label> <select id="domen" name="domen"><option value="Select One...">Select One...</option><option value="I need a Domain Name registered">I need a Domain Name registered</option><option value="I already have a Domain Name">I already have a Domain Name</option><option value="Not Sure Yet, Please Contact Me">Not Sure Yet, Please Contact Me</option></select><br /> <label class="labela" for="hosting">Website Hosting: </label> <select id="hosting" name="hosting"><option value="Select One...">Select One...</option><option value="I need Website Hosting">I need Website Hosting</option><option value="I already have Website Hosting">I already have Website Hosting</option><option value="Not Sure Yet, Please Contact Me">Not Sure Yet, Please Contact Me</option></select><br /> <label class="labela" for="opis">Which description best represents your desired e-store?</label> <select id="opis" name="opis"><option value="We do not intend to sell products on our site right now.">We do not intend to sell products on our site right now.</option><option value="Small store on a new site with a fewer than 40 products; paypal integration should do the trick.">Small store on a new site with a fewer than 40 products; paypal integration.</option><option value="We need a merchant account and have up to several hundred products; frequent updates.">We need a merchant account, up to several hundred products; we will update the store often.</option><option value="We are going to offer subscriptions and/or downloadable files.">We are going to offer subscriptions and/or downloadable files.</option></select><br /> <br /> <label class="labela" for="start">Project Start: </label> <select id="start" name="start"><option value="Select One....">Select One....</option><option value="ASAP">ASAP</option><option value="1-2 weeks">1-2 weeks</option><option value="3-4 weeks">3-4 weeks</option><option value="4+ weeks">4+ weeks</option></select><br /> <label class="labela" for="slicnost">Other websites that match the design and/or functionality you want for your website: </label> <input id="slicnost" type="url" name="slicnost" value="http://" size="30" /><br /> <input id="slicnost1" type="url" name="slicnost1" value="http://" size="30" /><br /> <label class="labela" for="poruka">Please describe your website project. </label><textarea id="poruka" class="txtarea" name="poruka" rows="9" cols="40"></textarea></div>
</fieldset></div>
<div class="form_para"><fieldset id="legborder"><legend id="legend">Other Important Functions Required</legend>
<div class="radio_butt"><input id="cms" type="checkbox" name="cms" value="CMS and Website Editing" /> CMS - Website Editing<br /> <input id="blog" type="checkbox" name="blog" value="Blog" /> Blog<br /> <input id="feedback_forms" type="checkbox" name="feedback_forms" value="Feedback Forms" /> Feedback Forms<br /> <input id="newsletter" type="checkbox" name="newsletter" value="Newsletter Management" /> Newsletter Management</div>
<div class="radio_butt"><input id="application_forms" type="checkbox" name="application_forms" value="Application Forms" /> Application Forms<br /> <input id="surveys" type="checkbox" name="surveys" value="Polls & Surveys" /> Polls & Surveys<br /> <input id="community_forum" type="checkbox" name="community_forum" value="Community Forum" /> Community Forum<br /> <input id="gallery_quote" type="checkbox" name="gallery" value="Photo Gallery" /> Photo Gallery</div>
<div class="radio_butt"><input id="flash_headers" type="checkbox" name="flash_headers" value="Flash Headers" /> Headers<br /> <input id="tell_a_friend" type="checkbox" name="tell_a_friend" value="Tell_A_Friend Feature" /> Tell-A-Friend Feature<br /> <input id="website_search" type="checkbox" name="website_search" value="Website Search" /> Website Search<br /> <input id="registration" type="checkbox" name="registration" value="registration" /> Registration/Membership</div>
<div class="radio_butt"><input id="call_back_forms" type="checkbox" name="call_back_forms" value="Call Back Forms" /> Call Back Forms<br /> <input id="file_uploading" type="checkbox" name="file_uploading" value="File Uploading" /> File Uploading<br /> <input id="social_media" type="checkbox" name="social_media" value="social_media" /> Social Media Integration<br /> <input id="logins" type="checkbox" name="logins" value="User/Password Logins" /> User/Password Logins</div>
<div class="radio_butt"><input id="live_support" type="checkbox" name="live_support" value="Live Support" /> Live Support<br /> <input id="chat_room" type="checkbox" name="chat_room" value="Chat Room" /> Chat Room<br /> <input id="bilingual_text" type="checkbox" name="bilingual_text" value="Bilingual Text" /> Bilingual Text</div>
</fieldset></div>
<input class="buttons" type="submit" name="submit" value="submit" />
</form></div>
</div>
</div>

--------This is JS which controls form-----


<script type="text/javascript">// <![CDATA[
  var frmvalidator  = new Validator("forma");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();

    frmvalidator.addValidation("ime","req","Please enter your First Name");
    frmvalidator.addValidation("ime","maxlen=20",	"Max length for FirstName is 20");

    frmvalidator.addValidation("email","maxlen=50");
    frmvalidator.addValidation("email","req","Please enter your Email");
// ]]></script>

 

This is the way I use to store page into DB:

if(isset($_POST['submit_no_roller'])){
	$body = htmlspecialchars($_POST['body1']);
	$naslov = $_POST['naslov'];
	$lang_short = $_POST['lang_short'];
	$pozicija = $_POST['pozicija'];
	$query = "INSERT INTO pages VALUES (NULL, '$body', 0, '$naslov', '$pozicija', '$lang_short')";
	$result = mysql_query($query);
	}

Link to comment
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.