2 Birds, 1 Stone... PHP And Testing

Soldato
Joined
11 Apr 2003
Posts
4,210
Location
Notts
Hi all, finaly got my site working how I want, at least in IE6, and FF, just wanted a few people with other browsers, operating systems, resolutions etc to test it if you can please :)

http://cpanel.lincoln.ac.uk/dci125/index.shtml

Also trying to get my guestbook working, can anyone see anything wrong with the following code for creating my table?:

Code:
<?php
// create table
// connecting to database

$sel=mysql_connect("localhost","cpanelu_dci125","******");
if (!$sel)
  {
  die('Could not connect: ' . mysql_error());
  }

// select database

mysql_select_db("cpanelu_dci125", $sel);

echo "db selected & connected to $sel";

// create table

$dat="CREATE TABLE guestbook
(
commentID int NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(commentID),
Name varchar(15),
Email varchar(40),
Comment varchar(1000)
)";

echo "creating table now";

mysql_query($dat,$sel);

mysql_close($sel);
?>

I get the message:

db selected & connected to Resource id #2creating table now

However when I got to insert a comment it gives the error:

Error: Table 'cpanelu_dci125.guestbook' doesn't exist
 
With:

Code:
<?php
// create table
// connecting to database

$sel=mysql_connect("localhost","cpanelu_dci125","*******");
if (!$sel)
  {
  die('Could not connect: ' . mysql_error());
  }

// select database

mysql_select_db("cpanelu_dci125", $sel);

echo "db selected & connected to $sel";

// create table

$dat="CREATE TABLE guestbook
(
commentID int NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(commentID),
Name varchar(15),
Email varchar(40),
Comment varchar(1000)
)";

echo "creating table now";

mysql_query($dat,$sel);

mysql_error()

mysql_close($sel);
?>

I get the following error:

Parse error: parse error, unexpected T_STRING in /home2/cpanelu/public_html/dci125/guestbook/connect.php on line 35

Edit, nevermind adding a ";" to the end of mysql_error()
fixed that, and I just got the origional message again
 
Last edited:
punky_munky said:
Maybe I'm missing something but can't you use myphpadmin or something like that?

I think the point of the script is to eliminate the need for phpMyAdmin in the future. I'm in the middle of doing exactly the same thing for my CMS. It will allow me to install a complete database + working environment in a few minutes.

jcb33, your code is a little messy - I'll post you mine when I can get onto my PC :)
 
mysql_select_db
(PHP 3, PHP 4, PHP 5)

mysql_select_db -- Select a MySQL database
Description
bool mysql_select_db ( string database_name [, resource link_identifier] )

db name is all that is needed. The page for this function in the php manual even has a worked example.
 
Last edited:
It's better to use link identifier, it's minimally more efficient, but meh.

you're missing the ; after mysql_error() for your second error.

For your SQL syntax, go full blown semantic and backtick your table and column names:
Code:
CREATE TABLE `guestbook`
(
`commentID` INT NOT NULL AUTO_INCREMENT, 
`Name` VARCHAR(15),
`Email` VARCHAR(40),
`Comment` TEXT,
PRIMARY KEY(`commentID`)
)
and afaik varchar() has a limit of 250.
 
I have tried installing a program called wizmysqladmin, however it seems to only allow me to create a primary key, and not alter it, could anyone please help me get this set up :) my msn is 06039966 [at] students.lincoln.ac.uk if you would be willing to help me over msn please add me :)
 
Ok thanks all, managed to get a table created (All be it not the way I wanted to!) But now I cant fetch the data from my table, I am using the following code:

Code:
<?php

$sel = mysql_connect("localhost","cpanelu_dci125","********");
if (!$sel)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cpanelu_dci125", $sel);

$comment = mysql_query("SELECT * FROM guestbook");

while($line = mysql_fetch_array($result))
  {
  echo $line['name'] . " " . $line['email'] . " " .$line['comment'];
  echo "<br />";

  }
mysql_close($sel);
?>

But get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/cpanelu/public_html/dci125/guestbook/display.php on line 13
 
punky_munky said:
Should be
mysql_fetch_array($comment)
Thanks :) only problem now is it looks a total mess e.g:

Andrew Not telling you! Whats with all the latin?
Andrew Not telling you! Whats with all the latin?
Andrew Etc Ooops sorry for the double post!

I want it to look like this:

Name: Andrew

Email: Not Telling You!

Comment: Whats with all the latin?

________________________________________________________

Name: Andrew

Email: Etc

Comment: Ooops sorry for the double post!

________________________________________________________
 
Is this method valid?

Code:
while($line = mysql_fetch_array($comment))
  {
  echo "Name: ";
  echo $line['name'];
  echo "<br />";
  echo "Email: ";
  echo $line['email'];
  echo "<br />";
  echo "Comment: ";
  echo $line['comment'];
  echo "<br />";
  echo "<br />";
  echo "<hr />";

  }
mysql_close($sel);
?>

Edit, also how can i make it so it displays the newest comment on top, down to oldest?
 
Last edited:
Looking at w3 schools I found some bits and bobs, and im currently trying to get it so that a user can input their email into a form, and they will then get an email, I can make it email me at a set address, however I cannot make it take the email from the form and send to that, I currently have:

Code:
			<?php
				mysql_query("SELECT * FROM newsLetter);
				$to = "$email";
				$subject = "Welcome!";
				$txt = "Dear User, this is just a quick email to thank you for signing up to the OCV newsletter!We look forward to sending you many exciting newsletters in the future! Thanks again the OCV Team!";
				$headers = "From: OverclockersVortex.co.uk" . "\r\n" .
				"CC: [email protected]";
				mail($to,$subject,$txt,$headers);
				?>
			<?php

But that is not working, any ideas?
 
Back
Top Bottom