Log in

View Full Version : Auto Insert Username


99SIVTEC
09-01-2003, 04:53 AM
I'm making a timeslip database for one of my car sites. On the page where a user can submit their own timeslip I would like the "driver" name field to automatically fill in with the persons screen name from the vbulletin forum. Is this possible? Can anyone shed some light on how I would go about this? In the displayed results I would also like to have the username linked to their profile as well if possible.

EvilLS1
09-01-2003, 05:16 AM
Will this file be in your vB directory? If so:

Make sure your php file contains this:

require('./global.php');


And then use this as the default input value in your form:

<a href="member.php?s=$session[sessionhash]&action=getinfo&userid=$userid">$bbuserinfo[username]</a>

99SIVTEC
09-01-2003, 04:06 PM
Ok, I added that, but when I display the results it is just showing $bbuserinfo[username]. Now does it matter if i'm using a different database for this hack apart from my vbulletin db? Should I just go ahead and add the contents of this database to my vb? Maybe that is the problem

99SIVTEC
09-01-2003, 04:06 PM
btw, sorry i'm pretty new to all of this

assassingod
09-01-2003, 04:09 PM
The file has to be in PHP format (.PHP) also, if you arent using HTML in the file, you use


echo("<a href=\"member.php?s=$session[sessionhash]&action=getinfo&userid=$userid\">$bbuserinfo[username]</a>");


If you are using HTML, use


<?php
echo("<a href=\"member.php?s=$session[sessionhash]&action=getinfo&userid=$userid\">$bbuserinfo[username]</a>");
?>

99SIVTEC
09-01-2003, 04:52 PM
here are the contents of my timeslipadd.php which is the part that actually adds the timeslip info to the database. The part that i'm trying to get to display the username is "DRIVER"

<?php
require('./global.php');
include ("mainfile.php");
$index = 1;
global $menu_id,$menu,$Pmenu,$activeusers;
$Pmenu="P_thememenu_homepage";
include("header.php");
?>
<body bgcolor="c9cace" text="000000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"><center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#333D4D" width="100%">
<tr>
<td width="100%">
<div align="center">
<center>
</center>
</div>
<div align="center">
<center>
</center>
</div>
<div align="center">
<center>
</center>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4" background="/vbulletin/images/bg.jpg">
<tr>
<td width="100%" align="center" bgcolor="ececec">

<?php

$dbh=mysql_connect ("localhost", "xxxxxxx", "xxxxxxx") or die ('I cannot connect to the database.');
mysql_select_db ("xxxxxxx_forums");

if($submit == "submit")

{
$sql = "INSERT INTO TIMESLIPS (DRIVER,MAKE,MODEL,YEAR,INDUCTION,ET,TRAP,LOCATION )
VALUES ('$DRIVER','$MAKE','$MODEL','$YEAR','$INDUCTION',' $ET','$TRAP','$LOCATION')";
$result = mysql_query($sql);
if (!$sql) {
echo mysql_error();
}
echo"<META HTTP-EQUIV='refresh' content='0;URL=http://www.sportcompactracing.com/vbulletin/TIMESLIP.php'>";
}
Else
{
?>
<form method=post action='<?php echo $PHP_SELF?>'>
<p><font color="000000">Driver<br>
<input name="DRIVER" type="text" value="&lt;a href=&quot;member.php?s=$session[sessionhash]&amp;action=getinfo&amp;userid=$userid&quot;&gt;$bbuserinfo[username]&lt;/a&gt;"member.php?s=$session[sessionhash]&action=getinfo&userid=$userid">
<br>
make<br>
<select name="MAKE" size="1" id="MAKE">
<option>Acura</option>
<option>Audi</option>
<option>BMW</option>
<option>Chevrolet</option>
<option>Dodge</option>
<option>Ford</option>
<option>Honda</option>
<option>Lexus</option>
<option>Mazda</option>
<option>Mercedes</option>
<option>MINI</option>
<option>Mitsubishi</option>
<option>Nissan</option>
<option>Porsche</option>
<option>Saab</option>
<option>Subaru</option>
<option>Toyota</option>
<option>Volkswagen</option>
<option>Volvo</option>
</select>
<br>
model<br>
<input type=Text name='MODEL' >
<br>
year<br>
<select name="YEAR" size="1" id="YEAR">
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
<option>1984</option>
<option>1985</option>
<option>1986</option>
<option>1987</option>
<option>1988</option>
<option>1989</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
</select>
<br>
Power Adder<br>
<select name="INDUCTION" size="1" id="INDUCTION">
<option>N/A</option>
<option>Turbocharged</option>
<option>Supercharged</option>
<option>Nitrous Oxide</option>
<option>Other</option>
</select>
<br>
ET<br>
<select name="ET" size="1" id="ET">
<option>9.00</option>
<option>9.10</option>
<option>9.20</option>
<option>9.30</option>
<option>9.40</option>
<option>9.50</option>
<option>9.60</option>
<option>9.70</option>
<option>9.80</option>
<option>9.90</option>
<option>10.00</option>
<option>10.10</option>
<option>10.20</option>
<option>10.30</option>
<option>10.40</option>
<option>10.50</option>
<option>10.60</option>
<option>10.70</option>
<option>10.80</option>
<option>10.90</option>
<option>11.00</option>
<option>11.10</option>
<option>11.20</option>
<option>11.30</option>
<option>11.40</option>
<option>11.50</option>
<option>11.60</option>
<option>11.70</option>
<option>11.80</option>
<option>11.90</option>
<option>12.00</option>
<option>12.10</option>
<option>12.20</option>
<option>12.30</option>
<option>12.40</option>
<option>12.50</option>
<option>12.60</option>
<option>12.70</option>
<option>12.80</option>
<option>12.90</option>
<option>13.00</option>
<option>13.10</option>
<option>13.20</option>
<option>13.30</option>
<option>13.40</option>
<option>13.50</option>
<option>13.60</option>
<option>13.70</option>
<option>13.80</option>
<option>13.90</option>
<option>14.00</option>
<option>14.10</option>
<option>14.20</option>
<option>14.30</option>
<option>14.40</option>
<option>14.50</option>
<option>14.60</option>
<option>14.70</option>
<option>14.80</option>
<option>14.90</option>
<option>15.00</option>
<option>15.10</option>
<option>15.20</option>
<option>15.30</option>
<option>15.40</option>
<option>15.50</option>
<option>15.60</option>
<option>15.70</option>
<option>15.80</option>
<option>15.90</option>
<option>16.00</option>
<option>16.10</option>
<option>16.20</option>
<option>16.30</option>
<option>16.40</option>
<option>16.50</option>
<option>16.60</option>
<option>16.70</option>
<option>16.80</option>
<option>16.90</option>
<option>17.00</option>
<option>17.10</option>
<option>17.20</option>
<option>17.30</option>
<option>17.40</option>
<option>17.50</option>
<option>17.60</option>
<option>17.70</option>
<option>17.80</option>
<option>17.90</option>
<option>18.00</option>
</select>
<br>
Trap Speed<br>
<input type=Text name='TRAP'>
<br>
Location<br>
<input type=Text name='LOCATION'>
<br>
</font><br>
<input type=submit name=submit value=submit>
</p>
</form>
<?
}
?>
<?php
echo "<br>";
include("footer.php");
?>

99SIVTEC
09-01-2003, 04:56 PM
Then this is the main file that displays the results (I haven't worked on it too much).

<?php
require('./global.php');
include ("mainfile.php");
$index = 1;
global $menu_id,$menu,$Pmenu,$activeusers;
$Pmenu="P_thememenu_homepage";
include("header.php");
?>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#333D4D" width="100%">
<tr>
<td width="100%" bgcolor="f5f5f5">
<div align="center">
<center>
</center>
</div>
<div align="center">
<center>
</center>
</div>
<div align="center">
<center>
</center>
</div>
<div align="center">
<p><font size="2" face="Arial, Helvetica, sans-serif"><a href="timeslipadd.php"><font color="123642" class="nf"><b>Add
your Timeslip to the Database</b></font></a> </font></p>
</div>
<tr>
<td width="100%"> <table width="98%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000">
<tr bgcolor="0072BC">
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=DRIVER">Driver</a>
</font></div></th>
<!-- the other six headers omitted... -->
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=MAKE">Make</a>
</font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=Model">Model</a>
</font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=Year">Year</a>
</font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=Induction">Power
Adder</a> </font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=ET">1/4
Mile ET</a> </font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=Trap">Trap
Speed</a> </font></div></th>
<th>
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="TIMESLIP.php?sortby=LOCATION">Track
Name</a> </font></div></th>
</tr>
<?
if(empty($sortby)) $sortby = "ET";
$dbh=mysql_connect ("localhost", "xxx_xx", "xxxxxx") or die ('I cannot connect to the database.');
mysql_select_db ("xxx_forums");
$result = @mysql_query("SELECT * FROM TIMESLIPS ORDER BY $sortby");
if (!$result)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
while ($row = mysql_fetch_array($result))
{
$driver = $row["DRIVER"];
$make = $row["MAKE"];
$model = $row["MODEL"];
$year = $row["YEAR"];
$induction = $row["INDUCTION"];
$et = $row["ET"];
$trap = $row["TRAP"];
$trackname = $row["LOCATION"];
?>
<tr bgcolor="f5f5f5">
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$driver?>
</font></div></td>
<!-- six other columns here...-->
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$make?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$model?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$year?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$induction?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$et?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$trap?>
</font></div></td>
<td>
<div align="center"> <font color="000000" size="2" face="Arial, Helvetica, sans-serif">
<?=$trackname?>
</font></div></td>
</tr>
<?
}
?>
</table><font size="2" face="Arial, Helvetica, sans-serif"></body></font>
<font size="2" face="Arial, Helvetica, sans-serif">
<?php
echo "<br>";
include("footer.php");
?>
</font>

assassingod
09-01-2003, 05:03 PM
Apologies but I thought you were doing something else, so my code won't work.

99SIVTEC
09-01-2003, 05:10 PM
Not a problem. That's why I just went ahead and put the code up so you guys know what i'm trying to do :)

99SIVTEC
09-02-2003, 12:14 AM
Ok, so when I use

<?php
echo("<a href=\"member.php?s=$session[sessionhash]&action=getinfo&userid=$userid\">$bbuserinfo[username]</a>");
?>


In my form as a test it properly displays my username, but the link to the profile is wrong. It takes me to :

http://www.mywebsite.com/vbulletin/member.php?s=&action=getinfo&userid=

it leaves the userid off from what I can tell.

When I use

<a href="member.php?s=$session[sessionhash]&action=getinfo&userid=$userid">$bbuserinfo[username]</a>



as the default value for my form it kind of works, but the results page doesn't display the username. It only displays:

$bbuserinfo[username]

Which then links to :

http://www.mywebsite.com/vbulletin/member.php?s=$session[sessionhash]&action=getinfo&userid=$userid

which isn't correct.

Any idea's? I'm trying everything I can think of. I plan to just use the echo command to display the username on the timeslipadd page, then a hidden form to actually insert into the database, or can I actually use an insert command to get the username into that field at the same time they submit the rest of teh data via the form?

Thanks for all the help guys. I think we are close

EvilLS1
09-02-2003, 02:53 AM
I would suggest storing the timeslip info in the user or userfield table of the vb database and also calling templates to display the html instead of putting it in the php file.

99SIVTEC
09-02-2003, 03:58 AM
Today at 04:53 AM EvilLS1 said this in Post #11 (https://vborg.vbsupport.ru/showthread.php?postid=430599#post430599)
I would suggest storing the timeslip info in the user or userfield table of the vb database and also calling templates to display the html instead of putting it in the php file.

Honestly though I have no idea where to even start to acomplish something like that. This is pretty much my first php program to date. Another hurdle might also be down the road. I "might" make this script into its own website, or at least build a site around it. I have a network going and this would fit that theme. Is there any way to do what i'm looking for without completely integrating it? I did go ahead and move the timeslip table into the vbulletin database for now.

assassingod
09-02-2003, 05:50 AM
Try this


<?php
echo("<a href=\"member.php?s=$session[sessionhash]&action=getinfo&userid=$bbuserinfo[userid]\">$bbuserinfo[username]</a>");
?>

99SIVTEC
09-02-2003, 05:59 AM
Cool, that worked to link the username to the profile :). Thank you

Now I just need to figure out how to get that same data to post to the database.

assassingod
09-02-2003, 06:05 AM
Im not sure if it'll work, but try replacing;

$sql = "INSERT INTO TIMESLIPS (DRIVER,MAKE,MODEL,YEAR,INDUCTION,ET,TRAP,LOCATION )
VALUES ('$DRIVER','$MAKE','$MODEL','$YEAR','$INDUCTION',' $ET','$TRAP','$LOCATION')";

with

$sql = "INSERT INTO TIMESLIPS (DRIVER,username,MAKE,MODEL,YEAR,INDUCTION,ET,TRAP ,LOCATION)
VALUES ('$DRIVER',''".addslashes(htmlspecialchars($ausername))."',$MAKE','$MODEL','$YEAR','$INDUCTION','$ET','$TRA P','$LOCATION')";


That should be it but I dunno if it'll work (or even if thats what you want)

99SIVTEC
09-02-2003, 06:29 AM
it doesn't appear to add the data to the database after making that change.

99SIVTEC
09-02-2003, 06:35 AM
wait, I jumped the gun. I changed it to replace the $DRIVER variable. Now the data posts to the database, but the DRIVER field is blank i nthe results. That syntax must be just a bit off. I think we are on the right track though. My sql looks like this now

$sql = "INSERT INTO TIMESLIPS (DRIVER,MAKE,MODEL,YEAR,INDUCTION,ET,TRAP,LOCATION )
VALUES ('".addslashes(htmlspecialchars($ausername))."','$MAKE','$MODEL','$YEAR','$INDUCTION','$ET','$TR AP','$LOCATION')";

assassingod
09-02-2003, 06:36 AM
didn't think it would. There is a way I just can't think what:ermm:

99SIVTEC
09-02-2003, 06:43 AM
wonder if I can use this? http://www.htmlgoodies.com/beyond/jspass.html#place

I "might" be able to use javascript to pass the <a href=\"member.php?s=$session[sessionhash]&action=getinfo&userid=$bbuserinfo[userid]\">$bbuserinfo[username]</a> variable to the form value. Forms don't seem to like html as a value so this ight be away around that.

assassingod
09-02-2003, 06:51 AM
Could work

99SIVTEC
09-02-2003, 04:55 PM
Didn't work, or at least not the way I tried it. Anyone else have idea's? I'm sure someone has done this before.

99SIVTEC
09-02-2003, 08:16 PM
Ohhhh I got it to work I used <?php
$var = "$bbuserinfo[username]";
echo "<input name=\"DRIVER\" type=\"hidden\" value=\"$var\">\n";
?>

It doesn't create a link to the persons profile, but i'll work on that.

assassingod
09-03-2003, 05:30 AM
Glad you got it working.