Rows,

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
-Rory-
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2003 6:11 am

Rows,

Post by -Rory- »

Hey,
I've been having some problems with a .php script, my first one ever :) . What I wan't to have is a script which displays the infomation from a sql database. I am able to do this, but I want to display one row at a time. At the moment it just lists the data. :( Anyway here is the code so far.

Code: Select all

<?
 //MySQL Variables. $host = "localhost";
$login_name = "*****";
$password = "******";


MySQL_connect("$host","$login_name","$password");


MySQL_select_db("knockou_knockout") or die("Could not select database");


$query = "SELECT * FROM subscribe";
$result = MySQL_query($query);


While($rows = MySQL_fetch_array($result) ) &#123;
$Clan = $rows&#1111;'Clan'];
$Amount = $rows&#1111;'Amount'];
$Accepted=$rows&#1111;'Accepted'];


echo("$Clan, $Amount, $Accepted ");
&#125;

MySQL_close()
?>
Any help would be appreciated
-Rory :)
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Use LIMIT in your mysql statement.
http://www.mysql.com/doc/en/SELECT.html
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

You have no newlines in your script, so it will display a load of info on the same line.

If you're using HTML the you should use:

Code: Select all

echo("$Clan, $Amount, $Accepted <br />\n");
The \n is just for when you view the source, it will look nicer.
If you're not using a browser, then remove the <br /> bit and it should work.
-Rory-
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2003 6:11 am

Post by -Rory- »

Whoa!Thx for all the quick replies guys. I will try these things out now. :)
-Rory-
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2003 6:11 am

Post by -Rory- »

I managed to fix that prob thx all. :) But now I am having another error 8O yes.... Well what I am trying to do is have a form which writes into a sql database. The table is called 'subscribe' , and the table has 5 columns which are 1. Clan .2. Website 3.members 4.website 5.accepted (I will fill number five in myself. :) The first code for the form is

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;align&gt;&lt;center&gt;&lt;form action=subscribe.php method=post&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clan Name:&lt;/u&gt;&lt;/b&gt; 
 &lt;input type=text name=Clan&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Contact Email:&lt;/u&gt;&lt;/b&gt; 
&lt;input name="email" type="text" value=""&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clan Members&lt;/b&gt;&lt;/u&gt;
&lt;br&gt;
&lt;textarea name=members&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clans Website&lt;/b&gt;&lt;/u&gt;
&lt;br&gt;
&lt;input type=text name=website&gt;
&lt;br&gt;
Please check these details are all correct, and then
&lt;input type=submit value=Submit&gt;
&lt;/form&gt;
&lt;/html&gt;
&lt;/head&gt;&lt;/center&gt;
Then this page sends the info to subscribe.php , but this is where the error is :? :P .

The error which I get is
Parse error: parse error, unexpected T_VARIABLE in /home/knockou/public_html/subscribe.php on line 18

I don't really know what that means. I kinda guess it has something to do with the $sql in the code below.
The second file, subscribe.php is

Code: Select all

<?
//MySQL Variables. Edit where necessary
$host = "localhost";
$login_name = "knockou";
$password = "XXXX";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("knockou_knockout") or die("Could not select database");
$Clan=$_post['Clan'];
$email=$_post['email'];
$members=$_post['members'];
$WEBSITE=$_post['website'];

$sql = "INSERT INTO subscribe SET
Clan="$Clan",
email="$email",
members="$members",
WEBSITE="$website",
"); 

$result=mysql_query($mysql)
if ($result) {
echo("Thank you, your details have been taken.")
}else{
echo("There was an error.");
}
MySQL_close()
?>
I really wanna get rid of this error :oops: Does anyone know what I should do? :P
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

You need to escape you double quotes in the sql string:

Code: Select all

$sql = "INSERT INTO subscribe SET
Clan="$Clan",
email="$email",
members="$members",
WEBSITE="$website"
");
-Rory-
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2003 6:11 am

Post by -Rory- »

K thx. Will try that now. :)
-Rory-
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2003 6:11 am

Post by -Rory- »

Well I made the changes you releasedj. :) I now get the row created in the database, but none of the data from the form. I also noticed that there was a missing '(' (I think) so I added that before the insect quote mark. You said that I should add /before " and before the end " . I did that but doesn't that confuse things and make the script think the variable is called $blah\? Anyway, here is the script I now have.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;align&gt;&lt;center&gt;&lt;form action="subscribe.php"&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clan Name:&lt;/u&gt;&lt;/b&gt; 
 &lt;input type="text" name="Clan"&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Contact Email:&lt;/u&gt;&lt;/b&gt; 
&lt;input type="text" name="email"&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clan Members&lt;/b&gt;&lt;/u&gt;
&lt;br&gt;
&lt;textarea name="members"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;b&gt;&lt;u&gt;Clans Website&lt;/b&gt;&lt;/u&gt;
&lt;br&gt;
&lt;input type="text" name="WEBSITE"&gt;
&lt;br&gt;
Please check these details are all correct, and then
&lt;input type=submit value=Submit&gt;
&lt;/form&gt;
&lt;/html&gt;
&lt;/head&gt;&lt;/center&gt;
and subscribe.php

Code: Select all

<?
//MySQL Variables. Edit where necessary
$host = "localhost";
$login_name = "XXXXX";
$password = "XXXXX";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("knockou_knockout") or die("Could not select database");
$Clan=$_post["Clan"];
$email=$_post["email"];
$members=$_post["members"];
$WEBSITE=$_post["WEBSITE"];

$sql = ("INSERT INTO subscribe SET
Clan="$Clan",
email="$email",
members="$members",
WEBSITE="$WEBSITE"
 ");
$result=mysql_query($sql);
if ($result) {
echo("Thank you, your details have been taken .");
}else{
echo("There was an error. Please contact Michael or Sacul.");
}
MySQL_close()
?>
Hope I am not bugging you guys too much. :?
Post Reply