Page 1 of 2
Whats wrong with this code?
Posted: Sun Aug 17, 2003 5:15 pm
by nick2
I am pretty sure I left something out.. lol refreshing up again.
Code: Select all
<?php
<?
if (isset($_COOKIE["logged_in"])) {
} else {
header( "Location: Http://slices.net/tradingsystem/nologin.html");
exit;
}
?>
<?
$db_name = "slices_net";
$table_name = "trading";
#
$connection = mysql_connect("localhost", "slices", "password")
or die(mysql_error());
#
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
#
$result = my_query("Select * from trading") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "User: " & $row["ID"];
echo "Location: " & $row["location"];
echo "Signature: " & $row["signature"];
}
mysql_free_result($result);
?>
#
?>
Posted: Sun Aug 17, 2003 5:26 pm
by nigma
Code: Select all
<?php
if ($_COOKIEї"logged_in"])
{
$db_name = "slices_net";
$table_name = "trading";
$connection = mysql_connect("localhost", "slices", "password")
or die(mysql_error());
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
$result = mysql_query("Select * from trading") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "User: " . $rowї"ID"];
echo "Location: " . $rowї"location"];
echo "Signature: " . $rowї"signature"];
}
mysql_free_result($result);
}
else
{
header( "Location: Http://slices.net/tradingsystem/nologin.html");
}
?>
I have a few questions myself.
1) Why did you use & instead of the concatenation operator( . )?
2) Why did you have end part of your php code and then start it once more on the very next line:
Code: Select all
<?php
//some code
?>
<?php
//some more code
?>
3) Would you like me to recommend some excellent php tutorials?
Posted: Sun Aug 17, 2003 5:27 pm
by nick2
rofl.. sorry.. that could be why.. I used & cuz i'm use to Visual basics, I started anotehr one up because I heard header doesn't work with other comamnds in the same "thing"
my error:
Fatal error: Call to undefined function: my_query() in /home/virtual/site9/fst/var/www/html/tradingsystem/members.php on line 15
also I removed the double <? tags so theres only 1 now.
the error accurs on:
Code: Select all
<?php
$result = my_query("Select * from trading") or die(mysql_error());
?>
Posted: Sun Aug 17, 2003 5:29 pm
by nigma
No problem. I am happy to be of any assistance whatsoever.
But I am curious to know if the changes I made to the code made the script work?
Posted: Sun Aug 17, 2003 5:30 pm
by nick2
noep they didn't.. and I edited my post look please. ;P see my error.
Posted: Sun Aug 17, 2003 5:58 pm
by Coco
no such thing as my_query()
maybe your meaning mysql_query() ?
Posted: Sun Aug 17, 2003 6:15 pm
by nick2
thx coco... I am having a problem.. how do I make it loop all the ids, locations, and signatures?
it only displays 1 records.
heres the code:
Code: Select all
<?php
<?
if (isset($_COOKIE["logged_in"])) {
} else {
header( "Location: Http://slices.net/tradingsystem/nologin.html");
exit;
}
#
$dbhost = "localhost"; // host name, usually localhost
$dbuser = "slices"; // username used to login
$dbpwd = "editedout"; // password used to login
$dbname = "slices_net"; // the name of your database
mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);
#
$result = mysql_query("select * from trading") or die(mysql_error());
$row = mysql_fetch_array($result);
$ID = $row["ID"];
$location = $row["location"];
$signature = $row["signature"];
mysql_free_result($result);
?>
<html>
<head>
<title>Members View</title>
</head>
<body>
<div align="center">
<center>
<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="51%" id="AutoNumber1">
<tr>
<td width="33%" bgcolor="#999999"><font size="2" face="Verdana">User(s):</font></td>
<td width="33%" bgcolor="#999999"><font size="2" face="Verdana">Location:</font></td>
<td width="34%" bgcolor="#999999"><font size="2" face="Verdana">Signature:</font></td>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="51%" id="AutoNumber2">
<tr>
<td width="33%"><?php echo "$ID"; ?></td>
<td width="33%"><?php echo "$location"; ?></td>
<td width="34%"><?php echo "$signature"; ?></td>
</tr>
</table>
</center>
</div>
</body>
</html>
?>
Posted: Sun Aug 17, 2003 8:14 pm
by nick2
please help me.
Posted: Sun Aug 17, 2003 9:01 pm
by nigma
Code: Select all
while ($row = mysql_fetch_array($result))
{
// Do stuff to each row (i.e. print their values, etc.)
}
And I belive I posted a revised version of your code in which my_query had been changed to mysql_guery...
Posted: Sun Aug 17, 2003 9:59 pm
by nick2
This time it posted my second user record not both..
heres my code:
Code: Select all
<?php
#
$result = mysql_query("select * from trading") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$ID = $row["ID"];
$location = $row["location"];
$signature = $row["signature"];
}
mysql_free_result($result);
?>
?>
I then do <? echo "$ID"; ?>
etc in the html.
Posted: Sun Aug 17, 2003 10:03 pm
by nigma
You should get rid of the #
You should get rid of one of the '?>'
Also, you don't need to do:
You can just do:
Posted: Sun Aug 17, 2003 10:05 pm
by nigma
You also might even be able to do the following depending on how your php.ini file is setup:
Posted: Sun Aug 17, 2003 10:07 pm
by nick2
None of that made a difference. lol >.<
Posted: Sun Aug 17, 2003 10:29 pm
by nigma
Code: Select all
<?php
// You have to connect to mySQL server and select a database!
$result = mysql_query("select * from trading") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$ID = $rowї"ID"];
$location = $rowї"location"];
$signature = $rowї"signature"];
}
mysql_free_result($result);
?>
You should get a book on PHP or at least take advantage of some tutorials or something. You need help finding any contact me.
Posted: Sun Aug 17, 2003 10:41 pm
by nick2
I'm not a complete idiot.. I didn't post my full code.. I posted the part that I needed help on.. common sense really -_-...
erm.