Jump to content


Photo

Quick question


  • Please log in to reply
7 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 07 April 2006 - 04:29 AM

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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 07 April 2006 - 07:14 AM

[!--quoteo(post=362440:date=Apr 7 2006, 05:29 AM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 7 2006, 05:29 AM) View Post[/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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 07 April 2006 - 11:52 AM

[!--quoteo(post=362452:date=Apr 7 2006, 03:14 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 7 2006, 03:14 AM) View Post[/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.

#4 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 07 April 2006 - 12:39 PM

[!--quoteo(post=362493:date=Apr 7 2006, 06:52 AM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 7 2006, 06:52 AM) View Post[/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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 07 April 2006 - 06:21 PM

[!--quoteo(post=362498:date=Apr 7 2006, 08:39 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Apr 7 2006, 08:39 AM) View Post[/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:
<?
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");
}
?>

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

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 07 April 2006 - 07:42 PM

One or two comments re your code

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

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


    $id_num = $_get['id_num'];
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
    $id2 = $_POST['id2'];
you don't a form element called 'id2'

(And yes, I did delete the PM)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 07 April 2006 - 11:31 PM

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.

#8 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 08 April 2006 - 04:30 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users