Jump to content

kingnutter

Members
  • Posts

    147
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kingnutter's Achievements

Member

Member (2/5)

0

Reputation

  1. I appreciate that. I'm trying to do too much at once. I'll spilt it up into stages and come back when stuck on a certain point. Many thanks.
  2. I am trying to echo a list which is essentially an index of a publication. It lists page number, title and a relevant link. Some links have no title, some titles pertain to several links. My existing code works to an extent. It is listing all of my records, grouping by title.name/id and ordering by location (page number). Neat. I have two problems: 1) Some of my links records have a title value of 0 (should it be NULL?). I don’t wish to group all of these together, but list them individually ordered by location mixed in with above. 2) All my attempts at working out whether a grouped title pertains to several links and then iterating through them is producing multi-nested conditions and queries which I am certain are superfluous. Here is my existing code. Apologies if some of the echos are not needed here. NB: I am using codeigniter hence the odd “anchor” but I want to sort this out as straight MySQL to start with. $result2 = mysql_query(" SELECT links.id, links.link, links.title, links.itemtype_id, links.notes, MIN(links.location), titles.id, titles.name FROM links JOIN titles ON links.title=titles.id WHERE heading = $id AND links.hidden = 0 GROUP BY titles.id ORDER BY MIN(links.location); "); while($linkarray = mysql_fetch_array($result2)){ echo "<div style='text-indent:" . $headings['depth'] . "em;'>" . "pg. " . $linkarray['MIN(links.location)'] . " <b>" . $linkarray['name'] . $linkarray['title'] . "</b> "; echo "<div style='text-indent:" . $headings['depth'] . "em;'>"; if ($linkarray['itemtype_id']==1){ echo "<a href='http://$linkarray[link]' target='_blank'>"; } echo $linkarray['link']; if ($linkarray['itemtype_id']==1){ echo "</a>"; } echo " "; // DELETE LINK echo anchor("edit/deleteLink/" . $linkarray['id'], "X<br />", array('class'=>'deleteLink')); echo "</div>"; echo "<div class='notes'>" . $linkarray['notes'] . " </div>"; } Here are the relevant table structures: MySQL client version: 5.1.30 CREATE TABLE IF NOT EXISTS `links` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `link` varchar(256) NOT NULL, `title` mediumint( unsigned NOT NULL DEFAULT '0', `heading` int(10) unsigned NOT NULL DEFAULT '0', `itemtype_id` tinyint(3) unsigned NOT NULL, `notes` varchar(256) DEFAULT NULL, `location` int(10) unsigned NOT NULL, `instance_id` smallint(5) unsigned NOT NULL, `hidden` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=215 ; CREATE TABLE IF NOT EXISTS `titles` ( `id` mediumint( unsigned NOT NULL AUTO_INCREMENT, `name` varchar(256) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201 ; Any help appreciated. Please let me know if any more information is required. Thanks.
  3. Hi everyone, I have a form which is repopulated with cookies of user entries following an unsuccessful submit. It works on all fields except the textarea which is just blank. Can anybody suggest why this isn't working? Here is the form page code: <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <?php include("functions.php"); getcompanyname(company); ?> <html> <head> <title>Nominate <?php echo getuserdetails("company", company); ?> for The WOW! Awards</title> <link href="mobile.css" rel="stylesheet" type="text/css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="javascript/form.js"></script> </head> <div id = "header"> <img src="images/mobile_banner.png"); </div> <div id="content"> <?php mobileerror(); ?> <h2>NOMINATE US!</h2> <div id = "rulesheading"> <b>There are just four criteria to be met:</b><br /> </div> <div id = "rules"> <ol> <li>It has to be for service that made you go WOW!</li> <li>It should be a recent experience</li> <li>It must have happened to you personally</li> <li>Employees of LoveFilm may not nominate</li> </ol> </div> <form id= "contactform" action="mobile_proc_nominate.php" method="post"> <fieldset><legend>Nomination Form</legend> <input type="hidden" name="type" value="nomination"/> <input type="hidden" name="jobtitle" value=" "/> <input type="hidden" name="department" value=" "/> <input type="hidden" name="mobile" value="1" /> <h4>Your Nomination Details</h4> <p> <?php if (!isset($_COOKIE['nominee'])){ ?> <!-- These stop the Java labels overwriting user text if error --> <label for="nominee">Tell us who WOW!ed you today (required)</label> <?php } ?> <input type="text" name="nominee" id="nominee" value="<?php echo readcookie('nominee'); ?>" title="Tell us who WOW!ed you today"/> </p> <p> <?php if (!isset($_COOKIE['comment'])){ ?> <label for="comment">How, where and when did they WOW! you? (required)</label> <?php } ?> <textarea name="comment" id="comment" value="<?php echo $_COOKIE["comment"]; ?>" title="How, where and when did they WOW! you? (required)" /></textarea> </p> <h4>Your Details</h4> <p> <?php if (!isset($_COOKIE['name'])){ ?> <label for="name">Your Name (required)</label> <?php } ?> <input type="text" name="name" id="name" value="<?php echo readcookie('name'); ?>" title="Please tell us your name"/> </p> <p> <?php if (!isset($_COOKIE['email'])){ ?> <label for="email">Your Email (required)</label> <?php } ?> <input type="text" name="email" id="email" value="<?php echo readcookie('email'); ?>" title="Please enter your email address"/> </p> <p> <?php if (!isset($_COOKIE['phone'])){ ?> <label for="phone">Your Phone Number</label> <?php } ?> <input type="text" name="phone" id="phone" value="<?php echo readcookie('phone'); ?>" title="And your phone number"/> </p> <input class="button" type="submit" value="Send" /> </fieldset> </form> </div> <div id="footer"> </div> </body> </html> And here is the form processing script: <?php include("functions.php"); checkaccess(0); require_once("includes/browser.php"); $browser = new Browser(); $thebrowser = ereg_replace("[^A-Za-z]", "", $browser->getBrowser()); $ver = $browser->getVersion(); setcookie("nominee",$_POST['nominee'],time()+3600); setcookie("comment",$_POST['comment'],time()+3600); setcookie("name",$_POST['name'],time()+3600); setcookie("email",$_POST['email'],time()+3600); setcookie("phone",$_POST['phone'],time()+3600); $email = $_POST['email']; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $email_error="TRUE"; } if ($thebrowser.$ver != "InternetExplorer6.0") { /* if(!captcha() ) { header("location: nominate.php?err=Spam Protection Code"); } else*/ if($_POST['name']=="" || $_POST['name']=="Your Name (required)" || $_POST['nominee']=="Tell us who WOW!ed you today (required)" || $_POST['nominee']=="" || $_POST['comment']=="How, where and when did they WOW! you? (required)" || $_POST['comment']=="" || $_POST['email']=="" || $_POST['email']=="Your Email (required)" || $email_error=="TRUE" ) { header("location: mobile.php?err=Please complete the required fields"); } else { connect(); $name=format_text_for_database($_POST['name']); $email=format_text_for_database($_POST['email']); $phone=format_text_for_database($_POST['phone']); $nominee=format_text_for_database($_POST['nominee']); $jobtitle=format_text_for_database($_POST['jobtitle']); $department=format_text_for_database($_POST['department']); $comment=format_text_for_database($_POST['comment']); $type=format_text_for_database($_POST['type']); $cid=company; $mobile=format_text_for_database($_POST['mobile']); $sql=mysql_query("insert into comments (date, name, email, phone, department, nominee, jobtitle, comment, type, cid, mobile) values (now(), '$name', '$email', '$phone', '$department', '$nominee', '$jobtitle', '$comment', '$type', $cid, $mobile)"); $lastid=mysql_insert_id(); disconnect(); senduseremail($lastid); sendclientemail($lastid); header("location: mobile_thanks.php"); } } if ($thebrowser.$ver == "InternetExplorer6.0") { /* if(!captcha_spam() ) { header("location: nominate.php?err=Please re-enter the Spam Protection Code"); } else*/ if($_POST['name']=="" || $_POST['email']=="" || $_POST['comment']=="") { header("location: nominate.php?err=Please complete the required fields"); } else { connect(); $name=format_text_for_database($_POST['name']); $email=format_text_for_database($_POST['email']); $phone=format_text_for_database($_POST['phone']); $nominee=format_text_for_database($_POST['nominee']); $jobtitle=format_text_for_database($_POST['jobtitle']); $department=format_text_for_database($_POST['department']); $comment=format_text_for_database($_POST['comment']); $type=format_text_for_database($_POST['type']); $cid=company; $sql=mysql_query("insert into comments (date, name, email, phone, department, nominee, jobtitle, comment, type, cid) values (now(), '$name', '$email', '$phone', '$department', '$nominee', '$jobtitle', '$comment', '$type', $cid)"); $lastid=mysql_insert_id(); disconnect(); senduseremail($lastid); sendclientemail($lastid); header("location: mobile_thanks.php"); } } ?> Any pointers would be greatly appreciated. KN
  4. Thanks. That works perfectly and I will refer to this syntax on all my future similar queries.
  5. Hi there, I'm trying to insert multiple values from one table to another along with a few set values. Hopefully you can see what I'm trying to do from the code below. Could anyone tell me the correct syntax? I am doing this through PHPmyadmin. Many thanks in advance. INSERT INTO node (nid, vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) (SELECT moj_id FROM mojocd, SELECT moj_id FROM mojocd, 'mojocd', 'en', SELECT moj_title FROM mojoocd, 0, 1, 1293671713, 1293671713, 0, 0, 0, 0, 0, 0)
  6. For anyone following this thread, I have sorted this problem by embedding the second .post in the first, so that the "json" type is just before the "return false;".
  7. Cheers I'll give that a go. By "at the top" do you mean where I list the other variables? And also, where is the anon.function?
  8. Hi everyone, In the code below, the first "alert(prev_track);" works fine, but the second doesn't. I want to use it in the response to the add_track_to_db post later but the value just seems to disappear. Can anyone tell me how to retain the variable to use it later in my script? Many thanks, KN <script type="text/javascript" charset="utf-8"> $('input[type="button"]').click(function(event) { var $target = $(event.target); var moj_id = $('#moj_id').val(); var track_no = $('#track_no').val(); var track_title = $('#track_title').val(); var track_artist = $('#track_artist').val(); var track_asinuk = $('#track_asinuk').val(); var track_asinus = $('#track_asinus').val(); $.post("../includes/get_order.php", { 'moj_id' : moj_id, 'track_no' : track_no, }, function(data){ var prev_track= data.prev_track; // John alert(prev_track); // THIS ONE WORKS }, "json"); alert(prev_track); // THIS ONE DOESN'T $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus, }, function(r) { console.log("hello" + prev_track); // NO RESPONSE HERE $('<div class="overlay"></div>') .appendTo('#form_block') .fadeIn(1000, function() { // SCRIPT STOPS $('<li>' + r + '</li>') //.hide() .appendTo("#tracks li:eq('+prev_track+')")//('#tracks') .show(1000, function() { if ($target.is('#submit1')) { $('#form_block').slideUp(1000, function() { $('.overlay').hide(); }); }; if ($target.is('#submit2')) { $('.overlay').fadeOut(1000); }; // clears form document.getElementById('form').reset(); }); }); }); return false; // disable submit click }); </script>
  9. Hi everyone, I am using JQuery to append a list item (to a ul on page tracks.php) generated on another page (add_track_to_db.php). I also need to retrieve a PHP variable ($prev_track_order) from the latter to manipulate in a JQ function. Is it possible to request and receive two separate responses, or is it a simple bit of php within the JQ? Here's the javascript from tracks.php: <script type="text/javascript" charset="utf-8"> $('input[type="button"]').click(function(event) { var $target = $(event.target); var moj_id = $('#moj_id').val(); var track_no = $('#track_no').val(); var track_title = $('#track_title').val(); var track_artist = $('#track_artist').val(); var track_asinuk = $('#track_asinuk').val(); var track_asinus = $('#track_asinus').val(); $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus, }, function(r) { // The next line is where I wish to call the php variable from add_track_to_db.php) var prev_track = "<?php echo $prev_track_order ; ?>"; console.log(prev_track) $('<div class="overlay"></div>') .appendTo('#form_block') .fadeIn(1000, function() { // $('<tr><td>' + r + '</td></tr>') $('<li>' + r + '</li>') //.hide() .appendTo("#tracks li:eq("+prev_track+")")//('#tracks') // + (track_no - // .appendTo('#tracks li:eq(prev_track)')//('#tracks') // + (track_no - 1)) .show(1000, function() { if ($target.is('#submit1')) { $('#form_block').slideUp(1000, function() { $('.overlay').hide(); }); }; if ($target.is('#submit2')) { $('.overlay').fadeOut(1000); }; document.getElementById('form').reset(); }); }); }); return false; }); </script> And here's add_track_to_db: <?php include ('conf.php') if(IS_AJAX) { $moj_id = $_POST['moj_id']; $track_no = $_POST['track_no']; $track_title= $_POST['track_title']; $track_artist= $_POST['track_artist']; $track_asinuk= "Its JQ"; // $_POST['track_asinuk']; $track_asinus= $_POST['track_asinus']; } $connection = mysql_connect($host, $user, $pass) or trigger_error('Unable to connect: ' . mysql_error($connection), E_USER_ERROR); // select database mysql_select_db($db) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); $query = "SELECT track_order FROM tracks WHERE track_no <= $track_no AND moj_id = '$moj_id' ORDER BY track_order DESC LIMIT 1"; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); $row = mysql_fetch_object($result); $prev_track_order = $row->track_order; $new_track_order = $prev_track_order + 1; // Increase track_order of all following tracks $query = "UPDATE tracks SET track_order=track_order + 1 WHERE track_order > $prev_track_order AND moj_id = '$moj_id'"; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); $query = "INSERT INTO tracks(moj_id, track_no, track_title, track_artist, track_asinuk, track_asinus, track_order) VALUES ('$moj_id', '$track_no', '$track_title', '$track_artist', '$track_asinuk', '$track_asinus', $new_track_order)"; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); if (!$result){ echo "There was an error on the add_track_to_db page"; } else{ if(IS_AJAX) { echo $track_no . ': ' . $track_title . ' - ' . $track_artist . ' ::: ' . $track_asinuk . ' ::: ' . $track_asinus ; } } ?> All suggestions welcome. Thanks in advance. KN
  10. I have a form which can be submitted with two button options: <input type="button" name="submit1" id="submit1" value="Add and Close" /> <input type="button" name="submit2" id="submit2" value="Add and Add More" /> I then want a JQuery function to behave slightly differenly depending on which button has been pressed. Something along these lines: <script type="text/javascript" charset="utf-8"> $(':button').click(function() { var moj_id = $('#moj_id').val(); var track_no = $('#track_no').val(); var track_title = $('#track_title').val(); var track_artist = $('#track_artist').val(); var track_asinuk = $('#track_asinuk').val(); var track_asinus = $('#track_asinus').val(); $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus }, function(r) { $('<div class="overlay"></div>') .appendTo('#form_block') .fadeIn(1000, function() { $('<tr><td>' + r + '</td></tr>') //.hide() .appendTo('table#tracks') .fadeIn(1000, function() { if('#submit1'){ // should this be an if == true? $('#form_block').slideUp(1000, function() { $('.overlay').hide() }); } // end submit1 if if('#submit2'){ // should this also be an if == true? Or an else? $('.overlay').hide(); } // end submit2 if }); // clears form document.getElementById('form').reset(); // }); } ); return false; // disable submit click }); </script> But it's not working. Can anybody point out the errors in my syntax or am I going about this the wrong way completely? Thanks, KN
  11. I found out today that JQuery does not support animation in tables. Ho hum.
  12. Hi everyone, In the return function ® below, I cannot get the appended <tr> to slide down nicely. As it stands the <tr> just appears, which is fine but not the graceful effect I wanted. If I reinstate the hide() command it flickers crazily before appending. <script type="text/javascript" charset="utf-8"> $('#submit').click(function() { var moj_id = $('#moj_id').val(); var track_no = $('#track_no').val(); var track_title = $('#track_title').val(); var track_artist = $('#track_artist').val(); var track_asinuk = $('#track_asinuk').val(); var track_asinus = $('#track_asinus').val(); $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus }, function(r) { $('<div class="overlay"></div>') .appendTo('#form_block') .fadeIn(1000, function() { $('<tr><td>' + r + '</td></tr>') //.hide() .appendTo('table#tracks') .slideDown(1000, function(){ $('#form_block').slideUp(1000, function() { $('.overlay').hide() }); }); // clears form document.getElementById('form').reset(); // }); } ); return false; // disable submit click }); </script> Themeforest.net have a fix for a similar piece of code: .children(':last') .height($('#comments li:last').height()) But I'm not sure how to incorporate it in my script to found out if it is pertinent to my problem. Any ideas how I can make my new <tr> slideDown nicely? Cheers KN
  13. OK I've done a bit of error checking and I'm pretty sure the error is to do with this section: $('#submit').click(function() { var moj_id = $('#moj_id').val(); var track_no = $('#track_no').val(); var track_title = $('#track_title').val(); var track_artist = $('#track_artist').val(); var track_asinuk = $('#track_asinuk').val(); var track_asinus = $('#track_asinus').val(); $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus }, ... I expect it is due to the fact that as the page is unrefreshed, the script is actioning previous submit clicks as well. So what I need to know is how do I only allow it to fire the post once only for each submit click? Cheers, KN
  14. Hi everyone, The JQ form in tracks.php below is working fine on first submit. However a subsequent entry will append (and be entered into my database add_track_to_db.php) twice. A third time it will do it three times etc. Should I be clearing variables somehow or is a page refresh necessary? Any thoughts welcome, Thanks KN tracks.php <?php define ('ROOT', $_SERVER['DOCUMENT_ROOT']); // start session. Put it above define /* session_start('username'); $username = ($_SESSION['username']); */ ?> <!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=iso-8859-1" /> <meta http-equiv="Content-Language" content="EN" /> <meta name="charset" content="ISO-8859-1" /> <meta name="robots" content="index,follow" /> <meta name="copyright" content="Copyright © 2010" /> <link rel="shortcut icon" href="../images/favicon.ico" type="images/favicon" /> <link type="text/css" href="/style/mojo_home.css" rel="stylesheet" /> <script src="/style/jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript" src="/style/prepareImageSwap.js"></script> </head> <body> <?php if (isset($_POST['submit'])) { // nothing happens with these errors yet. Could apend to form or just highlight bad fields in red. $errorList = array(); if (trim($_POST['track_no']) == '') { $errorList[] = 'Invalid Entry: Track No.'; } if (trim($_POST['track_title']) == '') { $errorList[] = 'Invalid Entry: Track Title'; } if (trim($_POST['track_artist']) == '') { $errorList[] = 'Invalid Entry: Track Artist'; } // Check for errors. If none found go to add_to_db page and insert data. if (sizeOf($errorlist) == 0) { $moj_id = $_POST['moj_id']; $track_no = ($_POST['track_no']); $track_title = ($_POST['track_title']); $track_artist = ($_POST['track_artist']); $track_asinuk = (trim($_POST['track_asinuk'])); $track_asinus = (trim($_POST['track_asinus'])); include '../includes/add_track_to_db.php'; // } dont forget to put this back when reinstating error check } } ?> <div id = "wrapper"> <div id = "left"> <?php include (ROOT.'/includes/header.php'); include (ROOT.'/includes/conf.php'); // Check for issue number if(!isset($_GET['id']) || trim($_GET['id'] == '')) { trigger_error('No issue present' . mysql_error($db), E_USER_ERROR); } // Open DB connection $connection = mysql_connect($host, $user, $pass) or trigger_error('Unable to connect: ' . mysql_error($connection), E_USER_ERROR); // Select database mysql_select_db($db) or trigger_error('Unable to select database: ' . mysql_error($connection), E_USER_ERROR); // Retrieve current "issue" (Will be project dependent too) $id = $_GET['id']; $query = " SELECT moj_title, moj_date, moj_issue, moj_summary FROM mojocd WHERE moj_id = '$id'"; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); // There should only be one issue if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)){ ?> <p /> <div id="cover"> <img src="../images/<?php echo $id; ?>.jpg" width="200" height="200" alt="Mojo CD: <?php echo $row->moj_title; ?>" title="mojo CD: <?php echo $row->moj_title; ?>"/> </div> <!-- closes cover --> <div id="cover-text"> <h1 class="top"><?php echo $row->moj_title; ?></h1> <h2 class="top"><font size="4">Issue No. <?php echo $row->moj_issue; ?> (<?php echo $row->moj_date; ?>) </font></h2> <b><?php echo $row->moj_summary; ?></b> <?php } // end while } // end if else { ?> <font size="-1">NO ISSUE PRESENT</font> <?php } // end else ?> </div> <!-- close cover-text --> <div id = "content"> <?php // Retrieve the tracks $id = $_GET['id']; $query = " SELECT track_id, track_no, track_title, track_artist, track_asinuk, track_asinus FROM tracks WHERE moj_id = '$id' ORDER BY track_no "; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); ?> <p /> <?php // if records present if (mysql_num_rows($result) > 0) { ?> <p class="strap"><b>Links go directly to full artist's album on which each track appears</b> <!-- removed to allow simple list while experimenting <div="tracks-table"> <p> <table class = "tracks"> --> <ul id="tracks"> <?php while($row = mysql_fetch_object($result)) { echo '<li>' . $row->track_no . ': ' . $row->track_title . ' - ' . $row->track_artist . ' ::: UK:' . $row->track_asinuk . ' ::: US:' . $row->track_asinus . '</li>'; } // end while echo '</ul>'; } // end if (rows present) else { echo '<p /><b>NO TRACKS ENTERED.</b>'; } // end else ?> <a href="add_track.php?id=<?php echo $id; ?>" id="add">Add a "track"</a><p /> <!-- FORM CODE GOES HERE. IDEALLY IT WILL DROP OUT AS ANOTHER TABLE ITEM IN REAL THING $_SERVER['PHP_SELF']--> <div id="form_block"> <form action="tracks.php?id=<?php echo $id; ?>" method="post" id="form" name="form"> <input type="hidden" name="moj_id" id="moj_id" value="<?php echo $id; ?>"> <label for="track_no">Track No:</label> <input type="text" size="4" maxlength="4" name="track_no" id="track_no" value="<?php if (sizeOf($errorlist)== 0) { echo $_POST['track_no']; } ?>" /><br /> <!-- add this IF to all --> <label for="track_title">Track Title:</label> <input type="text" size="50" maxlength="254" name="track_title" id="track_title" value="<?php if (sizeOf($errorlist)== 0) { echo $_POST['track_title']; } ?>" /><br /> <label for="track_artist">Track Artist:</label> <input type="text" size="50" maxlength="254" name="track_artist" id="track_artist" value="<?php if (sizeOf($errorlist)== 0) { echo $_POST['track_artist']; } ?>" /><br /> <label for="track_asinuk">Amazon Asin UK:</label> <input type="text" size="50" maxlength="254" name="track_asinuk" id="track_asinuk" value="<?php if (sizeOf($errorlist)== 0) { echo $_POST['track_asinuk']; } ?>" /><br /> <label for="track_asinus">Amazon Asin US:</label> <input type="text" size="50" maxlength="254" name="track_asinus" id="track_asinus" value="<?php if (sizeOf($errorlist)== 0) { echo $_POST['track_asinus']; } ?>" /> <input type="submit" name="submit" id="submit" value="Add" /> </form> </div> <!-- end form_block --> <p /> <?php if (isset ($_GET['fromsearch'])) { ?> <br /> <form> <input type="button" value="Back to search results" onClick="history.back()"> </form> <?php } //end if (fromsearch) include(ROOT.'/includes/random_cds.php'); ?> </div> <!-- closes Content --> <!-- PAGE SPECIFIC CONTENT ENDS HERE --> <?php // Sidebar, Tag Cloud and Footer as include include(ROOT.'/includes/footer.php'); ?> </div> <!-- closes left --> <div id = "right"> <?php include (ROOT.'/includes/extra.php'); ?> </div> <!-- closes right --> </div> <!-- closes wrapper --> <?php include_once(ROOT.'/includes/analyticstracking.php'); ?> <script type="text/javascript" charset="utf-8"> $(function(){ $('a#add').click(function(){ $('#form_block').slideDown(1000); $('#submit').click(function() { var moj_id = $('#moj_id').val(), track_no = $('#track_no').val(), track_title = $('#track_title').val(), track_artist = $('#track_artist').val(), track_asinuk = $('#track_asinuk').val(), track_asinus = $('#track_asinus').val(); $.post('../includes/add_track_to_db.php', { 'moj_id' : moj_id, 'track_no' : track_no, 'track_title' : track_title, 'track_artist' : track_artist, 'track_asinuk' : track_asinuk, 'track_asinus' : track_asinus }, function(r) { $('<div class="overlay"></div>') .appendTo('#form_block') .fadeIn(1000, function() { $('<li>' + r + '</li>') .appendTo('ul#tracks') .hide() .slideDown(1000, function(){ $('#form_block').slideUp(1000, function() { $('.overlay').hide() }); }); // clears form document.getElementById('form').reset('track_no', 'track_title', 'track_artist', 'track_asinuk', 'track_asinus'); // }); } ); return false; // disable submit click }); return false; }); }); </script> </body> </html> add_track_to_db.php <?php include ('conf.php'); if(IS_AJAX) { $moj_id = $_POST['moj_id']; $track_no = $_POST['track_no']; $track_title= $_POST['track_title']; $track_artist= $_POST['track_artist']; $track_asinuk= "Its JQ"; // $_POST['track_asinuk']; $track_asinus= $_POST['track_asinus']; } $connection = mysql_connect($host, $user, $pass) or trigger_error('Unable to connect: ' . mysql_error($connection), E_USER_ERROR); // select database mysql_select_db($db) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); // generate and execute query $query = "INSERT INTO tracks(moj_id, track_no, track_title, track_artist, track_asinuk, track_asinus) VALUES ('$moj_id', '$track_no', '$track_title', '$track_artist', '$track_asinuk', '$track_asinus')"; $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($connection), E_USER_ERROR); $_POST = array(); if (!$result){ echo "There was an error on the add_track_to_db page"; } else{ if(IS_AJAX) { /* echo '<h3>' . $track_title . '</h3>'; echo '<li>' . $row->track_no . ': ' . $row->track_title . ' - ' . $row->track_artist . ' ::: UK:' . $row->track_asinuk . ' ::: US:' . $row->track_asinus . '</li>'; echo '<p>' . $track_artist . '</p>'; */ echo $track_no . ': ' . $track_title . ' - ' . $track_artist . ' ::: UK:' . $track_asinuk . ' ::: US:' . $track_asinus; } /* else{ header("location:ROOT.'/pages/tracks.php?id=$moj_id'"); } */ } ?>
×
×
  • 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.