Help with my code

Could someone assist me to sort this out?

ERROR: Parse error: syntax error, unexpected $end in D:\Hosting\7995904\html\view.php on line 46

//view.php IS MY DB SEARCH FORM

My Code:

<?php include ([color=orange]transmit.php[/color]); [color=brown] // transmit.php IS MY PHP COMMUNICATE WITH DB FILE [color=orange]client [/color] [/color] if ($result = $mysqli->query("select * from [color=orange]client [/color]order by id"));// { if($results->num_rows>0) { echo ""; echo ""; while ($row = $result->fetch_object()) { echo ""; echo ""; echo ""; echo ""; } echo "
ID First Name Family Name
" . $row->id ."" . $row->first ."" . $row->family ."
"; } else { echo "Error" . $mysqli->error; } $mysqli->close(); [b][color=red][LINE 46 HERE- BLANK NO CODE][/color][/b] ?>

back

Many Thanks in Advance

You are missing one
[php]echo “”;[/php]

The error you are getting means more then likely you have a missing or an extra }

Your problem is on this line

[php]if ($result = $mysqli->query(“select * from client order by id”));//[/php]

The ; is outside the )). That ends the script and the If statement.

Thanks that fixed the error message but I have more problems it would seem

New error

Warning: include(transmitphp) [function.include]: failed to open stream: No such file or directory in D:\Hosting\7995904\html\view.php on line 14

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

Fatal error: Call to a member function query() on a non-object in D:\Hosting\7995904\html\view.php on line 16

I may be in over my Head

Your include include (transmit.php);

Should be [php]include(“transmit.php”);[/php]

I always use double quotes when including or linking

Oz we all start somewheres. There are tons of videos to learn php on Youtube, just search for php

Here is a video tutorial set that I found helpful. There are 11 videos

Don’t be put off my friend, Whilst this looks like a whole load of new errors, it’s actually all related to one.
Because you never used quotes in your include call (and you can use double or single) the transmit page wasn’t included. Hence the first two warnings.
The Fatal error was thrown because A) the transmit file wasn’t included so B) there is no $mysqli so in effect you are calling a function that does not exists - hence the fatal error.

Add the quotes to your include call and all should be well again.
include (‘transmit.php’);

Hope that helps,
Red :wink:

Thanks again to every one and the referral.

Now I do not get any errors - just a blank screen. (it does not display the data contents in the web browser)

obviously have mistakes elsewhere will look at videos and would like to comeback if I cannot find the solution my self

Again thanks - a really nice community

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:

Sponsor our Newsletter | Privacy Policy | Terms of Service