Ah form processing doing my head in!

This is a discussion on "Ah form processing doing my head in!" within the PHP Forum section. This forum, and the thread "Ah form processing doing my head in! are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 17th, 2007, 19:16
1840dsgn's Avatar
SuperMember

SuperMember
Join Date: Jun 2007
Location: Canterbury
Age: 19
Posts: 720
Thanks: 0
Thanked 0 Times in 0 Posts
Ah form processing doing my head in!

Hi all. I know theres some pretty good php'ers round here and afetr spending the best part of three hours getting more and more frustrated I thought maybe you could take a peek at my code for me and try and find what i've done wrong!

My table...

Field Type Collation Attributes Null Default Extra

ID int(6)
UNSIGNED No
auto_increment
client varchar(200) latin1_swedish_ci
Yes NULL

type varchar(200) latin1_swedish_ci
Yes NULL

imgpath varchar(200) latin1_swedish_ci
Yes NULL


imgalt varchar(200) latin1_swedish_ci
Yes NULL


worklink varchar(200) latin1_swedish_ci
Yes NULL

section varchar(60) latin1_swedish_ci
Yes NULL

description text latin1_swedish_ci
Yes NULL


and the code is....(sorry its long)

PHP: Select all

<?php

require_once('1840includes/Sentry.php');
$theSentry = new Sentry();
if (!
$theSentry->checkLogin(2) ){ header("Location: login.php"); die(); }

// Get the PHP file containing the DbConnector class
require_once('1840includes/DbConnector.php');
require_once(
'1840includes/Validator.php');

// Create an instance of DbConnector
$connector = new DbConnector();

// Check whether a form has been submitted. If so, carry on
if ($_POST){

// Validate the entries
$validator = new Validator();

$validator->validateGeneral($_POST['client'],'Client');
$validator->validateGeneral($_POST['type'],'Type');
$validator->validateGeneral($_POST['imgpath'],'Image Path');
$validator->validateGeneral($_POST['imgalt'],'Image Alt Text');
$validator->validateGeneral($_POST['worklink'],'Link');
$validator->validateGeneral($_POST['description'],'Description');
        
// Check whether the validator found any problems
if ( $validator->foundErrors() ){
    echo 
'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each
}else{

// Create an SQL query (MySQL version)
// The 'addslashes' command is used 5 lines below for added security
// Remember to use 'stripslashes' later to remove them (they are inserted in front of any
// special characters
        
        
$client$_POST['client'];
        
$type$_POST['type'];
        
$imgpath$_POST['imgpath'];
        
$imgalt$_POST['imgalt'];
        
$link$_POST['worklink'];
        
$section$_POST['section'];
        
$descr$_POST['description'];

$insertQuery = ("INSERT into cmsportfolio (client, type, imgpath, imgalt, worklink, section, description) VALUES('$client ','$type','$imgpath','$imgalt','$link','$section','$descr')";

    
// Save the form data into the database 
    
if ($result $connector->query($insertQuery)){

        
// It worked, give confirmation
        
echo '<div id="message">Work added to the portfolio<div><br/>';
        
    }else{

        
// It hasn't worked so stop. Better error handling code would be good here!
        
exit('<div id="warning">Sorry, there was an error saving to the database<div><br/>');

    }
}
}
?>

<body>
<form name="form1" method="post" action="newPortfolio.php">
                    <input type=hidden name="id" value="<?php echo $ID ?>">

        <p><label for="client">Client Name</label>
          <input name="client" type="text" id="client" size="50" value="<?php echo $client ?>">
        </p>
        <p><label for="type">Type of Work</label>
          <input name="type" type="text" id="type" size="50" value="<?php echo $type ?>">
        </p>
        <p>
          <label for="imgpath">Image name.ext </label>
        <input name="imgpath" type="text" id="imgpath" size="50" value="<?php echo $imgpath ?>">
        </p>
        <p><label for="imgalt">Img Description</label>
        <input name="imgalt" type="text" id="imgalt" size="50" value="<?php echo $imgalt ?>">
        </p>
        <p><label for="worklink">Link Path</label>
        <input name="worklink" type="text" id="worklink" size="50" value="<?php echo $worklink ?>">
        </p>
        <p class="tooltip"> Lightbox: (uploaded_images/image-1.jpg&quot; rel=&quot;lightbox&quot; title=&quot;my caption)<br />
        </p>
        <p><label for="section">Section</label>
        <select name="section" id="section"  value="<?php echo $section ?>">
        
        
    
        <?PHP     
        
// Create an instance of DbConnector
$connector = new DbConnector();
// Validate the entries
$validator = new Validator();

        
        
// Generate a drop-down list of sections.
                // NOTE : Requires database modifications in article 4

                
$result $connector->query('SELECT ID,name,link_name FROM portfoliosections ORDER BY name');

                
// Get an array containing the results.
                // Loop for each item in that array
                
while ($row $connector->fetchArray($result)){
                    echo 
'<option value="'.$row['link_name'].'">'.$row['link_name'].'</option>';
                }
          
?>
        </select>
</p>
        <p><label for="description">Description</label>
          <textarea name="description" cols="50" rows="3" id="description"> <?php echo $description ?></textarea>
        </p>
        <p class="submit">
          <input type="submit" name="Submit" value="Submit">
        </p>
</form>
if anyone can help me out...very very much appreciated...

its wierd because updating an existing entry works...but new entry doesn't.

It worked untill I changed the combo box on the form because i was rewriting the urls and rather than the id I wanted to use link_name in the table.

Thanks

Mike
Reply With Quote

  #2 (permalink)  
Old Jul 17th, 2007, 21:24
Junior Member
Join Date: Mar 2007
Location: California
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

Not sure if i am correct here or not just yet, I am at work and dont have to much time to dive into it. But a couple questions, Do you get an error message? if so what is the error (check logs as well). But, I think the problem lies in line 48: if ($result = $connector->query($insertQuery)) i'll look more into it when i get home. but i suspect break that down into steps and lets see if we cant solve this. I'll be back after work
Reply With Quote
  #3 (permalink)  
Old Jul 17th, 2007, 22:35
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

Does this code function just as the inserter, or do you use it to update too?

PHP: Select all

$insertQuery = ("INSERT into cmsportfolio (client, type, imgpath, imgalt, worklink, section, description) VALUES('$client ','$type','$imgpath','$imgalt','$link','$section','$descr')"
EDIT: IGNORE THIS
Should be:
PHP: Select all

$insertQuery = ("INSERT into cmsportfolio (client, type, imgpath, imgalt, worklink, section, description) VALUES('$client ','$type','$imgpath','$imgalt','$link','$section','$descr'"); 

END IGNORE

Should be:
PHP: Select all

$insertQuery "INSERT into cmsportfolio (client, type, imgpath, imgalt, worklink, section, description) VALUES('$client ','$type','$imgpath','$imgalt','$link','$section','$descr')"
You added brackets, and didn't add a trailing ")"
Not exactly sure of your problem though.
Do you get any error messages?

Last edited by balaclave; Jul 17th, 2007 at 23:09.
Reply With Quote
  #4 (permalink)  
Old Jul 17th, 2007, 22:43
1840dsgn's Avatar
SuperMember

SuperMember
Join Date: Jun 2007
Location: Canterbury
Age: 19
Posts: 720
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

Hi,

I use a different script to update it balaclave. i use the UPDATE SET query. i think!

Anyway, I don't know what was wrong, but afetr posting I kept at it, swapping this and that around and I have got it working.

I will try and take a look at it next time I get a chance and work out what I did and post the solution for others future reference.

Thanks for the help though!

Mike
Reply With Quote
  #5 (permalink)  
Old Jul 17th, 2007, 22:58
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

Quote:
I use a different script to update it balaclave. i use the UPDATE SET query. i think!
I thought you might.
I don't think that SQL query was valid.
Are you sure that isn't what you changed?

Last edited by balaclave; Jul 17th, 2007 at 23:09.
Reply With Quote
  #6 (permalink)  
Old Jul 17th, 2007, 23:03
1840dsgn's Avatar
SuperMember

SuperMember
Join Date: Jun 2007
Location: Canterbury
Age: 19
Posts: 720
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

Yea it was something in and around that area.Tell you what I'll post up the now working code....

Right I added this into the code

PHP: Select all

$up_section$_POST['section']; 

and changed the query to this...

PHP: Select all

$insertQuery "INSERT INTO cmsportfolio (client, type, imgpath, imgalt, worklink, section, description) VALUES (".
"'".$_POST['client']."', ".
"'".$_POST['type']."', ".
"'".$_POST['imgpath']."', ".
"'".$_POST['imgalt']."', ".
"'".$_POST['worklink']."', '$up_section', ".
"'".addslashes($_POST['description'])."')";

    
// Save the form data into the database 
    
if ($result $connector->query($insertQuery)){

        
// It worked, give confirmation
        
echo '<div id="message">Work added to the portfolio<div><br/>';
        
    }else{

        
// It hasn't worked so stop. Better error handling code would be good here!
        
exit('<div id="warning">Sorry, there was an error saving to the database<div><br/>');

    }
}
}
?> 
So if you can summarise what i've changed to make it work that might help others...pobviously I would...but I can't! As you can probably guess I'm still failry new to this php stuff! but I'm learning!

Mike
Reply With Quote
  #7 (permalink)  
Old Jul 17th, 2007, 23:13
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

OOoops.
I got it wrong.
I've edited my above posts.

You started with the query in brackets, but didn't close them at the end.

In the second example, you didn't attempt to wrap the query in brackets.
So either, you can't wrap queries in brackets, or you must close them as usual.

I.e.
Your original was like:
PHP: Select all

$query = ("SELECT * from blah";
// no closing bracket 
Your second, working query was:
PHP: Select all

$query "SELECT * from blah"
Reply With Quote
  #8 (permalink)  
Old Jul 17th, 2007, 23:14
1840dsgn's Avatar
SuperMember

SuperMember
Join Date: Jun 2007
Location: Canterbury
Age: 19
Posts: 720
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Ah form processing doing my head in!

ah I see.

Ah well its all done now!!! Woohoo!

Cheers balaclave!

Mike
Reply With Quote
Reply

Tags
combo box, php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing application and agreement form beerboi PHP Forum 1 Jun 26th, 2006 14:36
problems with form processing tooie Classic ASP 3 Apr 26th, 2006 17:34
Processing Form ASP using GET method to Email rbrown1972 Classic ASP 2 Feb 25th, 2005 05:23
Form processing javabean kinjiro PHP Forum 0 Aug 9th, 2004 14:18
Template Processing vor Classic ASP 3 Sep 10th, 2003 00:01


All times are GMT. The time now is 20:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43