Jump to content

2cool

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by 2cool

  1. No i havent provided any password for mysql_connect. Im afraid it has no reaction,did not delete the record and no output too. I didnt know this could get so complicated...
  2. Ive tried the latest code but that has no effect at all, it doesnt even delete the record.
  3. ok firstly... no echo statements show right at the beginning before entering anything so thats good and it deletes the record BUT no echo statements show saying for example 'the row has been deleted'.
  4. Here is the current code: <?php $var = isset($_REQUEST['name'])?$_REQUEST['name']:null; $delete = "delete from members where id = \"$var\""; $DBConnect = @mysql_connect("localhost", "root"); mysql_select_db("dietetics", $DBConnect) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $result =mysql_query($delete); if (mysql_affected_rows() > 0) { echo "The row has been deleted successfully"; } else { echo "No rows has been deleted"; } ?> [/Code] And after trying this code: [Code] <?php $var = isset($_REQUEST['name'])?$_REQUEST['name']:null; $delete = "delete from members where id = \"$var\""; $DBConnect = @mysql_connect("localhost", "root"); mysql_select_db("dietetics", $DBConnect) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $result =mysql_query($delete); $result =mysql_query($delete); if (mysql_affected_rows($result) > 0) { echo "The row has been deleted successfully"; } else { echo "No rows has been deleted"; } ?> [/Code] i have got this error, even though it deletes the record: Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource And the 'No rows has been deleted' comes before and after anything is entered.
  5. Ive replaced the code but now it doesnt change from 'No row has been deleted' at any stage
  6. Just another quick question, is there a way of getting the echo statement: 'The row has been deleted successfully' after i have entered something and deleted and not before as this line appears as soon as i enter the page?
  7. Thank you premiso that has taken away the error.
  8. I have put together this code for deleting a record from the database and it works but it always shows an 'Undefined Index: name' error... even before i have entered anything. The code i am using is: <form action ="adminRegister.php" name="thisform" method="get"> <div align="center"> <p> <INPUT TYPE="text" NAME="name" SIZE="30"> </p> <p><br> <input type="submit" value="click to delete!" onclick="submit();"> <br> <?php $var = $_REQUEST['name']; //enter the table name and primary key name $delete = "delete from members where id = \"$var\""; //you have to put the database connection code yourself. $DBConnect = @mysql_connect("localhost", "root"); mysql_select_db("dietetics", $DBConnect) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $result =mysql_query($delete); if ($result ==true) { echo "The row has been deleted successfully"; } else echo "No rows has been deleted"; ?> [/Code] Can anyone help me get rid of that error?
  9. Is there anyone that can help me as ive been working on this but still havent got anything positive. Please help
  10. I have created a pop-up window and that all works fine but when i click on the link for the pop-up window the original window with the link on changes to the pop-up window too. i don't want that to happen. I want the original window to stay to its original state.The code i have used is shown below: Header: <script language="javascript" type="text/javascript"> <!-- var win=null; function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;} if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;} else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20} settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no'; win=window.open(mypage,myname,settings);} // --> </script> And here's the rest of the code: <p align="center" onClick="myPopup5()"><font size="4" face="Comic Sans MS">For Help to complete Questionnaire Click on the 'HELP' button below!<br> <a href="http://localhost/final%20yr%20proj/helpQ.php" onClick="NewWindow(this.href,'helpForQ','400','600','yes','center');return false" onFocus="this.blur()"><strong><font size="5" face="Comic Sans MS">Help</font></strong></a> Can anyone help?
  11. Thanks Axeia, that was exactly what i was trying to do. Just another quick question, Ive looked at the tutorials on w3schools and Ive put together some code but I'm not exactly sure how to make the option selected input into the database. The code that Ive put together for radio buttons is as follows: <?php <font face="Comic Sans MS">Gender:</font><font face="Comic Sans MS"> Male: <input type="radio" value="Male" name="gender"> Female: <input type="radio" value="Female" name="gender"></font> ?> And the code for a combo box that Ive created is as follows: <?php <p align="right"><font face="Comic Sans MS"><strong>Ethnicity : </strong> <select name="ethnicity" size="1" ethnicity = "ethnicity"> <option value="A: White British">A: White British</option> <option value="B: White Irish">B: White Irish</option> <option value="C: Any Other White Backgound">C: Any Other White Backgound</option> </select> </font></p> </div> ?> It selects the option on the form but does not enter it into the database. for the text boxes Ive used this code: <?php if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" /> but I'm not sure how to change it to make it work for radio buttons and combo boxes? Ive tried many ways but have not been successful.
  12. Here is the output: Array ( [PatientID] => 130 [Password] => p130 [Password2] => p130 [DOB] => 1961-12-10 [Age] => 48 [sex] => male [Post_Code] => B26 8LK [Ward] => Erdington [submit] => insertingRecord [submitted] => TRUE )
  13. Another problem that has just come up.... All the input fields in my form are not necessarily text fields (i.e. when i input the gender field, it will have two options; male and female), and will require selecting radio buttons and some are drop-down boxes. Ive tried many ways but have not been successful. The code for my text fields in my form is already given in my last post. Any ideas how i could work around this?
  14. Here it is: <form action="testing2.php" method="post"> <p align="right"><font face="Comic Sans MS">Username: <input type="text" name="PatientID" size="15" maxlength="15" value="<?php if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" /> </font></p> <p align="right"><font face="Comic Sans MS">Password: <input name="Password" type="text" id="Password" value="<?php if (isset($_POST['Password'])) echo $_POST['Password']; ?>" size="15" maxlength="30" /> </font></p> <p align="right"><font face="Comic Sans MS">Confirm Password: <input name="Password2" type="text" id="Password2" value="<?php if (isset($_POST['Password2'])) echo $_POST['Password2']; ?>" size="15" maxlength="30" /> </font></p> <p align="right"><font face="Comic Sans MS">DOB: <input name="DOB" type="text" id="DOB" value="<?php if (isset($_POST['DOB'])) echo $_POST['DOB']; ?>" size="20" maxlength="40" /> </font></p> <p align="right"><font face="Comic Sans MS"> <input type="submit" name="submit" value="insertingRecord" /> </font></p> <div align="right"><font face="Comic Sans MS"> <input type="hidden" name="submitted" value="TRUE" /> </font> </div> </form>
  15. yes ive got that field in my form but its still not working
  16. Another slight problem is that im trying to compare the password and password2 field. the code i am using is: if ($_POST['Password'] != $_POST['Password2']) $errors[] = 'You forgot to confirm your password.'; { die('The passwords did not match'); } But it gives an error of: Undefined index: Password and Undefined index: Password2 i might not be putting it in the right place but im not sure if thats the problem? // Check for a password. if (empty($_POST['Password'])) { $errors[] = 'You forgot to enter the password.'; } else { $mypassword = trim($_POST['Password']); } // Check for a password2. if (empty($_POST['Password2'])) { $errors[] = 'You forgot to enter the password.'; } else { $mypassword2 = trim($_POST['Password2']); } if ($_POST['Password'] != $_POST['Password2']) $errors[] = 'You forgot to confirm your password.'; { die('The passwords did not match'); }
  17. Thanks Stephen68 that worked!
  18. <h2>Register</h2> <form action="testing2.php" method="post"> <p>Username: <input type="text" name="member_no" size="15" maxlength="15" value="<?php //if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" /></p> <p>Password: <input type="text" name="race_no" size="15" maxlength="30" value="<?php //if (isset($_POST['Password'])) echo $_POST['Password']; ?>" /></p> <p>DOB: <input type="text" name="time" size="20" maxlength="40" value="<?php if (isset($_POST['DOB'])) echo $_POST['DOB']; ?>" /> </p> <p><input type="submit" name="submit" value="insertingRecord" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form>
  19. I'm working on this code but it keeps pulling out the errors: Error! The following error(s) occurred: - You forgot to enter the Username. - You forgot to enter the password. - You forgot to enter the DOB. Please try again. These are errors that have been placed within the code. I have copied this code over from another page and it worked fine for that, but this one does not happen to pick up the fields i enter into the form, let alone submitting the information into the database. <?php require_once("DBConnect.php");//database connection session_start(); // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check for a username. if (empty($_POST['PatientID'])) { $errors[] = 'You forgot to enter the Username.'; } else { $myusername = trim($_POST['PatientID']); } // Check for a password. if (empty($_POST['Password'])) { $errors[] = 'You forgot to enter the password.'; } else { $mypassword = trim($_POST['Password']); } // Check for a DOB. if (empty($_POST['DOB'])) { $errors[] = 'You forgot to enter the DOB.'; } else { $myDOB = trim($_POST['DOB']); } if (empty($errors)) { // If everything's okay. // Register the member in the database. // Make the query. $query = "INSERT INTO main (PatientID, Password, DOB) VALUES ('$myusername', '$mypassword', '$myDOB')"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered!</p><p><br /></p>'; // quit the script (to not show the form). exit(); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } mysql_close(); // Close the database connection. } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of the main Submit conditional. ?> Can anyone help and tell me where I'm going wrong or what I'm missing?
  20. Silly me, I think I've spent too much time on it...I have corrected the spelling and it works fine now. Thank you all for the help.
  21. Thanks sasa, I have entered the amended code but it gives this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
  22. What i am trying to do is use the fields from my database (S1Weight and Height) to work out this calculation. I am a new programmer and not sure if I'm doing this the right way. I have tried many different ways but none have been successful. The code i am using now is: <?php $query="SELECT Height FROM `main` WHERE clientD='1'"; $result=mysql_query($query); $row = mysql_fetch_assoc($result); echo $row['Height']; ?> <br> <?php $query="SELECT S1Weight FROM `main` WHERE PatientID='1'"; $result=mysql_query($query); $row1 = mysql_fetch_assoc($result); echo $row1['S1Weight']; ?> <br> <?php $c=($row*$row/$row1); echo $c; ?> The first two parts display the Height and S1Weight individually but when i put it into the calculation i need i throws an error, 'Fatal error: Unsupported operand types'. Firstly is this the correct code and if it is how could i go about resolving this error. If not, can you direct me the right way. Thanks
  23. Hi I'm tyring to do this calculation, shown below: $Height='Height'; $S1Weight='S1Weight'; $result= ($Height * $Height / $S1Weight); echo ($result); Another way i tried was: print ("BMI for Session 1 is: "); print ("S1Weight FROM `main` WHERE clientID='1'" * "S2Weight FROM `main` WHERE clientID='1'" / "Height FROM `main` WHERE clientID='1'"); It gives me an error: 'Division by zero', There are figures in all the fields i am using ,i.e. Height and S1Weight and i am trying to individualise to to clientID. Any ideas why it throws this error? Thanks in advance.
×
×
  • 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.