
BasiM
New Members-
Posts
8 -
Joined
-
Last visited
BasiM's Achievements

Newbie (1/5)
0
Reputation
-
Hi Hope someone can help me. I have two tables from the database. 1 table - patient and the 2nd table - medical aid I want to extract data from both table. The query runs but it duplicates the data in the table. I am not sure what I have done wrong. Here is the code <?php echo "<table border='1' align='center' cellspacing='0' width='650px' cellspacing='0'> <tr><th>Surname</th> <th>Name</td> <th>ID Number</th> <th>Contact Numbet</th><th >Medical Aid Scheme</th><th>Medical Aid Number</th></th></tr>"; //connect to database $connection = mysql_connect('localhost','root','') or die ("Couldn't connect to server."); $db = mysql_select_db('medionline', $connection) or die ("Couldn't select database."); $query = 'SELECT patient.name,patient.surname,patient.id_number,medical_aid.medical_aid_scheme,medical_aid.medical_aid_number FROM patient,medical_aid WHERE patient.id_number = medical_aid.id_number ORDER BY patient_id'; $result = mysql_query($query) or die("Couldn't execute query. ". mysql_error()); while($row = mysql_fetch_array($result)) { $id = $row['id_number']; echo "<tr ><td>"; echo $row['surname']; echo "</td><td>"; echo $row['name']; echo "</td><td>"; echo $row['id_number']; echo "</td><td>"; echo $row['medical_aid_scheme']; echo "</td><td>"; echo $row['medical_aid_number']; echo "</td><td>"; echo "</tr>"; } echo"</table>"; mysql_close(); ?>
-
it prints out error occurred.
-
Hi. Hope someone can help. I have created a form that registers new users. It validates the information first before it inserts the data into the database. Problem : it does not validate the data meaning if u press submit it still processes the data. it does not insert the data into the database, it prints out error has occurred Please can some assist me. Thanx Here is the code <?php /* * author :[email protected] * * * */ include 'connection.php'; $title=$_POST['title']; $surname=$_POST['surname']; $name=$_POST['name']; $id_number=$_POST['id_number']; $date_of_birth=$_POST['date_of_birth']; $gender=$_POST['gender']; $occupation=$_POST['occupation']; $mobile_number=$_POST['mobile_number']; $email_add=$_POST['email_add']; $postal_add=$_POST['postal_add']; $titleconfirm=""; $surnameconfirm=""; $nameconfirm=""; $id_numberconfirm=""; $date_of_birthconfirm=""; $genderconfirm=""; $occupationconfirm=""; $mobile_numberconfirm=""; $email_addconfirm=""; $postal_addconfirm=""; $message=""; if(isset($_POST['submit'])) { if(!$title){ $titleconfirm="please select title"; } if(!$surname){ $surnameconfirm="please enter surname "; } if(!$name){ $nameconfirm="please enter name"; } if(!$id_number){ $id_numberconfirm="please enter id number"; } if(!$date_of_birth){ $date_of_birthconfirm="please enter date of birth"; } if(!$gender){ $genderconfirm="Please select gender"; } if(!$occupation){ $occupationconfirm="please enter occupation"; } if(!$mobile_number){ $mobile_numberconfirm="please enter mobile name"; } if(!$email_add){ $email_addconfirm="please enter email address"; } if(!$postal_add){ $postal_addconfirm="please enter postal address"; } if($titleconfirm="please select title" && $surnameconfirm="please enter surname" && $nameconfirm="please enter name" && $id_numberconfirm="please enter id number" && $date_of_birthconfirm="please enter date of birth" && $genderconfirm="Please select gender" && $occupationconfirm="please enter occupation" && $mobile_numberconfirm="please enter mobile name" && $email_addconfirm="please enter email address" && $postal_addconfirm="please enter postal address") { $connection = new createConnection(); // creating connection $connect = $connection->connectToDatabase(); // connect to database $connection->selectDatabase(); // select database $surname = mysql_real_escape_string($_POST['surname']); $name =mysql_real_escape_string($_POST['name']); $id_number = mysql_real_escape_string($_POST['id_number']); $date_of_birth = mysql_real_escape_string($_POST['date_of_birth']); $gender = mysql_real_escape_string($_POST['gender']); $occupation = mysql_real_escape_string($_POST['occupation']); $mobile_number = mysql_real_escape_string($_POST['mobile_number']); $email_add = mysql_real_escape_string($_POST['email_add']); $postal_add = mysql_real_escape_string($_POST['postal_add']); //Insert into database $query = "INSERT INTO `patient`(title,surname,name,id_number,date_of_birth,gender,occupation,mobile_number,email_add,postal_add) VALUES ('title','$surname','$name','id_number','$date_of_birth','$gender','$occupation','$mobile_number','$email_add','$postal_add')"; if(mysql_query($query,$con)) { $message="<b style='color:lightgreen'>team selection inserted into database</b>"; $message= $message. "<br /><a href='paitent_info.html'>back to selection list</a>"; } else { die("error occured:". mysql_error());} } } if(isset($_POST['clear'])){ $title=""; $surname=""; $name=""; $id_number=""; $date_of_birth=""; $gender=""; $occupation=""; $mobile_number=""; $email_add=""; $postal_add=""; } ?>
-
Thank you. Sorry about not using indentation. Will arrange my script and use it.
-
Hello. Hope someone can help me. I have created a simple user registration form. The user is required to insert data into the fields and insert a username and password. The server will check in the database if the username and password don't already exist. If the username and password are already in the database it will print out a message that username and password already exist. If username and password don't exist it will run the INSERT statement and display a user successful message. My issue/problem. There is no error message printed. When I run the script it says ''User successful''. When I run the script again entering the same username and password, it prints the ''User successful message'' yet no data is inserted into the database. Hope someone can help Thanx <?php /* * author :[email protected] * * * */ include 'connection.php'; if(isset ($_POST['name'] ) && isset ($_POST['surname']) && isset ($_POST[ 'id_number']) && isset ($_POST[ 'contact_number'])&& isset ($_POST[ 'job_id'])&& isset ($_POST[ 'username'])&& isset ($_POST['password'])) // getting the values from the post { $connection = new createConnection(); // creating connection $connect = $connection->connectToDatabase(); // connect to database $connection->selectDatabase(); // select database // escape sql injection $name = mysql_real_escape_string($_POST['name']); $surname =mysql_real_escape_string($_POST['surname']); $id_number = mysql_real_escape_string($_POST['id_number']); $contact_number = mysql_real_escape_string($_POST['contact_number']); $job_id = mysql_real_escape_string($_POST['job_id']); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $query=mysql_query("SELECT * FROM `medionline`.`employees` WHERE username='$username' AND password= '$password'"); // Check if the username and password already exist in the database if (mysql_num_rows($query) > 0) { echo "Username and password already exist!"; } else { // execute the insert query mysql_query("INSERT INTO `medionline`.`employees`(name,surname,id_number,contact_number,job_id,username, password) VALUES ('$name','$surname','$id_number','$contact_number','$job_id','$username','$password')"); // query for insert data } echo ("User registration Successfull"); $connection->closeConnection(); // closing the connection } else { echo "Error occured!"; // display error message } ?>
-
Good day Hope someone can help me. I am working on an Intranet project, the aim is to create a medical intranet system. Please help me with the following. 1. I have created users on my database(called medionline) and stored the relevant information in table employees. 2. I have a script which searches for the name and surname of the employees in the database 3. When a match is found, it then prints the details. The search functionality works but not as I want it to work, this is where I need help. It should do the following. a. Search for a user using either the name, surname or username b. When a match is found, it will then display all the details about the specific user(name, surname, id number, contact number, jobtile and username_ in a form, meaning a new form will have to be set up with these fields. This will allow me to create buttons within the form with the users details where I can delete users, update users or create new users. Your assistance in this will be highly appreciated. This is my search.php page <?php /* * author :[email protected] * * * */ include 'connection.php'; $connection = new createConnection(); // creating connection $connect = $connection->connectToDatabase(); // connect to database $connection->selectDatabase(); // select database //-------------------QUERY--------------------------------------// $query = $_GET['query']; // gets value sent over search form $min_length = 3; // you can set minimum length of the query if you want if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then $query = htmlspecialchars($query); // changes characters used in html to their equivalents, for example: < to > $query = mysql_real_escape_string($query); // makes sure nobody uses SQL injection $raw_results = mysql_query("SELECT * FROM employees WHERE (`name` LIKE '%".$query."%') AND (`surname` LIKE '%".$query."%')") or die(mysql_error()); // * means that it selects all fields, you can also write: `id`, `title`, `text` // articles is the name of our table // '%$query%' is what we're looking for, % means anything, for example if $query is Hello // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query' // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query' if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following while($results = mysql_fetch_array($raw_results)){ // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop echo "<p><h3>".$results['name']."</h3>".$results['surname']."</p>"; // posts results gotten from database(title and text) you can also show id ($results['id']) } } else{ // if there is no matching rows do following echo "No results"; } } else{ // if query length is less than minimum echo "Minimum length is ".$min_length; } This is my search.index.php page <!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=utf-8" /> <title>Medi_online</title> <link type="stylesheet" rel="stylesheet" href="main.css"/> <script src="buttons.js"></script> <script src="connect.js"></script> <script src="slider.js"></script> </head> <!---Website Design by Basetsana Manele medi_online intranet system 2013 Contact: [email protected] --> <body> <!--Twitter and Facebook connect tabs----> <div class="s-connect"> <div class="Fbutton"> <div class="facebook"> <img src="images/social_media/Facebook.png"/> </div> <div class="cont"></div>a </div> <div id="clear"></div> <div class="Tbutton"> <div class="twitter"> <img src="images/social_media/twitter.png"/> </div> <div class="Tcont"></div> </div> <div id="clear"></div> </div> <div id="clear"></div> <!--------------------------------------------------> <div id="weblinks"> <div id="link"><a href="../medionline/logout.php" target="_new">Logout | </a></div> <div id="link"><a href="../medionline/admin_login.php"target=_"new">Admin Login </a></div> </div> <!-------Banner------------------> <div id="banner"> </div> <!-------Main Navigation---------> <div id="nav"> <div class="nav_bs" style="width:175px;" ><a style="color:#e1e1e1;" href="index.html">INTRANET HOME</a></div> <div class="nav_bs" style="width:180px;" ><a style="color:#e1e1e1;" href="about_fisha.html">EMPLOYEE TOOLS</a></div> <div class="nav_bs" style="width:250px;" ><a style="color:#e1e1e1;" href="healthcare.html">COLLOBORATION TOOLS</a></div> <div class="nav_bs" style="width:190px;" ><a style="color:#e1e1e1;" href="training.html">DEPARTMENT HUB</a></div></div> <!-------Paitent information sign up-------> <div id="container_main"> <h3 align="center">SEARCH USER</h3> <br/> <h5 align="justify"> Please enter either name, surname or username to search.</h5> <br/> <form action="search.php" method="GET"> <table width="500" border="0" cellpadding="0"> <input type="text" name="query" /> <input type="submit" value="Search" /> <tr> <td> </td> </tr> </form> </div> </body> </html>
-
Thank you Strider64. I am batlling with php :-( and having to learn it online is harder. I am trying to use a function tho and not a case statement. Your post gave me some much needed light.
-
Hi Hoping someone can help so frustrated with this as I cant figure it out. This is what has to happen. Create a function of your choice. The function must accept 5 arguments. Create a form that accepts 5 arguments, each via a drop-down menu and echo the results back to the user. This is what I have so far. <?php // Declare the function and variables error_reporting (0); $msg = ""; $activity = ""; // Make sure the submit button has been selected if (isset ($_POST ['submit'])){ function activites ($paintballing , $ice_skating, $horse_riding, $para_gliding, $water_rafting ){ // Make the activity array $activites = array (1=> 'Paintballing', 'Ice_skating', 'Horse_riding', 'para_gliding', 'water_rafting'); // use a foreach loop to loop through the activity foreach ($activites as $key =>$value) { $msg = "We trust you will enjoy $activity today. Have fun and create memories"; } } if ($activity == ""){ $msg = "<font color = 'red'> Please select an activity from the drop down menu</font>"; } ?> <html> <head> <title>Function </title> </head> <body> <center> <a href="index.php">Home </a> | <a href ="calc.php">Calc</a> | <a href="string.php">String</a> | <a href ="array.php"> Array </a> | <a href = "function.php">Function </a></center> </center> <form name = 'function' method = "POST" action = 'function.php' > <p>Select one of the activity you would like to do today:</p> <select name="Activity" size="5"> <option selected value = ""> <option> Paintballing </option> <option> Ice-skating </option> <option> Horse-riding </option> <option> Para-gliding </option> <option> Water-rafting </option> </select> </form> <input type = "submit" name = "submit" value = "submit" /> </option> <?php echo $msg;?> <p align ="center"><a href ="function.txt" Onclick ="window.open ('function.txt', 'function', resizable =no, height=500, width=500, scrollercars=yes'); retrun false;">Function.txt</a></p>