Jump to content

daniel0816

Members
  • Posts

    45
  • Joined

  • Last visited

Everything posted by daniel0816

  1. OK I have a job table with a primary key J_RefNum. I also have a data recovery spec table with a primary key DRS_ID and a foreign key J_RefNum from the job table which indicates the relationship between the two tables. What I am trying to do is that when data gets submitted into the database the J_RefNum auto increments each time in the job table and that works ok but the J_RefNum doesn't show in the data recovery spec table. What I want to do is when data is submitted to the database and the J_RefNum increments in the job table it also inserts that number into the data recovery spec table. This is to indicate what data recovery spec is associated with which job.
  2. Yea there should be
  3. Thanks but I get the following error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
  4. Do I need to pass any parameters below, there are no errors as such but it still isn't displaying the value for J_RefNum from the job table. $jRefNum = mysql_insert_id(parameters here????); $sql="INSERT INTO dataRecSpec(J_RefNum, DRS_Name) VALUES ($jRefNum, $txt)";
  5. Sorry but for this issue how do i go about using the last insert id function because I know what your on about and it would work am just unsure as to how to structure the code. thanks
  6. For this issue the only two tables concerned are the Manufacturers and Models table. These are the two queries I used to create the tables. The two tables are related through the foreign key identified in the models table. As I said earlier the primary keys in each table are set to auto increment. The MANU_Name and MOD_Name values are submitted through a form and each time these values gets submitted the primary keys increment. $sql=" CREATE TABLE Manufacturers( MANU_ID int AUTO_INCREMENT NOT NULL, MANU_Name varchar(40), PRIMARY KEY(MANU_ID) )"; $sql=" CREATE TABLE Models( MOD_ID int AUTO_INCREMENT NOT NULL, MANU_ID int, MOD_Name varchar(40), PRIMARY KEY(MOD_ID), FOREIGN KEY(MANU_ID) REFERENCES Manufacturers(MANU_ID) )"; The query below inserts the model name into the models table. What I want to do is alter the query so that it takes the MANU_ID from the manufacturers table and inserts it into the models table but it doesn't take it out of the manufacturers table completely it copies it if u like, this is to indicate the relationship between the two tables. At the moment the MANU_ID doesn't show up in the Models table because I haven't said to put it there an that's what I am trying to do. $sql="INSERT INTO Models(MOD_Name) VALUES ('$_POST[model]')";
  7. Sorry what u mean?
  8. The MANU_ID is set to AUTO INCREMENT in the manufacturers table and so is the MOD_ID in the Models table. They both start at zero so each time a manufacturer or model gets submitted to the database the two ID's increment by one. Therefore the two ID'S will be the same. So if a model has the same ID as a manufacturer then that model is associated with that manufacturer.
  9. Has anyone got any suggestions anything ive tried isn't the correct syntax.
  10. TBH it doesn't make sense to me this is the query: $sql="INSERT INTO Models(MANU_ID, MOD_Name) SELECT MANU_ID FROM Manufacturers WHERE MOD_Name = '$_POST[model]'"; and I don't get the purpose of the function u posted because its not being called apologies for this am new to MySQL/php.
  11. Any other suggestions would be greatly appreciated. Thanks
  12. How do I change the query below so that MANU_ID which comes from the Manufacturers table is inserted into the Models table. $sql="INSERT INTO Models(MOD_Name) VALUES ('$_POST[model]')"; Any help would be greatly appreciated thanks
  13. How do I allow the user to specify what data they want backed up if they select yes in the drop down list below. Data Recovery Required?: <select name="dataRecYN" id="DataRec"> <option>Please Select</option> <option value="J_DataRecY">Yes</option> <option value="J_DataRecN">No</option> </select> Thanks
  14. I am trying to validate a forename so that it has to have a capital letter at the start. This is my javascript function: function validateForename() { var the_input = document.getElementById)("Fname").value; if (!the_input.match(/^[A-Z]/)){ alert('Forename must begin with a capital letter'); return false; }else{ return true; } } this is where I am calling the function: function validateForm() { var x=document.forms["custForm"]["fName"].value; if (x==null || x=="") { alert("Invalid Forename"); return false; } var x=document.forms["custForm"]["sName"].value; if (x==null || x=="") { alert("Invalid Surname"); return false; } validateForename(); <----------------------- here } and this is where I am calling the validate form function: <form name="custForm" action="action info here" onsubmit="return validateForm()" method="POST"> Any help would be greatly appreciated thanks
  15. nvm got it sorted thanks for the help
  16. This is my code now: I am now getting the following error: Parse error: syntax error, unexpected 'echo' (T_ECHO) on line 95 //Show tables in DB $sql = "SELECT * FROM CustomerTable"; // Execute query $retrieval = mysql_query($sql, $connect); if(!$retrieval){ die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retrieval, MYSQL_ASSOC)) { echo "FORENAME: {$row['forename']} <br>". echo "SURNAME: {$row['surname']} <br>" <-------------------------------------- Line 95 echo "CONTACT NUM: {$row['mobileNum']} <br>"; } echo "Fetched data successfully\n";
  17. I am trying to show everything that's in the CustomerTable, it just displays the echo I have set i.e. successful. There is data in the table. Don't know why this isn't working any help would be greatly appreciated thanks. //Show tables in DB $sql = "SELECT * FROM CustomerTable"; // Execute query if (mysql_query($sql, $connect)) { echo "successful!"; } else { echo "Error: " . mysql_error($connect); }
  18. Its ok I've fixed the problem thanks for your help.
  19. Sorry it is displaying the following error: Warning: mysql_query() expects parameter 1 to be string, resource given in /homepages/18/d228326958/htdocs/suppmytek/tablesdb.php on line 22 Error creating table: Any ideas as to what the problem is: Thanks
  20. Hi I am trying to insert a table a table into the database. I am connecting to the database ok but its not creating the table it just keeps displaying the echo which I have set in order to check that the table is created so in this case its saying error creating table. I have checked my code countless times but still cant find the problem any help would be greatly appreciated thanks. <?php $connect = mysql_connect("database info goes here"); //check connection if ($connect){ echo "Connected"; }else{ echo "Problem"; } //select database mysql_select_db("dbname", $connect); // Create table $sql="CREATE TABLE test( TestID int AUTO_INCREMENT NOT NULL, name varchar(30), PRIMARY KEY(TestID) )"; // Execute query if (mysql_query($connect,$sql)) { echo "Table Customers created successfully"; } else { echo "Error creating table: " . mysql_error($connect); } ?>
×
×
  • 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.