Jump to content

layman

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Everything posted by layman

  1. Thank you! I think I need some sleep, it is 1.32 am here... Thanks again, really appreciate your help! All the very best, Layman
  2. Thank you! I changed it to decimal(7,2), but still getting an error. #1064 - 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 'text not null default '', Product_price decimal(7,2) not null default '', Pr' at line 5 Do you see what the problem is with my table? CREATE TABLE Products ( Grp ENUM('Motherboard', 'HardDrive', 'Processor', 'RAM', 'GraphicCard', 'SoundCard', 'USBPort', 'RouterSwitch', 'Server', 'PowerAdaptor', 'Webcam', 'OperatingSystem', 'Software', 'CaseStyle', 'Speaker', 'FloppyDrive', 'OpticalStorage', 'Monitor', 'Printer', 'Mouse', 'Keyboard') NOT NULL, Serialno varchar(20) not null default '', Product_name varchar(50) not null default '', Product_description varchar(50)text not null default '', Product_price decimal(7,2) not null default '', Product_review varchar(70), Product_brand varchar(30), Product_type varchar(30), Product_speed varchar(30), Product_size varchar(30), Product_dimensions varchar(30), Product_on_board_dev varchar(30), Product_form_factor varchar(30), Product_FSB varchar(30), Product_secu_spec varchar(30), Product_techn_stand varchar(30), Product_maxres varchar(30), Product_colour varchar(30), Admin_id int(4) not null, key Serialno(Serialno), PRIMARY KEY (Serialno), FOREIGN KEY (Admin_id) references SYSTEM_ADMIN(Admin_id) on update cascade on delete cascade ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  3. Hello, Could you tell me why is this code not working? I appreciate any help! Thanks. The error I am getting is: #1064 - 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 'number(5) not null default '', Product_review text(100), Product_brand var' at line 6 Server version: 5.1.41 I have created already the SYSTEM_ADMIN table I am referencing, so that one should not be the problem. Can not see what is the problem with line 6. Can anyone spot it? CREATE TABLE Products ( Grp ENUM('Motherboard', 'HardDrive', 'Processor', 'RAM', 'GraphicCard', 'SoundCard', 'USBPort', 'RouterSwitch', 'Server', 'PowerAdaptor', 'Webcam', 'OperatingSystem', 'Software', 'CaseStyle', 'Speaker', 'FloppyDrive', 'OpticalStorage', 'Monitor', 'Printer', 'Mouse', 'Keyboard') NOT NULL, Serialno varchar(20) not null default '', Product_name text(100) not null default '', line 6 Product_description text(100) not null default '', Product_price number(5) not null default '', Product_review text(100), Product_brand varchar(30), Product_type varchar(30), Product_speed varchar(30), Product_size varchar(30), Product_dimensions varchar(30), Product_on_board_devices varchar(30), Product_form_factor varchar(30), Product_FSB varchar(30), Product_secu_spec varchar(30), Product_techn_stand varchar(30), Product_maxres varchar(30), Product_colour varchar(30), Admin_id int(4) not null, key Serialno(Serialno), PRIMARY KEY (Grp, Serialno), FOREIGN KEY (Admin_id) references SYSTEM_ADMIN(Admin_id) on update cascade on delete cascade ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  4. Hi I don`t understand. How should I make a foreign key if not like this?
  5. Hello, Could anyone tell me what is wrong with this code? Thanks for any help! The error I am getting is: #1072 - Key column 'Login_id' doesn't exist in table Server version: 5.1.41 I have created already the Login_detail table I am referencing, so that one can not be the problem. Or can be??? CREATE TABLE IF NOT EXISTS CUSTOMERS ( Customer_id int(4) not null auto_increment, Customer_name varchar(80) not null default '', Customer_address1 varchar(50) not null default '', Customer_address2 varchar(50) not null default '', Customer_town varchar(50) not null default '', Customer_postcode varchar(9) not null default '', Customer_county varchar(30) not null default '', Customer_country varchar(30) not null default '', Customer_phoneno int(14) not null, Customer_email varchar(50) not null default '', key Customer_id (Customer_id), PRIMARY KEY (Customer_id), FOREIGN KEY (Login_id) references login_detail(Login_id) on update cascade on delete cascade ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  6. Yes, that is what I would like to do! Is this the right way to represent one to many relationships?
  7. Thank you! It was accepted! So if I want to relate Order_no to the Customer_id from the Customer table, it should be always like this? I mean at the Foreign key part? I thought it has to be the customer id... CREATE TABLE ORDERS ( Orders_no int(6) not null auto_increment, Orders_date date default '0000-00-00', key Orders_no (Orders_no), PRIMARY KEY (Orders_no), FOREIGN KEY (Orders_no) references CUSTOMER(Customer_id) on update cascade on delete cascade ) ENGINE=INNODB AUTO_INCREMENT=1;
  8. Thank you. Put an "s" behind, so now the table is Orders. But still getting the same error! #1072 - Key column 'Customer_id' doesn't exist in table Could you help me why? Thanks for any help. CREATE TABLE ORDERS ( Orders_no int(6) not null auto_increment, Orders_date date default '0000-00-00', key Orders_no (Orders_no), PRIMARY KEY (Orders_no), FOREIGN KEY (Customer_id) references CUSTOMER(Customer_id) on update cascade on delete cascade ) ENGINE=INNODB AUTO_INCREMENT=1;
  9. Hello, Could you help me why is my CREATE TABLE statement not working? CREATE TABLE ORDER ( Order_no int(6) not null auto_increment, Order_date date default '0000-00-00', key Order_no (Order_no), PRIMARY KEY (Order_no), FOREIGN KEY (Customer_id) references CUSTOMER(Customer_id) on update cascade on delete cascade ) ENGINE=INNODB AUTO_INCREMENT=1; The error I am getting is: #1064 - 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 'ORDER ( Order_no int(6) not null auto_increment, Order_date date default '00' at line 1 Server version: 5.1.41 I have created already the Customer table I am referencing, so that one can not be the problem. Also I took out the default date, but got the same error. Thanks for any help!
  10. I got, its WORKING!! Thank you very much for everyone for the contribution. Again, I learned a lot from you guys! Thanks again. All the very best, layman
  11. Notice: Use of undefined constant getResult - assumed 'getResult' in C:\xampp\htdocs\cwk\Class_Student_Course_Proba.php on line 29 Notice: Use of undefined constant getResult - assumed 'getResult' in C:\xampp\htdocs\cwk\Class_Student_Course_Proba.php on line 29 Notice: Undefined variable: esc_grade in C:\xampp\htdocs\cwk\Student_Course_Update.php on line 66 Notice: Undefined variable: esc_comments in C:\xampp\htdocs\cwk\Student_Course_Update.php on line 66 Notice: Undefined variable: esc_sid in C:\xampp\htdocs\cwk\Student_Course_Update.php on line 66 Notice: Undefined variable: esc_cid in C:\xampp\htdocs\cwk\Student_Course_Update.php on line 66 UPDATE studentcourses set grade='', comments='' where sid='' and cid='' Notice: Undefined variable: numofrows in C:\xampp\htdocs\cwk\Student_Course_Update.php on line 71 Success. Number of rows affected: I have defined the constant on line 29. Line 66 is: $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid='{$esc_sid}' and cid='{$esc_cid}'"; Line 71 is: echo "Success. Number of rows affected: <strong>{$numofrows}</strong>"; //in this row
  12. I got the line, where the error is, but I can not see what is wrong here. $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid='{$esc_sid}' and cid='{$esc_cid}'"; And also here: echo "Success. Number of rows affected: <strong>{$numofrows}</strong>"; //in this row Could anyone point the it out for me what am I doing wrong? Thank you.
  13. I have looked for the syntax, but what I am trying is not working. http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting Is this the right syntax? function display_errors() { on; } error_reporting(E_ALL); display_errors(on);
  14. And where should I set this error reporting? Is that goes straight after the opening PHP tag?
  15. This was the output: Debugging output: Array ( [sid] => 4 [cid] => 10 [grade] => B [comments] => Comment ) End debuggingUPDATE studentcourses set grade='', comments='' where sid='' and cid=''Success. Number of rows affected: Do you know what does this mean? I have sid 4 in the student table so there is a record which should have been updated.
  16. Thanks. I just corrected them. I do not understand why I am not able to update any data via this form. I made all the corrections suggested here. The function looks like now this: function update_student_course($sid, $cid, $grade, $comments) { $esc_sid = mysql_real_escape_string($sid, $this->conn); $esc_cid = mysql_real_escape_string($cid, $this->conn); $esc_grade = mysql_real_escape_string($grade, $this->conn); $esc_comments = mysql_real_escape_string($comments, $this->conn); $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid='{$esc_sid}' and cid='{$esc_cid}'"; $result = mysql_query($sql, $this->conn); if (!$result) die("SQL Error: " . mysql_error()); else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } And the code after all the corrections looks like this: <?php $db1 = new student_course(); $db1->openDB(); $sql = "SELECT sid FROM STUDENTS"; $result1 = $db1->getResult($sql); $sql = "SELECT cid FROM COURSES"; $result2 = $db1->getResult($sql); if (!$_POST) { //page loads for the first time ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Choose student ID: <select name="sid"> <?php while ($row = mysql_fetch_array($result1)) echo "<option value='{$row['sid']}'>{$row['sid']}</option>"; ?> </select><br/> Choose course ID: <select name="cid"> <?php while ($row = mysql_fetch_array($result2)) echo "<option value ='{$row['cid']}'>{$row['cid']} </option>"; ?> </select><br/> Enter grade to update: <input type="text" name="grade" /><br /> Enter new comment: <input type="text" name="comments" /><br /> <input type="submit" value="Update" /> </form> <?php } //end if else { $sid = $_POST['sid']; $cid = $_POST['cid']; $grade = $_POST['grade']; $comments = $_POST['comments']; $db1 = new student_course(); $db1->openDB(); //$numofrows = $db1->update_student_course($sid, $cid, $grade, $comment); $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid='{$esc_sid}' and cid='{$esc_cid}'"; echo $sql; $result = mysql_query($sql); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> Could anyone explain the problem in very simple terms, so I`ll understand it. Thank you.
  17. I have corrected the name=attributes. Thanks! I have changed the comment to comments. But I can`t find the other one. Could you give me some clues please? What do you mean by that, which ones are the same?
  18. What if it does not contains the values? I got this back: UPDATE studentcourses set grade='', comments='' where sid='' and cid=''Success. Number of rows affected: Could you explain me in simple terms what am I doing wrong please?
  19. Thanks! I left them out... Now I got no error. However, the update is still not happening in the database. Any idea why??
  20. Hello Everyone I`m new to PHP, therefore I would really appreciate any help with this code. The error message I get: SQL Error: 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 'where cid=B' at line 1 This is the function, I`m trying to use: function update_student_course($sid, $cid, $grade, $comments) { $esc_sid = mysql_real_escape_string($sid, $this->conn); $esc_cid = mysql_real_escape_string($cid, $this->conn); $esc_grade = mysql_real_escape_string($grade, $this->conn); $esc_comments = mysql_real_escape_string($comments, $this->conn); $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid={$esc_sid} and cid={$esc_cid}"; $result = mysql_query($sql, $this->conn); if (!$result) die("SQL Error: " . mysql_error()); else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } And this would be the code: <?php $db1 = new student_course(); $db1->openDB(); $sql = "SELECT sid FROM STUDENTS"; $result1 = $db1->getResult($sql); $sql = "SELECT cid FROM COURSES"; $result2 = $db1->getResult($sql); if (!$_POST) { //page loads for the first time ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Choose student ID: <select name = "sid"> <?php while ($row = mysql_fetch_array($result1)) echo "<option value='{$row['sid']}'>{$row['sid']}</option>"; ?> </select><br/> Choose course ID: <select name = "cid"> <?php while ($row = mysql_fetch_array($result2)) echo "<option value ='{$row['cid']}'>{$row['cid']} </option>"; ?> </select><br/> Enter grade to update: <input type="text" name="cid" /><br /> Enter new comment: <input type="text" name="cname" /><br /> <input type="submit" value="Update" /> </form> <?php } //end if else { $sid = $_POST['sid']; $cid = $_POST['cid']; $grade = $_POST['grade']; $comment = $_POST['comment']; $db1 = new student_course(); $db1->openDB(); $numofrows = $db1->update_student_course($sid, $cid, $grade, $comment); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> Any idea, what am I doing wrong??? Server version: 5.1.41 Thank you very much in advance, for taking the time and reading it!!! layman
  21. Dear cyberRobot, Yeah, got them mixed up, corrected it, and voila! IT IS WORKING!!! Thank you very much for your time and answers, I really appreciate, what you did for me! You know I only started to learn PHP a month ago, I know, I am an amateur..., but with your help, I have learned a lot recently! Thanks again! All the very best to you, layman
  22. I managed to sort of insert SOME data to my studentcourse!!! I have changed the table. The message I get back is: INSERT INTO studentcourses (SID, CID, GRADE, COMMENTS) VALUES ('5', '3', '', '')Success. Number of rows affected: It inserts data to the SID and CID but NOTHING to the grade & comments. Any idea why? I think I`m so close!
  23. This is the code. Hope you can spot the mistake! <?php $db1 = new student_course(); $db1->openDB(); $sql = "SELECT sid FROM STUDENTS"; $result1 = $db1->getResult($sql); $sql = "SELECT cid FROM COURSES"; $result2 = $db1->getResult($sql); if (!$_POST) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Choose student ID: <select name = "sid"> <?php while ($row = mysql_fetch_array($result1)) echo "<option value='{$row['sid']}'>{$row['sid']}</option>"; ?> </select><br/> Choose course ID: <select name = "cid"> <?php while ($row = mysql_fetch_array($result2)) echo "<option value ='{$row['cid']}'>{$row['cid']} </option>"; ?> </select><br/> Enter grade:<input type="text" name="grade" /><br /> Enter comment:<input type="text" name="comments" /><br /> <input type="submit" value="Save" /> </form> <?php } else { $sid = $_POST['sid']; $cid = $_POST['cid']; $grade = $_POST['grade']; $comments = $_POST['comments']; $db1 = new student_course(); $db1->openDB(); $sql = "INSERT INTO student_course (SID, CID, GRADE, COMMENTS) VALUES ('{$sid}', '{$cid}', '{$esc_grade}', '{$esc_comments}')"; echo $sql; $result = mysql_query($sql); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> <?php require("db_config.php"); class student_course { private $conn; function insert_student_course($sid, $cid, $grade, $comments) { $esc_grade = mysql_real_escape_string($grade, $this->conn); $esc_comments = mysql_real_escape_string($comments, $this->conn); $sql = "INSERT INTO student_course (SID, CID, GRADE, COMMENTS) VALUES ('{$sid}', '{$cid}', '{$esc_grade}', '{$esc_comments}')"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } function getResult($sql) { $getResult = mysql_query($sql, $this->conn); if (!getResult) { die("SQL Insertion error: " . mysql_error()); } else { return $getResult; } } function openDB() { $this->conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$this->conn) { die("SQL Connection error: " . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $this->conn); if (!$db_selected) { die("SQL Selection error: " . mysql_error()); } }
  24. I took it out, and guess what happened! Not fatal error anymore, just this: INSERT INTO student_course (SID, CID, GRADE, COMMENTS) VALUES ('1', '1', '', '')Success. Number of rows affected: But in the table, the row was not inserted...
×
×
  • 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.