Web Design Forum: php problem - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

php problem Rate Topic: -----

#1 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 09 August 2009 - 06:05 PM

Hello everyone, i'm writing a e-commerce site, with the help of a php book my Larry Ullman, and i've run into a bit of trouble, i'm not following the code to the character as this site is a different base then the artist print one he does.

I'm getting this error here

This is the code from line 71 to 93
if (!empty($_POST['catagory']) && ($_POST['catagory'] == 'new')) {
			   //add entry to database
			   $q = 'INSERT INTO catagory (cat_name, cat_desc) VALUES ($cat_name, $cat_desc)';
			   $stmt = mysqli_prepare($dbc, $q);
			   mysqli_stmt_bind_param($stmt, 'sss',$cat_name,$cat_desc);
			   mysqli_stmt_execute($stmt);
			   
			   //check result
					if (mysqli_stmt_affected_rows($stmt) == 1){
						$thankyou[] ='Catagry added to the database';
						$a = mysqli_stmt_insert_id($stmt);//get catagory id
            		} else {
						$errors[] = 'The new catagory could not be added to the database';
					}
				//close prepared statment
    	              mysqli_stmt_close($stmt);
			}else{
              	$errors[] = 'Please enter the catagory name and description';  	
			}elseif(isset($_POST['catagory']) && ($_POST['catagory'] == 'existing') && ($_POST['existing'] > 0)){
				$a = (int) $_POST['existing'];
			} else {
				$errors[] = 'Please enter or select a catagory.';
			}


I know it's something around the elseif statement, but i just cant figure out what, and i've double checked all the { and } and they seem ok, Any help?

Many Thanks, Ben
0

#2 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 09 August 2009 - 06:19 PM

You can't have an else section preceding an elseif section.
0

#3 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 09 August 2009 - 06:24 PM

View PostThomas Thomassen, on 09 August 2009 - 06:19 PM, said:

You can't have an else section preceding an elseif section.

I didn't think you could, i got a feeling, i've gone off track with this as well, because it has an else if after and else statement, but i got a feeling that the elseif is part of the previous if. time to do some testing,

Thanks for confirming it Thomas
0

#4 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 09 August 2009 - 11:03 PM

So im not wasting more threads, ill add to this one..


Got another php error
"Fatal error: Only variables can be passed by reference in public_html/gorsehill/public_html/user1/index.php on line 75"
//add entry to database
			   $q = 'INSERT INTO catagory (cat_name, cat_desc) VALUES ($cat_name, $cat_desc)';
			   $stmt = mysqli_prepare($dbc, $q);
	            Line75>mysqli_stmt_bind_param($dbc,$stmt, 'sss',$cat_name,$cat_desc);
			   mysqli_stmt_execute($dbc,$stmt);


May someone enlighten me as to what the error is thank you :) I'm having a mess around with it, but i got a feeling them $dbc don't have to be there, my database connection details...

Can someone correct me, done the same as in the book and doesn't work.. Many Thanks.
0

#5 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 10 August 2009 - 06:15 AM

hm..
What PHP version do you use? 4 or 5?
0

#6 User is offline   zoonder 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 169
  • Joined: 31-March 09
  • Reputation: 1
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 10 August 2009 - 10:44 AM

It looks like you're pasing the "database connection" ($dbc) instead of the statement ($stmt) that you prepared earlier in the code.

Check out the procedural example in the PHP Manual.
0

#7 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 10 August 2009 - 11:46 AM

View PostThomas Thomassen, on 10 August 2009 - 06:15 AM, said:

hm..
What PHP version do you use? 4 or 5?

I've emailed my host to see what version I'm running but the book is using PHP 6, just waiting on a reply from my host.

View Postzoonder, on 10 August 2009 - 10:44 AM, said:

It looks like you're pasing the "database connection" ($dbc) instead of the statement ($stmt) that you prepared earlier in the code.

Check out the procedural example in the PHP Manual.

Having a read through it now, hopefully i can fix it.
0

#8 User is offline   zoonder 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 169
  • Joined: 31-March 09
  • Reputation: 1
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 10 August 2009 - 12:13 PM

Good luck. To find out PHP version do the following.

1. Create a new file and call it info.php (or whatever you like.)
2. Type the following code:

<?php 
            phpinfo(); 
      ?>


3. Save the file on your server.

4. Request the file from a browser. eg. http://www.example.com/info.php

The phpinfo() function will show your version number and a few other interesting things.

Remove the file when you're done.
0

#9 User is offline   zoonder 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 169
  • Joined: 31-March 09
  • Reputation: 1
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 10 August 2009 - 12:21 PM

You can also use the phpversion() function for a more concise output :)

You'll need to echo it out:

echo phpversion();
0

#10 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 10 August 2009 - 12:22 PM

View Postzoonder, on 10 August 2009 - 12:21 PM, said:

You can also use the phpversion() function for a more concise output :)

Ahh that save time thank you mate, ill get back to you all in a moment
0

#11 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 10 August 2009 - 12:30 PM

I'm running PHP Version 5.2.6
0

#12 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 10 August 2009 - 03:11 PM

You got a book on PHP6?

...don't think that's the best book to learn PHP by. PHP it still in active development. Going to be a while until it's complete. Lots of things are changing from PHP5/4 to PHP6.
0

#13 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 10 August 2009 - 03:27 PM

View PostThomas Thomassen, on 10 August 2009 - 03:11 PM, said:

You got a book on PHP6?

...don't think that's the best book to learn PHP by. PHP it still in active development. Going to be a while until it's complete. Lots of things are changing from PHP5/4 to PHP6.

It was the only php book waterstones had in when i went itn, But all the other scripts have worked fine, guess i will just have to do it a different way.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users