Jump to content

Obsession

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Obsession's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My bad, I generally just stick it all as text, bad habit. Anyway, new file- <?php $con=mysql_connect('localhost','root',''); if(!$con) { echo mysql_error(); } $select=mysql_select_db('a1',$con); if(!$select) { echo mysql_error(); } mysql_select_db('a1',$con); mysql_query("CREATE TABLE Drivers ( DriverName VARCHAR(22), DriverAddress TEXT, DriverHomeNum INT(11), DriverMobileNum INT(11), CarNum INT(3) )"); mysql_query("CREATE TABLE Cars ( CarNum Int(3), CarColor VARCHAR(22), CarType INT(11), CarMake INT(11), CarReg VARCHAR(22) )"); header('Location:index.html'); ?> Next step? Is there not some way I can identify CarNum as primary key?
  2. mysql_query("CREATE TABLE Drivers ( DriverName TEXT, DriverAddress TEXT, DriverHomeNum INT(11), DriverMobileNum INT(11), Carnum INT(3) )"); mysql_query("CREATE TABLE Cars ( CarNum TEXT, CarColor TEXT, CarType INT(11), CarMake INT(11), CarReg TEXT )"); Creates both tables. Now, when they search for one of the options that searches the car table, this code works. if (($SearchIn=="CarNum")||($SearchIn=="CarColor")||($SearchIn=="CarMake")||($SearchIn=="CarType")||($SearchIn=="CarReg")) { $sql="SELECT * FROM cars WHERE $SearchIn='$SearchValue'"; $result=mysql_query($sql) or die(mysql_error()); echo "<table border=1>"; echo "<tr>"; echo "<th>Car Number</th>"; echo "<th>Car Color</th>"; echo "<th>Car Type</th>"; echo "<th>Car Make</th>"; echo "<th>Car Reg</th>"; echo "<th>Driver Name</th>"; echo "<th>Driver Address</th>"; echo "<th>Phone Number</th>"; echo "<th>Mobile Number</th>"; echo "</tr>"; while ($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; echo $row['CarNum']; echo "</td>"; echo "<td>"; echo $row['CarColor']; echo "</td>"; echo "<td>"; echo $row['CarType']; echo "</td>"; echo "<td>"; echo $row['CarMake']; echo "</td>"; echo "<td>"; echo $row['CarReg']; echo "</td>"; $DriverNumber=$row['CarNum']; $sql="SELECT * FROM drivers WHERE Carnum=$DriverNumber"; $result2=mysql_query($sql); while ($row=mysql_fetch_array($result2)) { echo "<td>"; echo $row['DriverName']; echo "</td>"; echo "<td>"; echo $row['DriverAddress']; echo "</td>"; echo "<td>"; echo $row['DriverHomeNum']; echo "</td>"; echo "<td>"; echo $row['DriverMobileNum']; echo "</td>"; echo "</tr>"; } } echo "</table>"; } else But, they may also search the driver table for driver information, so the query is then else { $sql="SELECT * FROM drivers WHERE $SearchIn='$SearchValue'"; $result=mysql_query($sql) or die(mysql_error()); echo "<table border=1>"; echo "<tr>"; echo "<th>Car Number</th>"; echo "<th>Car Color</th>"; echo "<th>Car Type</th>"; echo "<th>Car Make</th>"; echo "<th>Car Reg</th>"; echo "<th>Driver Name</th>"; echo "<th>Driver Address</th>"; echo "<th>Phone Number</th>"; echo "<th>Mobile Number</th>"; echo "</tr>"; But now, I am completely lost. You see,if i search DriverName for "Peter", i get two results. If I do a while loop on the $result['Carnum'] variable...i get all the car numbers that have drivers named Peter, yes? Then how do i use those car numbers to do what the first part does and print all this data? (notice the small 'n' in num, and see how this matches the drivers table whereas the cars table has a big 'N'. Does that matter?)
  3. Sorted it now, but thanks anyway. My last problem is that when they search a value and select one of the driver options, i need a way of getting the carnumber of ALL drivers returned from the search, then with those car numbers print the table in this order- Car Number Car Color Car Type Car Make Car Reg Driver Name Driver Address Phone Number Mobile Number Been messing around with while loops, but I just cant do it. I hope it worded it well enough.
  4. $sql="SELECT * FROM cars,drivers WHERE $SearchIn='$SearchValue'"; $result=mysql_query($sql) or die(mysql_error()); Now, you see I am selecting values where $SearchIn=$SearchValue. $SearchIn can be any one of these - <option value="" selected="yes">Choose One...</option> <option value=""></option> <option value="CarNum">Car Number</option> <option value="CarColor">Car Color</option> <option value="CarMake">Car Make</option> <option value="CarType">Car Type</option> <option value="CarReg">Car Registration</option> <option value=""></option> <option value="DriverName">Driver Name</option> <option value="DriverAddress">Driver Address</option> <option value="DriverHomeNum">Driver Home Phone</option> <option value="DriverMobileNum">Driver Mobile Phone</option> Although, we assume the user will pick one of the options other than empty or Please Choose One. Now, if the choice is one of the ones starting with "Driver"(the bottom four), I need the query to search for whatever was input in the Drivers table. If it was one of the top five, I need it to search in the Cars table. BUT, the results I want to display are from both tables. An example, car 11. If we search for "Peter", driver 11's name, I need it to search the driver table for this, then print all the results from the driver table, THEN using the result in the CarNum field in the driver table, print everything from the Cars table. But, if I search for "Ford" I need it to search the cars table, then search the drivers and print it all. How do I do this? You see, CarNum is in both tables. Now, my problems. If I search for CarNum, value of 11, which should return one result, I get "Column 'CarNum' in where clause is ambiguous". No idea how to solve it, never ever seen it before. Now, if i search for "Peter" under DriverName, it should return the following- Car Number Car Color Car Type Car Make Car Reg Driver Name Driver Address Phone Number Mobile Number 11 Silver 6 Seater Citroen 9999888 Peter 6 Brig St 01229 07792 But, it returns this- Car Number Car Color Car Type Car Make Car Reg Driver Name Driver Address Phone Number Mobile Number 11 Silver 6 Seater Citroen 9999888 Peter 6 Brig St 01229 07792 56 Red Saloon Ford 1111333 Tim 3 Jarrow St 01229 07792 As you can see, "Tim" is not "Peter". Why does it return that?
  5. Go to "http://localhost/phpmyadmin/" in your browser, without the quotes, while WAMP is running. Here you see your database at the side, you can add tables, and edit them there.
  6. Sorry all, problem solved, after ALOT of searching. Used this- while ($row = mysql_fetch_assoc($queryone)) { echo $row['Tag']; } Didnt even think a while loop would help.
  7. I get "Resource ID #3" for the result of a query, which has me completely baffled. Any ideas? The code that generates this answer- <?php $con=mysql_connect('localhost','root',''); mysql_select_db('LolStrat',$con); $Champion=$_GET['Champion']; echo $Champion; $Tag=mysql_query("SELECT Tag FROM champions WHERE Name='$Champion'"); echo "<br>"; echo $Tag; ?> The first part works, it fetches the champion name from the URL and prints that. Then I want the query to find the tag of that champion, easily enough explained by the query. I thought $Tag would therefore be "The ChronoKeeper", which is what the database has for that record, only it prints "Resource id #3" in those exact words... Ideas? Thanks. Edit- After a bit more googling, I got some examples and tried those, to no success. <?php $con=mysql_connect('localhost','root',''); mysql_select_db('LolStrat',$con); $Champion=$_GET['Champion']; echo $Champion; $queryone=mysql_query("SELECT Tag FROM champions WHERE Name='$Champion'"); $Tag=mysql_fetch_row($queryone); echo "<br>"; echo $Tag; ?> This generates the word "Array" for $Tag, when it should be "The ChronoKeeper". I also tried Mysql_fetch_object and got a fatal error, could not convert to string. Really confused... 2nd Edit- <?php $con=mysql_connect('localhost','root',''); mysql_select_db('LolStrat',$con); $Champion=$_GET['Champion']; echo $Champion; $queryone=mysql_query("SELECT Tag FROM champions WHERE Name='$Champion'"); $query_row=mysql_fetch_array($queryone); echo($query_row[Tag]); ?> This code generates Zilean Notice: Use of undefined constant Tag - assumed 'Tag' in C:\wamp\www\LolStrategy\ViewChampion.php on line 30 The ChronoKeeper Now If i could just get rid of that notice, i'm done! Any ideas at all?
  8. Damn, people like you should be paid for doing this, I combed through that code for about 25 minutes and didn't spot that.
  9. Two quick questions. First up, will PHP still pull the correct information from this code- while($row = mysql_fetch_array($SearchRes)) { echo "<tr>"; echo "<td>" . $row['ItemType'] . "</td>"; echo "<td>" . $row['ItemPrice'] . "</td>"; echo "<td>" . $row['ItemDetails'] . "</td>"; echo "<td>" . $row['SupplierName'] . "</td>"; $FVPSupp=$row['SupplierName']; echo "<td>"; echo "<form action='ViewSupplier.php' method='POST'>"; echo "<input type='hidden' value='$FVPSupp' name='FVPSupp'>"; echo "<input type='submit' value='View Supplier'>"; echo "</form>"; echo "</td>"; echo "</tr>"; } Now, ignoring most of it, the form hidden in that code is the bit i'm interested in. Basically, the variable $FVPSupp needs to be used in the next page, so will that method of putting it through suffice or not? I thought a button like so- echo "<input type='button' value='View Supplier' onClick='location.href=ViewSupplier.php?name=$FVPSupp'>"; Only that wouldn't work, so I tried this hidden form method. Not sure if its working yet or not due to the next error. I'll need to include the entire page in this topic, sorry for the long thread. <html> <head> <link rel="stylesheet" href="Layout.css" type="text/css"> <link rel="stylesheet" href="View.css" type="text/css"> </head> <body> <div id="Border"> </div> <div id="Header"> <div id="Title"> <div class="TitleText">MiMar Construction Data</div> </div> </div> <div id="LeftSide"> </div> <div id="NavBar"> <br> <input type="button" value="Index" onClick="window.location='Index.html'"><br><br> <input type="button" value="Stats" onClick="window.location='Stats.php'"><br><br> <input type="button" value="Input" onClick="window.location='Input.php'"> </div> <div id="MainContent"><br><br> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Didn\'t connect, what a bitch!'); } mysql_select_db("Construction", $con); $SupplierName=$_POST['FVPSupp']; echo "<div id='SupplierName'>"; echo $SupplierName; echo "</div>"; $query=mysql_query("SELECT Delivery,Reliability FROM suppliers WHERE SupplierName='$SupplierName'"); while ($row = mysql_fetch_array($query)) { echo "<div id='Delivery'>"; echo $row['Delivery']; echo "</div>"; echo "<div id='Reliability'>"; echo $row['Reliability']; echo "</div>"; ?> </div> </body> </html> Now the error my browser(Firefox 3.0. returns is - Line 58 happens to be... </html> which has me baffled to hell and back. Is it trying to tell me the whole page is wrong or something? Maybe i'm not allowed HTML or something? Never seen it before at all, and havn't had much luck googling around. Anyone have any clues?
  10. I have a rough idea what you mean, would help if you posted the code though. You could use mysql_num_rows when you select all of one persons unread mail, so they have 3 mail unread it'll return 3, then use that for the notification, say - $NumReturn=mysql_num_rows($QUERY); echo "You have "; echo $NumReturn; echo " unread messages!"; The query would be selecting all from table(table being a user's mail) where $SomeVariable=1 (1 being unread). I could be completely wrong, only started learning PHP/MySQL about a week ago, but I think that could work..
  11. Thanks for that, seems to have helped some. Now, I have split the variables now to this - (has got rid of the errors somewhat) function InsSupp() { $SupplierName=$_POST['SupplierName']; $Delivery=$_POST['Delivery']; $Reliability=$_POST['Reliability']; $insSupp = mysql_query("INSERT INTO supplier (SupplierName,Delivery,Reliability) VALUES ('$SupplierName','$Delivery','$Reliability')"); echo "Ran Supplier Insert"; } function InsItem() { $ItemType=$_POST['ItemType']; $ItemPrice=$_POST['ItemPrice']; $ItemDetails=$_POST['ItemDetails']; $SupplierName=$_POST['SupplierName']; $insSupp = mysql_query("INSERT INTO item (ItemType,ItemPrice,ItemDetails,SupplierName) VALUES ('$ItemType','$ItemPrice','$ItemDetails,'$SupplierName')"); echo "Ran Item Insert"; } Now, I can fun the first function (InsSupp) perfectly. It works, with no errors and inserts into the database, and I can select it on the InsertItem page. But, after trying to insert an item with InsertItem.php, it tries to run the InsSupp function, returning these errors - Notice: Undefined index: SupplierName in C:\wamp\www\Construction\Input2.php on line 60 Notice: Undefined index: Delivery in C:\wamp\www\Construction\Input2.php on line 61 Notice: Undefined index: Reliability in C:\wamp\www\Construction\Input2.php on line 62 Ran Supplier Insert Now, those lines (60,61,62) are- $SupplierName=$_POST['SupplierName']; $Delivery=$_POST['Delivery']; $Reliability=$_POST['Reliability']; All 3 of which are from the wrong function. They are all in the InsSupp function, so it's trying to run both. Suggests a problem with the calling functions, or syntax of that. Here is the page again, after update - <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Construction", $con); $PageCheck=$_POST['PageCheck']; // check which insert has just been used if ($PageCheck="2") { InsSupp(); // Supplier has just been inserted, run Supplier insert query } else InsItem(); // Item has just been inserted, run Item insert query function InsSupp() { $SupplierName=$_POST['SupplierName']; $Delivery=$_POST['Delivery']; $Reliability=$_POST['Reliability']; $insSupp = mysql_query("INSERT INTO supplier (SupplierName,Delivery,Reliability) VALUES ('$SupplierName','$Delivery','$Reliability')"); echo "Ran Supplier Insert"; } function InsItem() { $ItemType=$_POST['ItemType']; $ItemPrice=$_POST['ItemPrice']; $ItemDetails=$_POST['ItemDetails']; $SupplierName=$_POST['SupplierName']; $insSupp = mysql_query("INSERT INTO item (ItemType,ItemPrice,ItemDetails,SupplierName) VALUES ('$ItemType','$ItemPrice','$ItemDetails,'$SupplierName')"); echo "Ran Item Insert"; } $con = mysql_connect("localhost","root",""); mysql_select_db("Construction", $con); ?> If anyone can see a problem, please point it out
  12. Well, I have 2 pages. InsertItem.php and InsertSupplier.php. InsertItem.php has 4 inputs, ItemType, ItemPrice, ItemDetails and SupplierName InsertSupplier.php has 3 inputs, SupplierName, Delivery and Reliability. The idea is,you input a supplier, then you can load all his items into the database, by adding its type(dropdown choice between 4 set types), price(text input), details(textarea) and then selecting the supplier from the dropdown, which gives you a choice of all the suppliers. I have this bit working. But, when you submit either the InsertItem form, or the InsertSupplier form, I am trying to use Input2.php to figure out which form they submitted, by using a hidden input, with value of 1 on InsertItem, and 2 on InsertSupplier. Then Input2.php checks this, and runs the correct function. Or that is what it's supposed to do anyway, but I have 2 problems. Firstly, I cannot get it to run a function at all, and secondly, it gives me errors for the variables that didnt get filled in (for instance ItemPrice doesnt get filled in on InsertSupplier.php, so Input2.php returns this as an error). I will include the code for all 3 pages, in the hope someone can see what is wrong! InsertItem.php- <form action="Input2.php" method="POST"> <b>Item Type</b>:<br><select name="ItemType"> <option value="Screw">Screw</option> <option value="Nail">Nail</option> <option value="Washer">Washer</option> <option value="Nut">Nut</option> </select> <br><br> <b>Item Price</b>(Per Single Unit):<br>£<input type="Text" name="ItemPrice"> <br><br> <b>Item Details</b><br><textarea height="5" width="30" name="ItemDetails">Input Item Details Here</textarea><br><br> <b>Supplier</b>:<br> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Construction", $con); $graball = mysql_query("SELECT * FROM supplier"); echo "<select name='supplier'>"; while($row = mysql_fetch_array($graball)) { $content = $row['SupplierName']; echo "<option value='$content'>"; echo $content; echo "</option>"; echo $row['SupplierName']; echo "</option>"; } echo "</select>"; ?> <br><br> <input type="hidden" value="1" name="PageCheck"> <input type="submit" value="Submit New Item"> </form> InsertSupplier.php- <form action="Input2.php" method="POST"> <b>Supplier Name</b>:<br><input type="Text" name="SupplierName"><br><br> <b>Delivery Time</b>(Within UK):<br><input type="text" name="Delivery"><br><br> <b>Reliability Rating</b>:<br><input type="Text" name="Reliability"><br><br> <input type="hidden" value="2" name="PageCheck"> <input type="submit" value="Submit New Supplier"> </form> Input2.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Construction", $con); $ItemType=$_POST['ItemType']; $ItemPrice=$_POST['ItemPrice']; $ItemDetails=$_POST['ItemDetails']; $SupplierName=$_POST['SupplierName']; $Delivery=$_POST['Delivery']; $Reliability=$_POST['Reliability']; $PageCheck=$_POST['PageCheck']; // check which insert has just been used if ($PageCheck="2") { InsSupp(); // Supplier has just been inserted, run Supplier insert query } else InsItem(); // Item has just been inserted, run Item insert query function InsSupp() { $insSupp = mysql_query("INSERT INTO supplier (SupplierName,Delivery,Reliability) VALUES ('$SupplierName','$Delivery','$Reliability')"; echo "Ran Supplier Insert"; } function InsItem() { $insSupp = mysql_query("INSERT INTO item (ItemType,ItemPrice,ItemDetails,SupplierName) VALUES ('$ItemType','$ItemPrice','$ItemDetails,'$SupplierName')"; echo "Ran Item Insert"; } ?> As you can see the functions, I can't get those echo's to print, nor will the insert's work. Any ideas?
  13. Say for instance, I want to pull out the path of an image stored in the database, by inputting said image's name in the search form? I know I can pull the whole line out with SELECT * FROM but, if I replace the * with any of the database column names I get answer "Resource ID #3" up to "Resource ID #5" (I want to pull out 3 fields, using the name to get the right row. Possible? I know my English isn't perfect, not my mothertongue This si the code- <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); }; mysql_select_db("CriminalDatabase", $con); $CrimName=$_POST['CrimName']; echo $CrimName; $CrimRes = mysql_query("SELECT * FROM criminals WHERE CrimName='$CrimName'"); if (!$CrimRes) { die('Error: ' .mysql_error()); } else echo "Successful Query!"; echo "<div id='CrimImg'>"; echo $CrimRes; echo "</div>"; mysql_close($con); ?> Now, the echo "Successful Query!" prints when I run this code...Anbd where I told it to print the value of the $CrimNameit prints, yet the result of the query is "Resource id #3"...
×
×
  • 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.