Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Shows the the errors if there are any for debugging
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- //create empty strings to stop undefined errors
- $results = "";
- $host="mysql5";
- $user="fet10027875";
- $password="ibizalad";
- $connection = mysql_connect($host,$user,$password);
- if (!$connection)
- {
- die("Couldn't connect to server");
- }
- else
- {
- $name=$_POST[name];
- // select database
- $db_selected = mysql_select_db($user, $connection);
- if (!$db_selected)
- {
- die ('Can\'t use $user : ' . mysql_error());
- }
- $query = "select name from computer, app where computer.code = app.code and app.app = '$name'";
- $result = mysql_query($query)
- or die ("Couldn't execute query");
- while ($row = mysql_fetch_array ($result))
- {
- extract ($row);
- echo "<p>$name</p>";
- }
- }
- mysql_close($connection);
- //start the first part of the Query
- $sql = "SELECT * FROM Drivers WHERE ";
- if( isset($_POST['SubmitDrivers']) )
- {
- //Add title to the results var
- $results = "<h1><u>Driver</u></h1>";
- //if the drivers feild is set and the content lenght is greater than 0
- if( isset($_POST['driverName']) && strlen($_POST['driverName']) > 0)
- {
- //set the posted var = to local var
- $driversName = $_POST['driverName'];
- //Add the driver clause to the sql string
- $sql = $sql."First_Name='".$driversName."' AND ";
- }
- if( isset($_POST['driversLast']) && strlen($_POST['driversLast']) > 0 )
- {
- $driversLast = $_POST['driversLast'];
- //search for the driver
- $sql = $sql."Second_Name='".$driversLast."' AND ";
- }
- if( isset($_POST['driverDoB']) && strlen($_POST['driverDoB']) > 0 )
- {
- $driversDOB = $_POST['driverDoB'];
- //search for the driver
- $sql = $sql."DOB='".$driversDOB."' AND ";
- }
- if( isset($_POST['driverNationality']) && strlen($_POST['driverNationality']) > 0 )
- {
- $driverNationality = $_POST['driverNationality'];
- //search for the driver
- $sql = $sql."Nationality='".$driverNationality."' AND ";
- }
- //your query is without the extra and bit on the end
- $query = substr_replace($sql ,"",-4);
- //link to db
- //$link = mysql_connect(/*arguments here*/);
- //gets the results of the query
- //$result = mysql_query($query, $link);
- //if there are results
- /*if ($result) {
- //loop over the results
- while($row = mysql_fetch_array($result)) {
- //output the results here
- $firstName = $row[First_Name];
- }
- }
- else {
- echo mysql_error();
- }
- //connect to db
- //proccess the results
- //Display the results*/
- }
- //shows the sql string
- echo $results;
- echo $query;
- // Includes the footer php, so only has to ba changed once
- ?>
- <?php include 'foot.php'; ?>
- sorry wrong code
- this is the one
- <html>
- <head>
- <!--This is a comment. Comments are not displayed in the browser-->
- <title>PHP MySQL</title>
- </head>
- <body>
- <h1> This is the response: </h1>
- <?php
- // Don't pass these details to students!
- $host="mysql5";
- $user="username";
- $password="password";
- $connection = mysql_connect($host,$user,$password);
- if (!$connection)
- {
- die("Couldn't connect to server");
- }
- else
- {
- $name=$_POST[name];
- // select database
- $db_selected = mysql_select_db($user, $connection);
- if (!$db_selected)
- {
- die ('Can\'t use $user : ' . mysql_error());
- }
- $query = "select name from computer, app where computer.code = app.code and app.app = '$name'";
- $result = mysql_query($query)
- or die ("Couldn't execute query");
- while ($row = mysql_fetch_array ($result))
- {
- extract ($row);
- echo "<p>$name</p>";
- }
- }
- mysql_close($connection);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement