Jump to content

[SOLVED] PHP MySQL help!


chewwie

Recommended Posts

Hi guys,

 

I'm kind of new to PHP/MySQL and I have had a google to try and find an answer to my question but so far I have had no luck so I thought I would ask someone.

 

I think my problem is fairly easy to solve its just I cant figure out how to do it! :S

 

Basically I want to submit form data to a new record in a my SQL database. I had it working that on submit it would run a validation script (JavaScript) then if that returned true it would save data to database and replace the form with a confirmation message. That all worked fine.

 

The problem is I actually need to send user to a different page, rather than just echo a confirmation message, as I am parsing some data (unique project code) using a query string to this other page. I don't know how to save data before redirecting! Currently the form validates and the page changes but the data isn't being saved!

 

PHP Script:

 <?php
                if (!isset($_POST['submit'])) {
            ?>

            <!-- start content -->
            <div id="content">
                <div class="post">
                    <h1 class="title">/ Create New Project</h1>
                    
                    <form id="createForm" action="" onsubmit="return validateForm()" method="post">   			
                            <input blah blah />
                    </form>   	

                </div>
            </div>
            <!-- end content -->
            
               
            <?php
				} else {

					$title = $_POST['project_title'];
					$country = $_POST['country'];
					$city = $_POST['city'];
					$project = $_POST['description_txt'];
					$artist = $_POST['artist_name'];
					$artistage = $_POST['artist_age'];
					$artisturl = $_POST['artist_url'];
					$user = $_POST['user_txt'];


					$query = "INSERT INTO news VALUES ('','$code','$title','$country','$city','$project','$artist','$artistage','$artisturl','$user')";
					mysql_query($query);
					}              
				mysql_close();
            ?>		
           

 

Validation:

 }else{
        //A-OK
        document.getElementById('createForm').action = "viewNew.php?projectCode="+201;
        return true;
    }

 

Any suggestions would be greatly appreciated. Thanks

 

Chewwie

Link to comment
Share on other sites

Sorry guys I was being a complete muppet with my first post! Got it all working now tho. Must have been at that tired stage last night which stopped the brain functioning!

 

Thanks for your suggestion tho bobinindia! I didn't need to try it in the end but i'm sure it would have also worked!

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.