[jQuery] newbie jquery.load help wanted!
HI. I'm really new to jquery, and PHP for that matter. I'm trying to complete a school assignment, and I'm s stuck. What I'm trying to do is submit form data through jquery to a php page. The php works as intended when called outside of jquery. It basically takes some POST values, and writes them to a database. It's then supposed to return a string which lets a user know the result of the attempt. All I want to do is load the resulting string into a div on my form page. However, in the way I'm calling it from Jquery, I'm doing something wrong, since all I'm getting back in my alert message is a huge pop up with the entire contents of the PHP page. It's never actually processing. Here's my jquery call (the one letter variables are derived from my validation script. These also hold the correct values): *** $.post(bin/uploadstory.php, {heading: h, story: s, urllink: u, image: p, category: c}, function(data){ alert(Data Loaded: + data); }); *** and here's my php page, bin/uploadstory.php (this is the full code on this page). *** ?php include(dbconnect.php); //db connection script include(dbstories.php); // script which writes story to database, using a writestory() function //this is my call to the code below, which returns a number between 0-2, depending on result echo(getResult()); function getResult(){ $msg = ; if(connectDB()){ $user = $_SESSION('userid'); $heading = $_POST('heading'); $story = $_POST('story'); $urllink = $_POST('urllink'); $image = $_POST('photo'); $category = $_POST('category'); //calls external script. writes form data to DB. works perfectly $result = writeStory($user, $heading, $story, $urllink, $image, $category); if($result==0) $msg =couldn't create record; else if($result==1) $msg =record created, couldn't add category; else if ($result==2) $msg = article added successfully; else $msg = unknown error occured. please try again.; return $msg; } else $msg = Couldn't connect to the database. Please try again later.; return $msg; }
[jQuery] beginner help jquery.load
HI. I'm really new to jquery, and PHP for that matter. I'm trying to complete a school assignment, and I'm s stuck. What I'm trying to do is submit form data through jquery to a php page. The php works as intended when called outside of jquery. It basically takes some POST values, and writes them to a database. It's then supposed to return a string which lets a user know the result of the attempt. All I want to do is load the resulting string into a div on my form page. However, in the way I'm calling it from Jquery, I'm doing something wrong, since all I'm getting back in my alert message is a huge pop up with the entire contents of the PHP page. It's never actually processing. Here's my jquery call (the one letter variables are derived from my validation script. These also hold the correct values): *** $.post(bin/uploadstory.php, {heading: h, story: s, urllink: u, image: p, category: c}, function(data){ alert(Data Loaded: + data); }); *** and here's my php page, bin/uploadstory.php (this is the full code on this page). *** ?php include(dbconnect.php); //db connection script include(dbstories.php); // script which writes story to database, using a writestory() function echo(getResult()); function getResult(){ $msg = ; if(connectDB()){ $user = $_SESSION('userid'); $heading = $_POST('heading'); $story = $_POST('story'); $urllink = $_POST('urllink'); $image = $_POST('photo'); $category = $_POST('category'); $result = writeStory($user, $heading, $story, $urllink, $image, $category); if($result==0) $msg =couldn't create record; else if($result==1) $msg =record created, couldn't add category; else if ($result==2) $msg = article added successfully; else $msg = unknown error occured. please try again.; return $msg; } else $msg = Couldn't connect to the database. Please try again later.; return $msg; } * Can anyone help me out? I've been stuck on this little part for 3 days, and i know it's something stupid, but i can't figure out what.
[jQuery] beginner help jquery.load
HI. I'm really new to jquery, and PHP for that matter. I'm trying to complete a school assignment, and I'm s stuck. What I'm trying to do is submit form data through jquery to a php page. The php works as intended when called outside of jquery. It basically takes some POST values, and writes them to a database. It's then supposed to return a string which lets a user know the result of the attempt. All I want to do is load the resulting string into a div on my form page. However, in the way I'm calling it from Jquery, I'm doing something wrong, since all I'm getting back in my alert message is a huge pop up with the entire contents of the PHP page. It's never actually processing. Here's my jquery call (the one letter variables are derived from my validation script. These also hold the correct values): *** $.post(bin/uploadstory.php, {heading: h, story: s, urllink: u, image: p, category: c}, function(data){ alert(Data Loaded: + data); }); *** and here's my php page, bin/uploadstory.php (this is the full code on this page). *** ?php include(dbconnect.php); //db connection script include(dbstories.php); // script which writes story to database, using a writestory() function echo(getResult()); function getResult(){ $msg = ; if(connectDB()){ $user = $_SESSION('userid'); $heading = $_POST('heading'); $story = $_POST('story'); $urllink = $_POST('urllink'); $image = $_POST('photo'); $category = $_POST('category'); $result = writeStory($user, $heading, $story, $urllink, $image, $category); if($result==0) $msg =couldn't create record; else if($result==1) $msg =record created, couldn't add category; else if ($result==2) $msg = article added successfully; else $msg = unknown error occured. please try again.; return $msg; } else $msg = Couldn't connect to the database. Please try again later.; return $msg; } * Can anyone help me out? I've been stuck on this little part for 3 days, and i know it's something stupid, but i can't figure out what.