I need urgent help pls

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.

As i said. Put all your records into one table. (And once again, i look at the forum leaders and wonder why this wasnt put in the databases forum)
That table should contain the fields:
‘id’ (or trackingnumber, if you want to use id as an autoincrementing field)
‘Date/Time’ (though i despise having a / in a field name)
‘Event’
‘Location’
‘Details’
‘Type of Move’

Why do you have 2 different tables for 1 page? I dont understand your logic.

Should I run to diff database or what do you advice? Thanks for your assistance and understanding all thru.

Thanks for your help. Am really greatful. It is off different tracking number with each executing diff tables. Each table on a database represent a tracking number. I have table FTYX34555867 & ECMY4572957 which records to run diff tracking numbers. I was thinking of this script, please see if am right…maybe u wd ve a clue of wat I am looking 4.


<?php 
//Connect To Database
$hostname='localhost';
$username='forxample';
$password='xxxxx';
$dbname='forxample';
$usertable='ECMY4572957';
$usertable1='FTYX34555867';

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{

$correct_tracking_numbers2=array(FTYX34555867);
if(in_array($track_number,$correct_tracking_numbers2)){
	$query1= 'SELECT * FROM ' . $usertable1;
	$result = mysql_query($query1) or die(mysql_error());
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>

Step 1: Put all your records in one table. I’m gonna assume it will be called “tracking”.
Step 2: Try this…


<?php
//Connect To Database
$hostname='localhost';
$username='forexamlpe';
$password='xxxx';
$dbname='forexamlpe';
$usertable='tracking';


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{
$query = 'SELECT * FROM ' . $usertable . ' WHERE id = "'.$track_number'"';
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) == 1){
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>';
}
}

NOTE: I assume here that $_POST[‘track_number’] contains exactly 1 tracking number. If this isnt the case, i need to see how you’re inputting the numbers.

Okay #1: Erase your passwords!

#2: You need a basic understanding of how databases work; you’re creating tables when you should be just adding entries to a single table.

#3: Your correct_tracking_numbers should be being filled from the database (or not at all, you should really be using a num_rows check)

I got information on the first usertable and the second 1 as well. With the script, it works as wanted but the only problem I have is, it echo “The tracking number is invalid, Please go back & enter a Valid Tracking Number” wen I track the 2nd usertable and the first as well but though it still run mysql. I want to get rid of the “The tracking number is invalid, Please go back & enter a Valid Tracking Number” stuff…pls help.

Hi can u help me with it pls? I tried this script but wen I run it, it is either is echo the else in the first userstable and vice versa. It execute mysql but still echo “The tracking number is invalid, Please go back & enter a Valid Tracking Number!”. Please let me look into the script and advice pls.

====================

<?php 
//Connect To Database
$hostname='localhost';
$username='forexamlpe';
$password='xxxx';
$dbname='forexamlpe';
$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>';
}
}

//Connect To Database 2
$hostname1='localhost';
$username1='forexamlpe';
$password1='xxxxx';
$dbname1='forexamlpe';
$usertable1='FTYX34555867';

mysql_connect($hostname1,$username1, $password1) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname1);


//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_numbers2=array(FTYX34555867);
if(in_array($track_number,$correct_tracking_numbers2)){
	$query1= 'SELECT * FROM ' . $usertable1;
	$result = mysql_query($query1) or die(mysql_error());
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>

You’re… creating a new table for every number you want to track? I dont think you’ve grasped the basics of a database yet. Filed for this question to be moved to mySQL forum.