Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,645 members, 7,809,434 topics. Date: Friday, 26 April 2024 at 09:34 AM

I Need Help Pls On My Php Script - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Help Pls On My Php Script (794 Views)

How To Improve My Php Skills / My Php Diary / How Do I Install Php, My Sql To Kit Start My Php Programming Lesson. (2) (3) (4)

(1) (Reply) (Go Down)

I Need Help Pls On My Php Script by mby247: 8:24pm On Jun 05, 2010
Pls I need help. I got two tables on a database but I dont know how to run them independently. Please find below our script. It is a shipping tracking website. All I want is each table to run independently once tracked.

-------------------------------------------------

<?php
//Connect To Database
$hostname='localhost.com';
$username='forexample';
$password='xxxx';
$dbname='example';
$usertable='ECMY4572957';

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

//This array contains all correct tracking numbers
$track_number = $_POST['track_number'];
if(empty($track_number)){
    die('<b>Please go back & enter tracking number</b>');
}
else if(strlen($track_number) <= 0 || strlen($track_number) > 15){
    die('<b>Invalid tracking number, please go back</b>');
}
else{
$correct_tracking_numbers=array(ECMY4572957, BHSZ006933);
if(in_array($track_number,$correct_tracking_numbers)){
$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query) or die(mysql_error());
echo "<table border='5'>
<tr>
<th>Date/Time</th>
<th>Event</th>
<th>Location</th>
<th>Details</th>
<th>Type of Move</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['Date/Time'] .  "</td>";
echo "<td>" . $row['Event'] .  "</td>";
echo "<td>" . $row['Location'] .  "</td>";
echo "<td>" . $row['Details'] .  "</td>";
echo "<td>" . $row['Type of Move'] .  "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";

}else{
echo '<b>The tracking number is invalid, Please go back & enter a Valid Tracking Number!</b>';
}
}
?>
</body>
</html>


How do I write or connect the second usertable to the php file as the first script which is working fine once tracked? The table name is "FTYX34555867". I don't know how to run or write multiple table on same database. All I need is, how to connect multiplt tables so each table can run different tracking number. Am stress as am not getting it well. Please help me.
Re: I Need Help Pls On My Php Script by lojik(m): 11:47pm On Jun 06, 2010
You don't connect to tables in SQL, u connect to database whc u've done. U just query any contained table once u've connected to d database.
E.G:

$query = "SELECT * FROM FTYX34555867 WHERE tracking_number = '$track_number'";
$result = mysql_query($query) or die(mysql_error());

OR
$query = "INSERT INTO FTYX34555867(Event,Location,Details) VALUES('my event','my location','my details')";
mysql_query($query) or die(mysql_error());

A better illustration can be given if u explain what u wanna do on the second table.
Re: I Need Help Pls On My Php Script by mby247: 10:15am On Jun 07, 2010
Dear friend,
Thanks for the assistance and help. Must greatful and I really appreciate. The main problem am having is, I got 2 tables in a database, am I correct if I write it this way?

//Connect To Database
$hostname='localhost';
$username='fooexample';
$password='xxxxxx';
$dbname='fooexample';
$usertable='ECMY4572957';
$usertable2='FTYX34555867';
$usertable3='FTYS56869456';
$usertable4='GTVX34554367';

Also how to I run each table independently, the logic is it is a shipping website and the table are tracking history for each customer. I want them to be able to view the tracking history on the table without them seeing the order table. As you can see below the script if for the first table, so I do I go about with the other tables? Can you please explain.

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

//This array contains all correct tracking numbers
$track_number = $_POST['track_number'];
if(empty($track_number)){
die('<b>Please go back & enter tracking number</b>');
}
else if(strlen($track_number) <= 0 || strlen($track_number) > 15){
die('<b>Invalid tracking number, please go back</b>');
}
else{
$correct_tracking_numbers=array(ECMY4572957, BHSZ006933);
if(in_array($track_number,$correct_tracking_numbers)){
$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query) or die(mysql_error());
echo "<b>Container Number: ECMY4572957</b>";
echo "<br>";
echo "<br>";
echo "<b>B/L Number: BHSZ006933</b>";
echo "<br>";
echo "<br>";
echo "<b>Estimated Delivery: 14 Days</b>";
echo "<br>";
echo "<br>";
echo "<b>Port of Loading : Port Klang, Malaysia</b>";
echo "<br>";
echo "<br>";
echo "<b>Port of Transshipment : Port Moresby, Papau New Guinea</b>";
echo "<br>";
echo "<br>";
echo "<b>Port of Discharge/Unloading: Port Honiara, Solomon Island</b>";
echo "<br>";
echo "<br>";
echo "<b>NOTE</b>:<i>Container to be transshipped with another Shipping Line in Papau New Guinea. Once container is <br>transshipped, we would advice the delivery carrier and their Agent contact details in Solomon Island.</i></br>";
echo "<br>";
echo "<br>";
echo "<b>SHIPMENT HISTORY</b>";
echo "<br>";
echo "<table border='5'>
<tr>
<th>Date/Time</th>
<th>Event</th>
<th>Location</th>
<th>Details</th>
<th>Type of Move</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['Date/Time'] . "</td>";
echo "<td>" . $row['Event'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "<td>" . $row['Details'] . "</td>";
echo "<td>" . $row['Type of Move'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";

}else{
echo '<b>The tracking number is invalid, Please go back & enter a Valid Tracking Number!</b>';
}
}
?>
</body>
</html>
Re: I Need Help Pls On My Php Script by DonSegmond(m): 6:20am On Jun 08, 2010
$query = mysql_query('SELECT * FROM firsttablewink
$query2 = mysql_query('SELECT * FROM othertable');


something like that.
BTW, you need to learn about MVC, how to separate code and data/html.
then you need to learn security, your web app will be so easy to hack.

good luck.

(1) (Reply)

Settings / Help Me / Integration Of Network Management System (nms) To Helpdesk Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 28
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.