Hi guys,

I did a quick tutorial on the internet on using php and mysql. It is my first ever time using it so forgive me if im being a bit of a "NOOB".

anyways ill post the script below and can you give me a few pointers about where im going wrong?

Bare in mind its my first time using these scripts and phpmyadmin.
--------------------------------------------------------------------------------------------------------------

<?php
$db=mysql_connect("grafax.co.uk", "dbOne", "*password*") or die("Could not connect to localhost."); mysql_select_db("people", $db) or die("Could not find database.");

// The above lines establishes a connection with the database. Keep localhost as is unless something different is mentioned by your sql host. usrnm is user name and pswd is password. What I want to say is, copy these lines as they are and just replace the required fields and it should connect.

$querySQL = "insert into people (d_Name, d_Birthday,
d_Birthday) values ($Name, $Birthday, $Telephone)";
if(!$querySQL) error_message(sql_error());

// The above statement generates an error if you have setup the table in such a way that there should not be a duplicate entry.
?>
<form name="toSave" method="post" action="save_it.php">
  <p>name 
    <input type="text" name="Name" size="100" />
    <br> 
birthday 
<input type="text" name="Birthday" size="50" />
<br> 
telephone 
<input type="text" name="Telephone" size="50" /> 
</p>
  <p>
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>

--------------------------------------------------------------------------------------------------------------

Go on this link to see a screen shot of my database's settings etc.
http://www.grafax.co.uk/db.bmp

--------------------------------------------------------------------------------------------------------------
As far as i know, my database is called either web163-dbone (or as I named it dbone), the table is people, the website is http://www.grafax.co.uk.

If you need any more information just post it in this thread.

Thanks again guys :D
Max

Recommended Answers

All 8 Replies

$querySQL = "insert into people (d_Name, d_Birthday,
d_Birthday) values ($Name, $Birthday, $Telephone)";

Thats wrong. Wrap values in single quote. ie.,

$querySQL = "insert into people (d_Name, d_Birthday,
d_Birthday) values ('$Name', '$Birthday', '$Telephone')";

Cheers,
Nav

Ah okay thanks. Also when i try it now i get the following error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dbOne'@'79.170.40.163' (using password: YES) in /home/sites/grafax.co.uk/public_html/db/save_it.php on line 4
Could not connect to localhost.

Its probably because im putting in the wrong localhost, database and table information. Can you take a quick look at the code im using and this screen shot to make sure the connection info links up?
http://www.grafax.co.uk/db.bmp
Thanks! =]
Max

Hmm.. Are you sure about host, username and password ? The database ("people") you are selecting isn't really a database but its a table. web163-dbone is the database.

ill try changing them around a bit. do you have any suggestions as what to put where?

im not sure what my hostname, user name and passwords are... any ideas? Or any ideas on how to change them?

Substitute correct values to mysql_connect and mysql_select_db.. Are you testing it locally or on a server ? If you are running it on a server, ask your administrator to provide the details.

im the network administrator :D

dont worry, ill send an email to my website registrar or something

Thanks for your help

Max

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.