Jump to content

yobo

Members
  • Posts

    87
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

yobo's Achievements

Member

Member (2/5)

0

Reputation

  1. yobo

    Mysql Join Issue

    Thanks Barand, But I am still getting errors; mysql> select postname, name from posts p join lookup l on p.id = l.postid join postcategory c on l.categoryid = c.id; ERROR 1146 (42S02): Table 'p3-blog.lookup' doesn't exist mysql> select postname, name from posts p join category l on p.id = l.postid jo in postcategory c on l.categoryid = c.id; ERROR 1054 (42S22): Unknown column 'l.postid' in 'on clause' mysql> select postname, name from posts p join postcategory l on p.id = l.posti d join postcategory c on l.categoryid = c.id; ERROR 1054 (42S22): Unknown column 'name' in 'field list' mysql> select postname from posts p join postcategory l on p.id = l.postid join postcategory c on l.categoryid = c.id; I have replaced the names with my tables: my lookup table is called 'postcategory' my category table is called 'category' and my posts table is called 'posts'
  2. yobo

    Mysql Join Issue

    Thanks Barand for your help however I am still getting errors, from folling your guidance, my lookup table is called 'postcategory' my category table is called 'category' and my posts table is called 'posts' using your sQL above mysql> select postname, name from posts p join lookup 1 on p.id = 1.postid join postcategory c on 1.categoryid = c.id; I get a Mysql error.
  3. Hello All, I am working on a small PHP / Mysql project and I have ran aground on this issue, and I am looking for some advice as to why this is not working. What I am trying to acheive is to show a list of blog post titles, along with their respective categories that they are assigned too, However I am unable to get my query to work. below are my 3 tables structure: The Posts table +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | postname | varchar(255) | NO | | NULL | | | postcontent | varchar(255) | NO | | NULL | | | postdate | date | NO | | NULL | | | authorid | int(11) | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ The Category Table +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | NO | | NULL | | +-------+--------------+------+-----+---------+----------------+ The Lookup table +------------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------+------+-----+---------+-------+ | postid | int(11) | NO | PRI | 0 | | | categoryid | int(11) | NO | PRI | 0 | | +------------+---------+------+-----+---------+-------+ My query mysql> select id, postname from posts join postcategory on posts.id = categoryid; Empty set (0.00 sec) so far example it should look like this on the web page Post Name Post Category Linux DNS How Too Linux Windows 10 Hacks Windoiws Again grateful for any help. Joe
  4. Hey All, I am having some issues my data gets added to the database ok but since I am using a header redirection (to clear the $_post variable) my success message is not displayed or my error if there is an error. Basically I would like my message to be displayed just above the form to say success it worked or error if it did not. header("Location: addproduct.php"); echo ' <div class="span9" id="content"> <div class="alert alert-success"> <div id="success"><p>Product has been added to the database</p></div> </div> </div>'; exit; the above code is a snippet of my main code I am also using ajax to help with this. my simple ajax code $('#btnSave').click(function() { $.post($("#addproduct").attr("action"), data, function(info){ $("#success").html(info); }); clearInput()); }); $("#addproduct").submit( function() { return false; }); function clearInput() { $("#addproduct :input").each( function() { $(this).val(''); }); } Many Thanks J
  5. Hey All, I am in the process of learning PHP so I am not an expert by any means. I am looking for some advice on how I would go about implementing this idea. 1. I have a page called addproduct.php with a form and which also includes the header.php file 2. when the form is submitted on the addproduct.php it goes to the database processing script called addproduct-func.php, 3. the addproduct-func.php page has a conditional that checks to see if the database query succeeded if so it redirects using the header function back to addproduct.php. however what I would like to implement is some form validation and checking before it gets submitted to the addproduct-func.php and only if validation and form checking passes then goto addproduct-func.php. I also would like to output a little success msg informing the user that the record had been added to the database just above the addproduct.php form. I am using bootstrap as my css framework. Many Thanks for your time and help J
  6. Hey All I have a page where a users types in a number and using Ajax if that number exsist in the DB it will say on the same page "this record was found in the DB click here to view this record" and the opposite happens if the record does not exsist instead of view the record a link says "not found click here to create this record" now this is where I cant seem to find solutions in my Ajax books at the moment when a user clicks the link it goes to the correnponding page example "addrecord.php or viewrecord.php" what I would like is for a popup to show with the content of those pages rather than going to the seperate pages unless JS has been disabled. hope that kinda makes sense Joe
  7. Hey All, I am making a small application to help me learn, my question is this I am making a page where the users enters a number asset number that is they click submit and if that record exsists it will have a link underneath the input box saying record found click here to view details if the record does not exsist there will be a link saying record not found click here to add the record. my problem is that I dont know how to do this on one page I can do it with seperate pages but not sure how to do it on one any ideas please? Joe
  8. Hey Guys, I am having a strange issue I have a form where a user can enter there name and it will echo it out on the next page (it is a bigger script but i am doing some testing bit by bit) The form page <form action="includes/runtime.php" method="post"> <p>Asset ID: <input type="text" name="asset_id" size="15" maxlength="20" value="<?php echo $_GET['asset_id'];?>" /></p> <label>Select Hardware Type:</label><select name="hw_type"> </select> <input type="hidden" name="rma_status" size="20" maxlength="20" value="New"/> <p>Submitter Name: <input type="text" name="name" size="20" maxlength="20"/></p> <p>Fault Description: <textarea name="fault_desc" rows="20" cols="30"></textarea></p> <p><input type="submit" name="submit" value="Add Record" /></p> <input type="hidden" name="newrma" value="new"/> </form> and the runtime page code foreach ($_POST as $key => $value) { $post[$key] = $value; echo $post['name']; } basically it echos the value of name but outputs 4 copies for example if i added name john it would output JohnJohnJohnJohn I only need it to output the once any ideas J
  9. hey all, I use to have a msg output to the screen to inform the user that there file had been uploaded but i needed to add a bit of code to stop the same data been added to the database trice when the page was refreshed so I added a header redirection to the same page now the msg will not be outputted this is what I have. echo "<br>File $fileName uploaded<br>"; header("Location: http://localhost/php/upload.php"); the above snippet is my code
  10. Hey dude, that dont really help me? since there examples have hard coded mutiple input fileds for files where as mine does not mine uses jquery and php to allow for one file to be uploaded mandatory and an option to add another upload file input box if necssary. Joe
  11. Hey all, I have created an upload script that allows the user to upload a file using this same page if the user wants to upload another file at the same time they click a button and it will create an extra file upload box built using jquery. now this seems to work but I am having problems with my php code taking the upload file(s) add adding them to the database. I have attached my Code along with the javascript code that i am using. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="ohyeah" /> <title>Untitled 1</title> <script src="includes/jquery.js" type="text/javascript"></script> <script src="includes/upload.js" type="text/javascript"></script> </head> <body> <?php /** * @author ohyeah * @copyright 2011 */ if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { foreach($_FILES['userfile']['error'] as $key => $error) { $tmpName = $_FILES['userfile']['tmp_name'][$key]; $fileName = $_FILES['userfile']['name'][$key]; $fileSize = $_FILES['userfile']['size'][$key]; $fileType = $_FILES['userfile']['type'][$key]; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } } //include 'library/config.php'; include ('includes/dbconnect.php'); $query = "INSERT INTO uploads (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysqli_query($dbc, $query); mysqli_close($dbc); echo "<br>File $fileName uploaded<br>"; } ?> <form action="upload2.php" method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <div id="text"> <div ><input name="userfile[]" type="file" /></div> <!-- This is where the new file field will appear --> </div> <input type="button" id="add-file-field" name="add" value="Add input field" /> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload " /></td> </tr> </table> </form> </body> </html> the java script code $(document).ready(function(){ // This will add new input field $("#add-file-field").click(function(){ $("#text").append("<div class='added-field'><input name='userfile[]' type='file' /><input type='button' class='remove-btn' value='Remove Field' /></div>"); }); // The live function binds elements which are added to the DOM at later time // So the newly added field can be removed too $(".remove-btn").live('click',function() { $(this).parent().remove(); }); }); thanks for your help
  12. thanks all for your help and PFMaBiSmAd thanks for clearing that up for me
  13. Hey all this is my source html source code that is <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>View File</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body> <p>Click a file to download</p> <table align="center" cellspacing="5" cellpadding="5" border="1"> <tr> <td align="center"><b>File Name</b></td> <td align="center"><b>File Size</b></td> </tr> <tr> <td><a href="C:/wamp/uploads/101_LPIC1_Mega_Guide.zip">101_LPIC1_Mega_Guide.zip</a></td> <td>753kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Blue+hills.jpg">Blue+hills.jpg</a></td> <td>28kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Symfony2-QuickTour.pdf">Symfony2-QuickTour.pdf</a></td> <td>131kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Winter.jpg">Winter.jpg</a></td> <td>103kb</td> </tr> </table> </body> </html>
  14. Hey all, this kinda relates to my upload script problem but in some what way different I have now created a download script a small one that pulls the details of the files that where uploaded and places them with a link in a html table, now it creates the link ok but when I click the link nothing happens? <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>View File</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body> <p>Click a file to download</p> <table align="center" cellspacing="5" cellpadding="5" border="1"> <tr> <td align="center"><b>File Name</b></td> <td align="center"><b>File Size</b></td> </tr> <?php /** * @author ohyeah * @copyright 2011 */ $dir = 'C:/wamp/uploads/'; $files = scandir($dir); foreach($files as $filedownload){ if(substr($filedownload, 0, 1) != '.'){ $file_size = round((filesize("$dir/$filedownload")) / 1024) . "kb"; $filedownload = urlencode($filedownload); echo "\t<tr> \t\t<td><a href=\"$dir$filedownload\">$filedownload</a></td> \t\t<td>$file_size</td> \t</tr>\n"; } } ?> </table> </body> </html>
  15. Hey MrAdam, Thanks for the tip about the file extension validation input rather than what I was doing before hand ,it worked. this is what i changed if ($_FILES['upload']['type'] == 'zip' || 'pdf') {do stuff here} Joe
×
×
  • 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.