GetDotted Domains

Viewing Thread:
"PHP / mySQL - Help a beginner?"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Thu 04/11/04 at 19:04
Regular
"Picking a winner!"
Posts: 8,502
OK, as part of my final year at uni I have to do an individual project, a rather large one and to start of I need to create a webpage using php and mysql. Won't go into details of what the site has to do as thats not too important right now.
First off the basics.

I've looked at PHP once or twice before, so hopefully that wont be to bad.
Did a bit on SQL ages ago as well as some database work but I'm not sure whats different between SQL and mySQL.

Have downloaded all the stuff for apache, php and mySQL from [URL]http://www.aesthetic-theory.com/learn.php?server2[/URL] and installed before but something went wrong so I'm in the process of installing again just to make sure its all working properly.

Just not sure where to start.
Have a few ebooks to try make things easier but a few things that don't seem to clear....

mySQL files, someone give me an example of one and what the file type they are?

No doubt a few more things will crop up so I'll post them here too :0)

Thanks
Mon 22/11/04 at 15:05
Regular
"Picking a winner!"
Posts: 8,502
This one is confussing me now.
Trying to insert data into a table but also checking to make sure the data is in a suitable format.

Have two files. Userregtest.php
include_once('includes/header.inc');
?>

To Register please fill in all of the details below.




Thank you.














First name:
Last name:
Address:
Town/City:



include_once('includes/footer.inc');
?>

And RegformHandler.php
include_once('includes/header.inc');
include_once('includes/database.inc');

//check that form data entered is valid

if (!$_POST['firstName'] || $_POST['firstName'] == "" || strlen($_POST['firstName']) < 2 || strlen($_POST['firstName']) > 20)
{
echo'

There is a problem with your first name, please make sure you filled one in and that it is betweem 2 and 20 characters long.

';
}
else if (!$_POST['lastName'] || $_POST['lastName'] == "" || strlen($_POST['lastName']) < 2 || strlen($_POST['lastName']) > 20)
{
echo'

There is a problem with your last name, please make sure you filled one in and that it is betweem 2 and 20 characters long.

';
}
else if (!$_POST['address'] || $_POST['address'] == "" || strlen($_POST['address']) < 10 || strlen($_POST['address']) > 255)
{
echo'

There is a problem with your address, please make sure you filled one in and that it is betweem 10 and 255 characters long.

';
}
else if (!$_POST['town'] || $_POST['town'] == "" || strlen($_POST['town']) < 3 || strlen($_POST['town']) > 12)
{
echo'

There is a problem with your Town/City, please make sure you filled one in and that it is betweem 3 and 12 characters long.

';
}


else
{
$first = $_POST['firstName'];

$last = $_POST['lastName'];

$address = $_POST['address'];

$town = $_POST['town'];



$query = "INSERT INTO user(userID, first, last, address, town)
VALUES (3, '$first', '$last', '$address', '$town',)";
$result = mysql_query($query);


if (mysql_affected_rows() == 1)
{
echo '

Your information has been entered into our database. Welcome to the site. Please remember your signup username and password.

';
}
else
{
echo '

There has been a problem with your signup attempt. Please attempt to register again later.

';
}
}
include_once('includes/footer.inc');
?>


If the data entered isn't what it expects then it returns the error message (have tested them all and thats all fine) its just when I enter correct data then when I click submit it is never entered into the database and I get the "There is a problem with your signup...." error.

Anyone know why this dosn't work and how to go about getting it to work?
Cheers

Fri 19/11/04 at 00:22
Regular
"Picking a winner!"
Posts: 8,502
Another thing that I aint to sure about.

I have a smallish system that I'm using to test a few ideas about. User registers some details that are entered into a database, was thinking it would be nice to e-mail the person with the details they signed up with.

Is this possible if I'm just using apache on my pc? Can it actually send an e-mail if I give it the right info or would my files have to be hosted on a suitable web server that others can access?

Cheers
Thu 11/11/04 at 21:47
Regular
"Picking a winner!"
Posts: 8,502
Cheeers, went through my old notes and found the way sql does it.
Then a neighbour droped in the books that had been delivered and they have the mysql database stuff in them which is pretty much the way I thought I'd have to go about it.
Thu 11/11/04 at 21:43
Regular
"Devil in disguise"
Posts: 3,151
AliBoy wrote:

> In Access you join fields by assigning foreign keys, can this be done
> in mySQL? Or do I have to give the attribute another name and then do
> a join in a similar way to how SQL handles them?

You can use foreign keys in MySQL as long as the table is of a type InnoDB. The problem is, where ever you might host your site, the host might not let you create tables of type InnoDB because a) they don't like you using the resource and b) they don't have it installed anyway (the InnoDB engine isn't provided with all installs of MySQL).

In short I'd stick to handling joins yourself, yes you can use them, but maybe not worth the hassle.
Thu 11/11/04 at 17:22
Regular
"Picking a winner!"
Posts: 8,502
Thanks.
Managed to borrow a book and bought another one myself so should hopefully make things a bit easier from now on.

Have a database quiestion though off the top of my head.
Have done quite a bit of database stuff using MS Access and other relational database stuff, even done a little bit in SQL.

In Access you join fields by assigning foreign keys, can this be done in mySQL? Or do I have to give the attribute another name and then do a join in a similar way to how SQL handles them?
Wed 10/11/04 at 21:33
Regular
"It goes so quickly"
Posts: 4,083
Opps, I ment if (isset($_POST['submit'])) {, sorry.
Wed 10/11/04 at 21:28
Regular
"Picking a winner!"
Posts: 8,502
Cheers, had tried the $_POST['submit'] and it wouldn't work.

So whats the difference between that and the if (isset($submit)) ?
Wed 10/11/04 at 21:23
Regular
"It goes so quickly"
Posts: 4,083
Form data is stored in the global $_POST, while query string data (data added to the end of a URL) is stored in the global $_GET.

In this case, you'll want $_POST['submit'], or more than likely:

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

The isset() built-in function checks for a variables existence.
Wed 10/11/04 at 21:01
Regular
"Picking a winner!"
Posts: 8,502
Right, those old global variables again.



if ($submit) {
// process form
$db = mysql_connect("localhost", "name", "pass");
mysql_select_db("mydb",$db);
$sql = "INSERT INTO employee (first,last,address,position) VALUES ('$first', '$last','$address','$position')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>

First name:

Last name:

Address:

Position:



} // end if
?>



Just basic I know but I have no idea what to replace $submit with to get this to work.

Cheers if you can get me on the right track.
Mon 08/11/04 at 23:24
Regular
"Devil in disguise"
Posts: 3,151
cjh wrote:
> Really? I was under the impression MySQL supported SQL completely,
> with a few additional MySQL custom SQL'd extras.
>

Fairly common among DB servers/APIs to find varying degrees of support. All developers think they know best so they inevitably support things in a manner they think is right, irrespective of what the standard might be. :-) As I said originally, its fairly close though. And the stuff thats not supported, if you need any of it, probably picked the wrong DB in the first place.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

The coolest ISP ever!
In my opinion, the ISP is the best I have ever used. They guarantee 'first time connection - everytime', which they have never let me down on.
Thank you very much for your help!
Top service for free - excellent - thank you very much for your help.

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.