Jump to content

Quick question


hostfreak

Recommended Posts

How do I retrieve information from a user that is logged in? See what im trying to do is allow users in my system add like trucks and only have the trucks they added show up for them on the truck list page. So what I did was create a unique id for the trucks called id2, and the value of the id2 will be the id_num (the id for the users). That way it matches up and is unique to that user. But everytime I try to add a new truck on a user account, it always uses the id_num of the last user in the database. It's not allowing it to be unique to the user adding it. So I guess im not calling the id_num correctly to target just the id_num of the user logged in.
Link to comment
Share on other sites

[!--quoteo(post=362440:date=Apr 7 2006, 05:29 AM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 7 2006, 05:29 AM) [snapback]362440[/snapback][/div][div class=\'quotemain\'][!--quotec--]
So I guess im not calling the id_num correctly to target just the id_num of the user logged in.
[/quote]
It does seem that way. Without seeing your code, though, it's not too easy to see exactly what you are doing wrong.
Link to comment
Share on other sites

[!--quoteo(post=362452:date=Apr 7 2006, 03:14 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 7 2006, 03:14 AM) [snapback]362452[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It does seem that way. Without seeing your code, though, it's not too easy to see exactly what you are doing wrong.
[/quote]

Hey, thanks for your reply Barand. I have pm'd you the code.
Link to comment
Share on other sites

[!--quoteo(post=362493:date=Apr 7 2006, 06:52 AM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 7 2006, 06:52 AM) [snapback]362493[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hey, thanks for your reply Barand. I have pm'd you the code.
[/quote]

The whole point is to post the problematic code, minus any sensitive information of course, and get input from all members that come across your post. Perhaps Barand has an answer that will work, in fact I am fairly confident this is the case, but perhaps someone else has a better one or may see something that both of you over look. Posting the code keeps you from having to PM multiple people with your code and it keeps people from having an inbox full of code. I know I would just delete it if someone starting PMing me code unless I specifically asked them to PM it to me.
Link to comment
Share on other sites

[!--quoteo(post=362498:date=Apr 7 2006, 08:39 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Apr 7 2006, 08:39 AM) [snapback]362498[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The whole point is to post the problematic code, minus any sensitive information of course, and get input from all members that come across your post. Perhaps Barand has an answer that will work, in fact I am fairly confident this is the case, but perhaps someone else has a better one or may see something that both of you over look. Posting the code keeps you from having to PM multiple people with your code and it keeps people from having an inbox full of code. I know I would just delete it if someone starting PMing me code unless I specifically asked them to PM it to me.
[/quote]


Sorry, Here is the code:
[code]
<?
include("include/session.php");
include("include/constants.inc");
$connection = mysql_connect("$server","$user","$password");
$db = mysql_select_db("$database", $connection);

if($session->logged_in){
include("top.txt")
if ($HTTP_POST_VARS['submit']) {

//Start calling id_num

$connection = mysql_connect("$server","$user","$password");  
$db = mysql_select_db("$database", $connection);    
$id_num = $_get['id_num'];

//end

$connection = mysql_connect("$server","$user","$password");
mysql_select_db ($database);
$name = $_POST['name'];
$city = $_POST['city'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$cca = $_POST['cca'];
$id2 = $_POST['id2'];

$query = "INSERT INTO shippers(name , city , state , phone , cca, id2)

VALUES('$name','$city','$state','$phone','$cca','$id_num')";

$result = mysql_query($query);
echo "<center>The Shipper $shippername has been added to the system<center><br><br>";

}

echo "<br><form name='addshipper' method='post' action=\"".$_SERVER['PHP_SELF']."\"><input type='hidden' name='userlevel' value='1'><center>";
echo "<table border='0' cellpadding='2' cellspacing='0' style='border-collapse: collapse' bordercolor='#cc7358' width='80%'>";
echo "<tr><td width='30%' align='right'><p><font color='#cc7358'><b>Shipper Name:</b></font></td><td width='153%'>&nbsp;<input type='text' name='name'></td>";
echo "</tr><tr><td width='30%' align='right'><font color='#cc7358'><b>City:</b></font></td><td width='153%'>&nbsp;<input type='text' name='city'></td></tr><tr>";
echo "<td width='30%' align='right'><font color='#cc7358'><b>State:</b></font></td><td width='153%'>&nbsp;<SELECT
name=state>
<option>ALABAMA</option>
<option>ALASKA</option>
<option>AMERICAN SAMOA </option>
<option>ARIZONA</option>
<option>ARKANSAS</option>
<option>CALIFORNIA </option>
<option>COLORADO</option>
<option>CONNECTICUT</option>
<option>DELAWARE</option>
<option>DISTRICT OF COLUMBIA</option>
<option>FEDERATED STATES OF MICRONESIA</option>
<option>FLORIDA</option>
<option>GEORGIA</option>
<option>GUAM</option>
<option>HAWAII</option>
<option>IDAHO</option>
<option>ILLINOIS</option>
<option>INDIANA</option>
<option>IOWA</option>
<option>KANSAS</option>
<option>KENTUCKY</option>
<option>LOUISIANA</option>
<option>MAINE</option>
<option>MARSHALL ISLANDS</option>
<option>MARYLAND</option>
<option>MASSACHUSETTS</option>
<option>MICHIGAN</option>
<option>MINNESOTA</option>
<option>MISSISSIPPI</option>
<option>MISSOURI</option>
<option>MONTANA</option>
<option>NEBRASKA</option>
<option>NEVADA</option>
<option>NEW HAMPSHIRE</option>
<option>NEW JERSEY</option>
<option>NEW MEXICO</option>
<option>NEW YORK</option>
<option>NORTH CAROLINA</option>
<option>NORTH DAKOTA</option>
<option>NORTHERN MARIANA ISLANDS</option>
<option>OHIO</option>
<option>OKLAHOMA</option>
<option>OREGON</option>
<option>PALAU</option>
<option>PENNSYLVANIA</option>
<option>PUERTO RICO</option>
<option>RHODE ISLAND</option>
<option>SOUTH CAROLINA</option>
<option>SOUTH DAKOTA</option>
<option>TENNESSEE</option>
<option>TEXAS</option>
<option>UTAH</option>
<option>VERMONT</option>
<option>VIRGIN ISLANDS</option>
<option>VIRGINIA </option>
<option>WASHINGTON</option>
<option>WEST VIRGINIA</option>
<option>WISCONSIN</option>
<option>WYOMING</option>
</td></tr><tr>";
echo "<td width='30%' align='right'><font color='#cc7358'><b>Telephone #:</b></font></td><td width='153%'>&nbsp;<input type='text' name='phone'></td></tr><tr>";
echo "<td width='30%' align='right'><font color='#cc7358'><b>Credit Approved:</b></font></td><td width='153%'>&nbsp;<SELECT
name='cca'><option>Yes</option><option>No</option><option>N/A</option></td>";
echo "</tr></table><br><br><input name='submit' type='submit' value='Add Shipper'></form><br><br></center>";
include("bottom.txt");
}
?>[/code]

It isn't close to the best coding, I've just really started with php. Any help would be appreciated. Thanks.
Link to comment
Share on other sites

One or two comments re your code

[code]$connection = mysql_connect("$server","$user","$password");
$db = mysql_select_db("$database", $connection);
[/code]
Unless you are connecting to multiple database servers, once per page is sufficient.

[code]if ($HTTP_POST_VARS['submit']) {[/code]
Use
[code]if (isset($_POST['submit'])) {[/code]


[code]    $id_num = $_get['id_num'];[/code]
You don't have a $_get array (unless it's in the included files). As your problem is with the $id_num being wrong, it is not possible to see where it comes from in the code.

Also
[code]    $id2 = $_POST['id2'];[/code]
you don't a form element called 'id2'

(And yes, I did delete the PM)
Link to comment
Share on other sites

Im not sure if what my problem is, is understood. The id2 needs to be the id_num. That way on the edit page for each user I can call upon it by if id2 = id_num . That way it only shows the trucks that user added for that user. So what im trying to do is call the id_num of the user thats adding the truck and insert it into the id2. The problem im currently having is that it inserts the id_num of the last user in the database into the id2. So it's not calling upon the id_num of the user logged in.
Link to comment
Share on other sites

You have to get the id_num from the database at some point. I don't see where you have even attempted this. If it is in one of your included pages you need to show the related lines of code from that page as well. You should definitely listen to the suggestions that Barand made. Update your code with Barand's suggestions and show the relavent code from any other files and we can go from there. Also I see you use $shippername, but I don't see where you setup the variable.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.