
Copilot π€
Members-
Posts
22 -
Joined
-
Last visited
Never
Everything posted by Copilot π€
-
I just don t see how to link fileds of one table to another table
franklos replied to franklos's topic in MySQL Help
Been busy, finally found some time Here s tha table with the compostions: composers Field Type Null Default Comments MIME idcomp int(10) No Composer varchar(255) Yes NULL Birth varchar(255) Yes NULL Nationality varchar(255) Yes NULL Opus varchar(255) Yes NULL Publisher varchar(255) Yes NULL Oddities varchar(255) Yes NULL Fname varchar(255) Yes NULL Lname varchar(255) Yes NULL information varchar(25000) No Indexes: Keyname Type Unique Packed Field Cardinality Collation Null Comment idcomp BTREE No No idcomp 0 A Publisher BTREE No No Publisher 323 A YES Here the one with the publshing companies: publisher Field Type Null Default Comments MIME idpub int(10) No abbreviation varchar(30) Yes NULL country varchar(255) Yes NULL street varchar(255) Yes NULL postcode varchar(255) Yes NULL city varchar(255) Yes NULL address varchar(255) Yes NULL name varchar(255) Yes NULL website varchar(255) Yes NULL email varchar(255) Yes NULL oddities varchar(255) Yes NULL phone text Yes NULL Indexes: Keyname Type Unique Packed Field Cardinality Collation Null Comment idpub BTREE No No idpub 0 A abbreviation BTREE No No abbreviation 0 A YES So I created a table called compositions: composition Field Type Null Default Comments MIME id int(10) No abbreviation varchar(255) No composer varchar(255) No idcomp int(11) No idpub int(11) No Opus varchar(255) No Indexes: Keyname Type Unique Packed Field Cardinality Collation Null Comment id BTREE No No id 2 A I started to try and construct a query and ended up with this: INSERT INTO composition (idcomp,Opus) SELECT idcomp,Opus FROM quartets Off course it just copied all the data into the latter table, and In think I need to somehow split the composers and their compostions -> the compostitions table all having the same ID on that table? Is that correct? How do I do that with a query? -
I just don t see how to link fileds of one table to another table
franklos replied to franklos's topic in MySQL Help
Hmm is there a way to do stuff like that with a querry, or should I just split 900 composer/compostion records manually and add composer ID s manually? Sound like a hell of a job. -
I just don t see how to link fileds of one table to another table
franklos replied to franklos's topic in MySQL Help
so you mean a table for the compositions, one for the composers and one for publishers? Compositions holding an ID of the composer and an ID of the publisher. Composer holding a ID of the compositions? Something like that -
I just don t see how to link fileds of one table to another table
franklos replied to franklos's topic in MySQL Help
okay but thing is the tables have one field in common. The "publisher field in the table composer" equals the "name field in the table publisher". I was hoping these two could be eh linked? -
Hi I ve been trying this for a while but seem to get nowhere. A have two tables one composer and one publishers, the latter publishes sheet music from the fist. composers contains id fname lname date of birth name of composition publisher publishers contains id name website address phone email I would like to diplay a link to the publisher details (stored in the publisher table) on the web page of a composer. So when you EG click dvorack opus 9 in bes, the name of the publisher diplayed on that particular page would link to the details of that publisher. I thinks I read I need to do a JOIN ar use a foreign key, tried all to no avail. Can someone give me a wee push in the right direction or even better write a little PHP example so I can continue this search. Google and the likes have been tried off course, cheers.
-
Hi, two questions First I have two tables one containing composers and one their publsher details. The site owner now would like to have the option (will it ever stop) to be able to click from the composer details "publisher name" (field:publisher) to the publisher details(through field:abbreviation) from the second table.Also it would be great to get a dropdown list of the available publishers in the composer modification / add new form. (is that a total of three qustions?) Second I would like the option to upload an image of the composer with the URL stored in that table. So we can retrieve that picture if we view the composer details. For the first I found some stuff, related to foreign key etc, but can, t see how to create a foreign key. FOr thye second I have found an upload script but don' t see how to couple that with the ID of that composer. Thanks, Frank. Here s the tables Composers: idcomp int(10) No Composer varchar(255) Yes NULL Birth varchar(255) Yes NULL Nationality varchar(255) Yes NULL Opus varchar(255) Yes NULL Publisher varchar(255) Yes NULL Oddities varchar(255) Yes NULL fname varchar(255) Yes NULL lname varchar(255) Yes NULL Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 947 idcomp Publishers: idpub int(11) No abbreviation varchar(30) Yes NULL country varchar(255) Yes NULL street varchar(255) Yes NULL postcode varchar(255) Yes NULL city varchar(255) Yes NULL address varchar(255) Yes NULL name varchar(255) Yes NULL website varchar(255) Yes NULL email varchar(255) Yes NULL oddities varchar(255) Yes NULL phone text Yes NULL Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 121 idpub abbreviation INDEX 121 abbreviation And the picture upload script: <?php //start image uploader //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, otherwize we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="images/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { echo "<h1>File Uploaded Successfully! Try again!</h1>"; } ?> <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> //end image uploader
-
@Maq, thanks for your script, finally it does delete. Still some errors but hey one step at a time. Thanks all. PS attached an image of the page I see when I hit submit and deletion is done. [attachment deleted by admin]
-
hi, don't know if this is related, but if I delete, it deletion does not seem to update the row numbers. Before a delete I can add a publisher. Once I deleted a publisher I get a "Could not run query: Duplicate entry '122' for key 1 " error. Have a nice weekend, Frank.
-
Hi It does work but.... I had to comment out //mysql_free_result($result); supplied argument is not a valid MySQL result resource ? huh? And the page that should mention that "the record has been deleted" also states it has "the record has not been deleted" and it turns back to an empty page with the submit form? Strano. Thanks loads so far, Frank.
-
Hi an "almost" winner then, now get ' the record has NOT been deleted" I don t see where I should put your bit of code in the following. What a mountain to climb for me... <?php $idpub = $_POST['idpub']; session_start(); if (isset($_POST['idpub'])) { //User has made a decision on the deletion confirmation if($_POST['button1']=='Yes') { //User confirmed the deletion include('connections.php'); $idpub = mysql_real_escape_string($_POST['idpub']); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); mysql_free_result($result); echo "The record has been deleted."; } else { //User selected NOT to delete. Redirect somewhere else echo "The record has NOT been deleted."; } //Confirmation process complete exit(); } else if (isset($_GET['idpub'])) { //Record passed on the query string for deletion //NOTE: You will need to correct this code for the right field names include('connections.php'); $idpub = mysql_real_escape_string($_GET['idpub']); //Get the name and abbreviation for the form $sql = "SELECT name, abbreviation FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); $record = mysql_fetch_assoc($result); $name = $record['name']; $abbreviation = $record['abbreviation']; } else { //No id passed on GET or POST - error handling echo "No record selected"; //exit(); } ?> <html> <body> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table border="1" cellpadding="0" cellspacing="0" width="500"> <tr> <td> <p class="bodytext"> You have selected '<B><?php echo $abbreviation; ?></B>' for deletion. Do you want to continue with the delete action? </p> </td> </tr> <tr><td> </td></tr> <tr> <td> <input id="button1" type="submit" value="Yes" name="submit"> <input id="button2" type="submit" value="No" name="submit"> <input type="hidden" value=<?php echo $idpub;?> name="idpub"> </td> </tr> </table> </form> </body> </html>
-
Hi, so I changed the pubdelete.php with the echo $sql, like so <? include('connections.php'); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; echo $sql; $result = mysql_query($sql); echo "Publisher deleted!"; //exit to make sure the script stops! exit(); ?> On clicking "ΓΏes" (delete publisher) that returns: DELETE FROM publisher WHERE idpub=Publisher deleted! so the idpub is not passed on to the pudelete.php? While on the page with the buttons the source shows this: [code <input id="button1" type="submit" value="Yes" name="submit"> <input id="button2" type="submit" value="No" name="submit"> <input type="hidden" value="123" name="idpub"> idpub is the id from that publisher table, so integer.
-
Hi Gizmola, I know it is all basic and maybe someday it will get up to standard. This was to be a simple site but things ran out of control. Anyway here' s my connections.php. Let me know whats wrong and how to debug if you find the time or feel like it. <?php $sqlConn = mysql_connect('localhost','user','password'); if (!$sqlConn) { die ('unable to connect' . mysql_error()); } $db = mysql_select_db('database', $sqlConn); //sets encoding to utf8 mysql_query("SET character_set_client = utf8;"); mysql_query("SET character_set_results = utf8;"); ?> As for the codes that I gracefully use, written above. It looks like whatever I click it returns the "User selected NOT to delete" button. I have got the feeling the $idpub = mysql_real_escape_string($_GET['idpub']); does not pickup a value. Thanks all, Frank.
-
Hi, the file posted is the pudelete.php. As said I am a total newbie to PHP and the scripts I use ( add pub(blisher), mod(ify) publisher) all have the same (apparently) unsafe method of handeling data. If you want you can see what I am doing eh trying to do on www.pianoquartet.nl/test for deletion you would need a login which off course I can not provide here. Anyway when clicking delete (if logged in) the page containing the delete submission button. The source shows the hidden input type with the correct value. But deletion is not done. I will try to see what I can do. A learning process. Thanks
-
<sweating more> Could it just be that I am completly dumb. SHould the above script be divided in two scripts? One the deletion form and one doing the deletion action?
-
<starts sweating>Hi, made a mistake that script seems to be okay, have I still got the right of a futher question? Deletion still does not function so I guess it must be in the pubdelete.php. Probably full off mistakes but I am trying hard. <? $idpub = $_GET['idpub']; include('connections.php'); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql); echo "Publisher deleted!"; //exit to make sure the script stops! exit(); ?> <off for a shower> thanks
-
Hi Haku, the connection is done through connection.php and runs fine for all the other scripts. Problem seems the mysql_real_escape_string() . But i am a complete newbie, thanks anyway
-
here are the errors: And the include('connections.php'); is right before that line. Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'hike'@'localhost' (using password: NO) in /usr/home/pianonl/public_html/assets/snippets/nbscripts/readdir.php on line 29 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /usr/home/pianonl/public_html/assets/snippets/nbscripts/readdir.php on line 29 Warning: mysql_query() [function.mysql-query]: Access denied for user 'hike'@'localhost' (using password: NO) in /usr/home/pianonl/public_html/assets/snippets/nbscripts/readdir.php on line 33 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /usr/home/pianonl/public_html/assets/snippets/nbscripts/readdir.php on line 33 Access denied for user 'hike'@'localhost' (using password: NO)
-
Hi one last question, $idpub = mysql_real_escape_string($_POST['idpub']); gives a login error Access denied for user 'hike'@'localhost' (using password: NO) Googles and found it could be a connection problem, however the line just before this line connects to the database. Anyway its a challenge, thanks, Frank.
-
Hi, you are right about the minimum ability to debug etc. I am currently trying to study PHP from here http://devzone.zend.com/article/627-PHP-101-PHP-For-the-Absolute-Beginner. So i hope to understand more aout them curley brackets, question marks, etc in the comming time. however it seems difficult (but fun) to me. Thanks again, Frank.
-
Hi looks nice your site. Did you however try to make the browser window smaller in IE7? Your content div width gets very narrow. Give it at least some (min) width. In FF the content div seems to get overlapped by the rightnav div. when resizing the window. Should be easy to fix that, no? cheers, frank.
-
Thanks for your time. However, it seems not much has changed. Also in the statusbar for most of the actions I see the var s that are sent with the action. (pubchar, pubid etc) Do not see those with the altered script. Below the code of the pubdelete.php. I see publisher deleted, when clicking "yes" delete but also on "no" (those buttons). Also this confirmation no longer is inside the site but on a white page. So the CSS is no longer there? Hope there is some TYPO I made. <? include('connections.php'); $idpub = $_GET['idpub']; $pubchar = $_GET['pubchar']; $idpubdelete = $_GET ['idpdel']; $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql); echo "Publisher deleted!"; //exit to make sure the script stops! exit(); ?>
-
Hi I need to finnish of this site. Unexpected it needed a database and PHP scripts. A friend created some scripts adn I altered them to use them with the CMS I use. (came from Typo3 I use Modx) The problem is in a form that needs to enable folks to delete data. Problem is that deletion works, but the data is also deleted when clicking "no do not delete". Got the script attached. Hopefully there are some stupid errors in this script, attached! gr Frank. [attachment deleted by admin]