Help with my code

If you are using FIrefox, install firebug as an extension. That will help you trouble shoot

If you are using Chrome, look under tools/developer tools. That will also help you find your mistakes.

Why not post your transmit files, you may have an error there

I am using IE9.

Hosting with Godaddy.

transmit.php code

<?php $server ='hosename' EXTRACTED FROM HOSTING PROVIDER AC DETAILS'; $user ='DB NAME'; $pass ='DBPASSWORD'; $db ='DBNAME'; $mysqli = new MySQLi ($server,$user,$pass,$db); ?>

I am off to my daughter place in 1 hour and will not be back until tomorrow afternoon - she had a plumbing problem and lives 210k away (The wide open spaces of Australia) - so if that is alright, catch up then

Ok then, Houston we have a small problem :slight_smile:

This is the way it should look:

[php]
$server =‘localhost’’; //this is usually “localhost”
$user =‘Your user name’; //godaddy user name
$pass =‘The godaddy password you use’;
$db =‘The actual table name’;

$mysqli = new MySQLi ($server,$user,$pass,$db);[/php]

Now if you want to use it the way it is, you have to do this:

[php]
DEFINE DB_NAME = “ozwaz”;//Whatever your godaddy username is
DEFINE DBPASSWORD = “XXXXXXXX”; //your godaddy password
DEFINE DBNAME = “your db name”;

$server =‘localhost’;
$user =‘DB_NAME’;
$pass =‘DBPASSWORD’;
$db =‘DBNAME’;

$mysqli = new MySQLi ($server,$user,$pass,$db);[/php]

I think what you are calling hosename is supposed to be “hostname”. Unless godaddy is totally different then that should be $server = “localhost”

I think IE9 has developer tools. You may want to look for it in the menus

Back home again

I find things a little confusing thanks to the English language.

I have an OVERALL account with Godday it has a username and password

I have an HOSTING account with Godday it has a username and password and of course now

I have a DATABASE with Godday’s HOSTING Ac. it of course has a username and password

from the ADMIN section of the HOSTING Ac, Godaddy tells me that for my MYSQL this:

Hostname: (the database name).db.[color=pink](string of numbers)[/color].hostedresource.com

Godaddy also gives you the give you suggested source code

It is this

<?php //Variables for connecting to your database. //These variable values come from your hosting account. $hostname = "[color=pink]mydbHname[/color].db.[color=pink](string of numbers[/color]).hostedresource.com"; $username = "[color=pink]mtdbUname[/color]"; $dbname = "[color=pink]mydbname[/color]"; //These variable values need to be changed by you before deploying $password = "your password"; $usertable = "your_tablename"; $yourfield = "your_field"; //Connecting to your database mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); //Fetching from your database table. $query = "SELECT * FROM $usertable"; $result = mysql_query($query); if ($result) { while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; echo "Name: $name
"; } } ?>

However I am working my way through an online tutorial and the information/coding is different and of course I just have to little knowledge at present to make enough sense of the material provided.

You will use the database name and password for this. And of course you will use your database name.

When you have a database made, you will create a table inside that database with your fields

You use the database name to connect, then the table name for queries

When you insert code like you did, in the menu above you will see an icon that says php. Click that and put your code between the [php code here [/php. It will make is much easier to read. Do not add your own php tags

A. BY “in the menu above” do you mean on this page “http://www.phphelp.com/forum/beginners-learning-php/help-with-my-code/?action=post;last_msg=76619”?

as I cannot locate an icon that just say “php”

OR

do you mean in my code writing program?

B.-In the database I have set up on my web site I have inserted a table and populated three fields
“id” -PRIMARY
"first’
“family”

as shown in my original post

as you know I am attempting to populate those fields from the web site using the form and a separate file for communication with DB. called “transmit.php

This is how the tutorial instructed.

I have tried using the code as provided by the tutorial (M1 )and then tried Godaddy’s (M2) with what I think was the correct identity code - but as yet I cannot get it to work.

M1 seems to work on the web site but does not populate the DB
M2 gives this error

"
Name: Onserver
Name: Onserver
Name: OnServer
"

When you respond to me look right above where you are typing. You see B I U and further down php just above the smiliys.

I was looking back over your code and you are including

"Warning: include() [function.include]: Failed opening ‘transmitphp’ for inclusion (include_path=’.;C:\php5\pear’) in D:\Hosting\7995904\html\view.php on line

Notice that you do not have a period in the file name. It should be “transmit.php”

Okay - Thanks on both accounts.

Here is my current code

Submission Form (form.html)

[php]

First Name
Family Name
   

[/php]

[b]Communication Form /b

[php]

<?php //Variables for connecting to your database. //These variable values come from your hosting account. $hostname = "Godaddy IP address for where db is located "; $username = "username"; $dbname = "dbname"; //These variable values need to be changed by you before deploying $password = "thesetupdbpassword"; $usertable = "client"; $yourfield = "first"; $yourfield = "family"; //Connecting to your database mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); //Fetching from your database table. $query = "SELECT * FROM $usertable"; $result = mysql_query($query); if ($result) { while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; echo "Name: $name
"; } } ?>

[/php]

Enquiry Form (view.php)

[php]

<?php include ("comm.php"); if ($result = $mysqli->query("select * from client order by id")) { if($results->num_rows>0) { echo ""; echo ""; while ($row = $result->fetch_object()) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
ID First Name Family Name
" . $row->id ."" . $row->first ."" . $row->family ."
"; } } else { echo "Error" . $mysqli->error; } $mysqli->close(); ?>

[/php]

Which produces No input into the Table and no enquiry result - just the errors shown previously.

Ok, when you connect
[php]mysql_connect($hostname, $username, $password) OR DIE (“Unable to
connect to database! Please try again later.”);[/php]

it needs to have a variable with it.
[php]$conn = mysql_connect($hostname, $username, $password) OR DIE (“Unable to
connect to database! Please try again later.”);[/php]

http://www.w3schools.com/php/php_mysql_connect.asp (read this page and the PHP database links with it.)

Next, you are using comm.php as your form action, but in comm.php you only select data, you do not insert it into your database.

form.php => comm.php(form results get put into table. You need the insert command here.)
enquiry.php => comm.php(get data) => enquiry.php for display

In short you are not putting the results from your form into your database table. Therefore you will not get any results back. You need to do that in comm.php. You might try putting some dummy data into your table to see if you can get that data to display

I am not real familiar with MSQLI but here is a possible solution to get stuff into your database from your form(comm.php)

[php]
if(isset($_POST)) { //this is when you submit your form

$first = $_POST[‘first’];
$family = $_POST[‘family’];

$query = INSERT INTO client (name, family)Values($name, $family); //insert into db

if($query) {
echo “one record added”;
}
}
[/php]

Read http://www.w3schools.com/php/php_mysql_insert.asp

the guys over at php.net have been warning us for years and now I guess the time is getting nearer when mysql_… will cease to work.

I suggest before you get any deeper into it you have a read of this and this.
The first link is to php.net which explains about mysql v mysqli.
The second link is to a tutorial within this site that Jim wrote about PDO.

Read both articles, choose a new ‘way’ and dive in.
Whichever one you choose is up to you as I believe it’s a matter of personal preference as I use one and many others in here use the other.

I really can’t stress this enough - make sure you change to one or the other.
Do not continue to use mysql_… or you will wake up one morning in the near? future and every website you built will have stopped working.

Red :wink:

@Red
He is using MYSQLI driver from a tutorial. I use PDO myself. He isnt using named parameters and all that yet. So you are correct.

I think one of the best things he can do is download WAMP and work on local host to learn before he goes live on the net.

That would be very wise - good shout! :wink:

That for the more advice - I really appreciate the assistance and advice from this community.

It is obviously easy to see that until four weeks ago I have had nothing to do with databases on a website, although I first started writing computer programs 30 years ago and have had a static website for the last 13.

I understand it will take me a while to get my head around PHP language and the then the MYSQL database system and I am prepared to persevere until I find the information I need and this forum is excellent in that regards and I do appreciate the assistance.

However I have found it quite a daunting task for a number of reasons

Firstly, nothing changes as fast as technology.

Much of the material on the Internet appears to be out dated and you can spend a lot of time learning material that is no longer applicable. The tutorial I am following was written in 2011.

The other problem is more based on educational psychology.

That is, when you know something and you have been doing it and progressing with it, for a while, a process can appear plainly obvious and relatively simple to the adviser but to the uninitiated it can be quite puzzling. Try asking a person who has lived in an area, for a long time, for directions to somebody’s place and I’m certain you’ll end up lost or try teaching a child to write.

I have downloaded and installed XAMPP on my computer and have attempted to teach myself using that process however again all the literature I have access to so far, in setting up a database, locating it and getting it to work on my computer has not delivered the desired outcome.

I figured that as my web hosting service provider has already done that (provided a data base system) and eventually I need to be able to use that system, my best option was to learn how to do it directly in the environment in which it must would operate.

I have read all the literature on MYSQL “Building a Database-Driven Web Site Using PHP and MySQL” (http://dev.mysql.com/tech-resources/articles/ddws/) which while useful as background information is useless for my specific process because it is dated and in a few instances technically inaccurate.

php.net will to be a very useful site, but for an absolute beginner it is not well structured or readily designed site for that purpose. Naturally enough it’s purpose is to cater for the programming profession and experienced enthusiasts.

Don’t misunderstand, I think it’s wonderful that people freely devote their time and knowledge to the service of the community and any contribution they make should always be gratefully received and appreciated.

However so far at my stage - THIS site has provided the most appropriate assistance for an absolute beginner.

Thanks Redscouse I will work my way thought the referrals but a cursory look is that it is still to advance for what I am looking for.

Regards

.

I have been making my own websites(as a hobby) for more then 15 years. But I still feel I am a novice. I have followed the website Nettuts which has a tremendous amount of tutorials on it for php, css3, HTML5, Jquery and everything else.

However I now find everything they are teaching now is way above my head. So yes technology moves on.

I just strongly advise you use Xampp and do not put this code on the net.

PHPMYADMIN is very easy to work with. Create a database, then a table with your fields and do it on your computer, not the net. Search the internet for php and mysq(PDO)l tutorials. Read everyone you can find because nothing makes sense till you see someone else do it.

PHP

PDO

I have an ebook called Getting good with PHP I can email you too

Thank you for your guidance and I would welcome a look at your book if that is okay

I will try the reference you have provided and see how I go

Thanks for your patience

I can certainly recommend Larry Ullman’s books as I own a few myself, certainly helped me when i moved into sql.

Mr Wilson said below ‘nothing makes sense till you see someone else do it.’ - that is often very true!
Sometimes I can explain till i’m blue in the face - or i can just show an example and the learner will go ‘oh yeah’ i get it now… so with that said, when you get stumped with something, come back here post your question(s) and i’m sure someone will help you make sense of it.

Red :wink:

Thanks Red

I agree with you 100% I have tried to find someone in my small community that knows how to use PHP and MYSQL but have been unable to find anybody that is interested in mentoring me, who I think knows what they are talking about.

I will read your reference but you really have hit the nail on the head. I have read so much material so far but when something goes wrong and I have no idea what it is, it is very difficult to resolve the issue.

I have now installed XAMPP on my computer but I’m getting an error message that the installation is not correct and I’m currently in the process of trying to resolve that issue.

But thank you very much for your kind support and interest and I have already bookmark this site for reference in future as my coding skills progress but I step outside my knowledge zone.

Regards

Waz.

I am not sure but I think there are forums at the Xampp site you could post to

Thanks

Have just posted a request for support

Waz

Sponsor our Newsletter | Privacy Policy | Terms of Service