Jump to content

dustflower

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dustflower's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey peeps, I have a code on which was coded in mysql - i am trying to connect and fixs the section on which is MySQL. Here is the code <!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"> <head> <meta name="description" content="Nearest Neighbour Algorithm - Data Mining" /> <meta name="keywords" content="nearest neighbour, data mining, php, computer science, james hamilton" /> <meta http-equiv="Content-Language" content="en-gb" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="robots" content="all" /> <meta name="revisit-after" content="1 days" /> <title>Nearest Neighbour Algorithm - Data Mining11</title> <?php $conn = pg_Connect ("port=**** dbname=***** # make the corresponding replacements if (!$conn) { exit; } ?> <link rel="stylesheet" media="all" href="style.css" type="text/css" /> <link rel="stylesheet" media="all" href="nearestneighbour.css" type="text/css" /> </head> <body> <?php if(isset($_GET[source])) { highlight_file(__FILE__); }else{ ?> <p>The nearest neighbour algorithm classifies a given instance based on a set of already classified instances (the training set), by calculating the distance to the nearest training case. The new instance is classified in the same class as the closest training case (i.e. the one that has the least differences/the one that is most the same). </p> <p> Try this out below. There are 10 instances in the training set. Use the select boxes to diagnose a new patient using the nearest neighbour algorithm. The diagnosis is made by selecting the diagnosis (class) of the instance in the training set with the least differences (i.e. closest distance). </p> <table id="patients" cellpadding="3" cellspacing="0"> <tr> <th>Patient ID</th> <th>age</th> <th>sex</th> <th>chestpaintype</th> <th>bloodpressure</th> <th>cholesterol</th> <th>fbs120</th> <th>restingegh</th> <th>maxheartrate</th> <th>angina</th> <th>slop</th> <th>thal</th> <th>diagnosis</th> </tr> <?php /* function getRows takes an SQL query string (and a optional array key type - NUM or ASSOC) and returns and array containing all the rows of the query. define(ASSOC, 1); define(NUM, 2); function getRows($sql, $type=ASSOC) { $result = mysql_query($sql); if($type == ASSOC) { while($row = mysql_fetch_array($result)) $ret[] = $row; }else if($type == NUM) { while($row = mysql_fetch_row($result)) $ret[] = $row; }else{ die("type should be NUM or ASSOC"); } return $ret; } */ $sql_code = "SELECT * FROM heartcondition "; if(isset($_POST[diagnose])) { $distance = array_fill(0, count($sql_code), 0); $instance = $_POST[instance]; for($i = 0; $i < count($sql_code); $i++) { for($j = 1; $j < 11; $j++) { if($sql_code[$i][$j] != $instance[$j]) $distance[$i]++; } } $closest = array_search(min($distance), $distance); $diagnosis = $sql_code[$closest][12]; } for ( $a = 0; = 0; $a< pg_numrows($result); $row++) --foreach($rows as $row) { ?> <tr<?php if($closest == $a) { ?> class="selected"<?php } ?>> <td><?=$row[0]?></td> <td><?=$row[1] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[2] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[3] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[4] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[5] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[6] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[7] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[8] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[9] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[10] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[11] == 0 ? "No" : "Yes"; ?></td> <td><?=$row[12]?></td> <td><?=$distance[$a++]?></td> </tr> <?php } ?> <tr> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> <td><input type="hidden" name="instance[]" value="11" />11</td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][1] == "0") echo "selected=\"selected\"";?>>No</option> <option value="1"<?php if($_POST[instance][1] == "1") echo "selected=\"selected\"";?>>Yes</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][2] == "0") echo "selected=\"selected\"";?>>Sixties</option> <option value="1"<?php if($_POST[instance][2] == "1") echo "selected=\"selected\"";?>>forties</option> <option value="1"<?php if($_POST[instance][2] == "2") echo "selected=\"selected\"";?>>fifties</option> <option value="1"<?php if($_POST[instance][2] == "2") echo "selected=\"selected\"";?>>thirties</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][3] == "0") echo "selected=\"selected\"";?>>Male</option> <option value="1"<?php if($_POST[instance][3] == "1") echo "selected=\"selected\"";?>>Female</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][4] == "0") echo "selected=\"selected\"";?>>Angina</option> <option value="1"<?php if($_POST[instance][4] == "1") echo "selected=\"selected\"";?>>AbnomalAngina</option> <option value="1"<?php if($_POST[instance][4] == "2") echo "selected=\"selected\"";?>>No tang</option> <option value="1"<?php if($_POST[instance][4] == "3") echo "selected=\"selected\"";?>>Asymptomatic</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][5] == "0") echo "selected=\"selected\"";?>>onethirty+</option> <option value="1"<?php if($_POST[instance][5] == "1") echo "selected=\"selected\"";?>>oneten+</option> <option value="1"<?php if($_POST[instance][5] == "2") echo "selected=\"selected\"";?>>onefourty+</option> <option value="1"<?php if($_POST[instance][5] == "3") echo "selected=\"selected\"";?>>onefifty+</option> <option value="1"<?php if($_POST[instance][5] == "4") echo "selected=\"selected\"";?>>onetwenty+</option> <option value="1"<?php if($_POST[instance][5] == "5") echo "selected=\"selected\"";?>>onesisty+</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][6] == "0") echo "selected=\"selected\"";?>>twoten+</option> <option value="1"<?php if($_POST[instance][6] == "1") echo "selected=\"selected\"";?>>twosixty+</option> <option value="1"<?php if($_POST[instance][6] == "2") echo "selected=\"selected\"";?>>twofifty+</option> <option value="1"<?php if($_POST[instance][6] == "3") echo "selected=\"selected\"";?>>twohundred+</option> <option value="1"<?php if($_POST[instance][6] == "4") echo "selected=\"selected\"";?>>twotwenty+</option> <option value="1"<?php if($_POST[instance][6] == "5") echo "selected=\"selected\"";?>>twoeight+</option> <option value="1"<?php if($_POST[instance][6] == "6") echo "selected=\"selected\"";?>>twothirty+</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][7] == "0") echo "selected=\"selected\"";?>>f</option> <option value="1"<?php if($_POST[instance][7] == "1") echo "selected=\"selected\"";?>>t</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][8] == "0") echo "selected=\"selected\"";?>>Hyp</option> <option value="1"<?php if($_POST[instance][8] == "1") echo "selected=\"selected\"";?>>Normal</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][9] == "0") echo "selected=\"selected\"";?>>onethirty+</option> <option value="1"<?php if($_POST[instance][9] == "1") echo "selected=\"selected\"";?>>oneforty+</option> <option value="0"<?php if($_POST[instance][9] == "2") echo "selected=\"selected\"";?>>onefifty+</option> <option value="0"<?php if($_POST[instance][9] == "3") echo "selected=\"selected\"";?>>onesixty+</option> <option value="0"<?php if($_POST[instance][9] == "4") echo "selected=\"selected\"";?>>oneseventy+</option> <option value="0"<?php if($_POST[instance][9] == "5") echo "selected=\"selected\"";?>>oneeighty+</option> <option value="0"<?php if($_POST[instance][9] == "6") echo "selected=\"selected\"";?>>onetwenty+</option> <option value="0"<?php if($_POST[instance][9] == "7") echo "selected=\"selected\"";?>>onehundred+</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][10] == "0") echo "selected=\"selected\"";?>>f</option> <option value="1"<?php if($_POST[instance][10] == "1") echo "selected=\"selected\"";?>>t</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][11] == "0") echo "selected=\"selected\"";?>>Falt</option> <option value="1"<?php if($_POST[instance][11] == "1") echo "selected=\"selected\"";?>>Up</option> <option value="1"<?php if($_POST[instance][11] == "2") echo "selected=\"selected\"";?>>Down</option> </select> </td> <td><select name="instance[]"> <option value="0"<?php if($_POST[instance][12] == "0") echo "selected=\"selected\"";?>>Rev</option> <option value="1"<?php if($_POST[instance][12] == "1") echo "selected=\"selected\"";?>>Normal</option> <option value="1"<?php if($_POST[instance][12] == "2") echo "selected=\"selected\"";?>>Fix</option> </select> </td> <td<?php if($diagnosis) { ?> class="selected"<?php } ?>><?=$diagnosis?></td> <td><input type="submit" name="diagnose" value="Diagnose" /></td> </form> </tr> </table> <p> <a href="<?=$_SERVER[php_SELF]?>?source">View Page Source</a> </p> <?php } ?> <p> Back to <a href="index.php">Data Mining</a> </p> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-1032885-1"; urchinTracker(); </script> </body> </html> Thanks
  2. so do i implement it within the the if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "../uploads/{$_FILES['thefile']['name']}")) { section!
  3. Hello ! i am having issue on uploading and displaying an image in php! i keep getting the errors! "Warning: move_uploaded_file(../uploads/boxing.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php122.tmp' to '../uploads/boxing.jpg' in C:\xampp\htdocs\upload_file.php on line 15 i am trying to figure what is wrong but i don't get it " plz help" <!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=utf-8" /> <title>Upload a File</title> </head> <body> <?php // Script 11.4 - upload_file.php /* This script displays and handles an HTML form. This script takes a file upload and stores it on the server. */ if (isset($_POST['submitted'])) { // Handle the form. // Try to move the uploaded file: if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "../uploads/{$_FILES['thefile']['name']}")) { print '<p>Your file has been uploaded.</p>'; } else { // Problem! print '<p style="color: red;">Your file could not be uploaded because: '; // Print a message based upon the error: switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'The temporary folder does not exist.'; break; default: print 'Something unforeseen happened.'; break; } print '.</p>'; // Complete the paragraph. } // End of move_uploaded_file() IF. } // End of submission IF. // Leave PHP and display the form: ?> <form action="upload_file.php" enctype="multipart/form-data" method="post"> <p>Upload a file using this form:</p> <input type="hidden" name="MAX_FILE_SIZE" value="3000000" /> <p><input type="file" name="thefile" /></p> <p><input type="submit" name="submit" value="Upload This File" /></p> <input type="hidden" name="submitted" value="true" /> </form> </body> </html> plz help!
  4. thanks cunoodle2 and the182guy ! i modified the codes and even notice that i didn't specify the MySql connection but i still have that error plz help ! :'( <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Register</title> </head> <body> <h1>Register</h1> <table><tr> <form action="registerTest.php" method="post"> <td width="81">Username:</td> <td width="247"><input name="username" size="30" autocomplete="off" value="" type="text" /></td> </tr><tr> <td>Password:</td> <td><input name="password" size="30" type="password" /></td> </tr> <tr> <td>First Name:</td> <td><input name="firstname" size="30" type="text" /></td> </tr> <tr> </tr> </table> <p><input type="submit" class="button" value="Register" /></p> </form> </body> </html> <?php define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_DATABASE', 'login1'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $result = mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_name='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO users (user_name, password, userID) VALUES ('$username', '$password', '$firstname')"); } echo '<p>Congratulations! You have successfully registered! </p>'; } ?>
  5. not to sound dumb :-\ but didn't i have a closing parentheses after the INSERT command
  6. HELLO! I got an error with my php file and i no its bound to be a silly mistake as i am prone to it - i keep getting Parse error: syntax error, unexpected $end in C:\xampp\htdocs\registerTest.php on line 65 here is my code <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Register</title> </head> <body> <h1>Register</h1> <table><tr> <form action="registerTest.php" method="post"> <td width="81">Username:</td> <td width="247"><input name="username" size="30" autocomplete="off" value="" type="text" /></td> </tr><tr> <td>Password:</td> <td><input name="password" size="30" type="password" /></td> </tr> <tr> <td>First Name:</td> <td><input name="firstname" size="30" type="text" /></td> </tr> <tr> </tr> </table> <p><input type="submit" class="button" value="Register" /></p> </form> </body> </html> <?php include 'mysql-connect.php'; $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $result = mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_name='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO users (user_name, password, userID") VALUES ('$username', '$password', '$firstname'); } echo '<p>Congratulations! You have successfully registered! </p>'; <p>Click <a href="login.html">here</a> to login.</p>; ?> if anyone could help then i will be greatly apperciate it ! Thanks
×
×
  • 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.