Posted: Sun Feb 24, 2008 6:26 pm Post subject: MySQL not recieving data from seemingly functional php...
Hello all,
I am new to mySQL, php etc as of the last few weeks and this is my first post (probably of many )...
All my files are running through the WAMP stack, which includs Apache, myQL, Php and phpMyAdmin. I have also got PEAR up and running, and throughout installing everything I have modified the inlude_paths in the ini files to make sure everything works swimmingly. And everything was fine, until yesturday. I have several test foms which were functioning perfectly, and now, although seemingly executing in the browser with no errors, do not alter anything in the MySQL datbase.
I have tried checking the php.ini file, but everything that was there was there two days ago. I have tried substituting include('db_login.php') for a full expression of the variables, but that didn't chnage anything.
One thing which is odd is that when I alter an existing file in notepad, now the changes are not aparant in the browser. For example, to test this theory I changed the type of one simple from "text" to "blahblahblah", but when I called the page in the browser there were no errors and the text field was still there.
Anyone who thinks they can help, I would greatly appreciate it.
Joined: 02 May 2004 Posts: 5574 Location: toronto, canada
Posted: Sun Feb 24, 2008 9:02 pm Post subject:
Just as a guess, I thnk that you are modifying the files that are not in the web root. So the webserver never sees those changes. Make sure that the caching for the browser is set to always look for new files as well to ensure that you are not getting a cached file. _________________ Lostboy
Hey Lost boy...thanks very much for your help. Unfortunately I'm still haven't trouble.
Before I read your reply, I ended up reinstalling the WAMP stack because my lecturer suggested it. Sure enough, the forms worked, at least for about 5 or 6 pieces of data. Now they're not display any other received information. The code seemed to work the first 5 times, in both browsers, but now the table isn't updating. I have disabled the cache memory, as well the internal cache memory through about:config method, but nothing.
Any other ideas? I've been checking tutorials, but because the browser isn't displaying an error, it seems like a bit of an enigma...
Joined: 02 May 2004 Posts: 5574 Location: toronto, canada
Posted: Tue Feb 26, 2008 4:17 am Post subject:
kitty,
Is error reporting turned on? In some installations its turned off by default and the code won't show errors at all. Also have you any error reporting in the mysql call?
Code:
// turn error reporting on in your script
error_reporting(E_ALL);
// add mysql error handling
$result = mysql_query($sql, $conn) or die("Error in query<br>". mysql_error());
I've got error handling running and now the page is telling me that the query has failed. It displays -
Notice: Undefined index gmood in c:/wamp/www/Opus/guiitar.php on Line 49.
Query gone wrong!
I have checked the mysql table but the keys are correctly named. I've also checked the php code, but the name definitions are all correct. What even stranger is I still haven't altered the code that was functioning a few days ago. Now it's informing me of error in parts of the script which had previously sent data to the mysql table. Bizarre.
Any ideas? Thankyou so much for your help...I hope this isn't a lost cause. If you want me to print my code just say the word.
Joined: 02 May 2004 Posts: 5574 Location: toronto, canada
Posted: Wed Feb 27, 2008 7:14 pm Post subject:
Kitty,
I re-organized your code somewhat to make it easier to read...I also added a mysql_error() call into the db piece to see why its objecting to your code
if(!$connection){
die ("Can't connect to database: <br />".DB::errorMessage());
}
// control code for the page
// i really prefer to code in function as it keeps all the bits cleanly separated and easier to read
// here is some control code that will alter the flow of the page depeding on what happens
if (!isset($_POST['submit'])){
showForm();
} else {
processForm();
}
// below are the separate pieces set into functions, keeping all the related stuff together, then if you want to expand
// the functionality, write another function, and then code the function call into the correct place
Rhythm: <br />
Straight <input type="radio" name="grhythm" value="gstraight"><br>
Slightly swung <input type="radio" name="grhythm" value="gsswung"><br>
Heavily swung <input type="radio" name="grhythm" value="ghswung"><br>
Accent the 1st and 3rd beat of the bar <input type="radio" name="grhythm" value="g13"><br>
Accent the 2nd and 4th beat of the bar <input type="radio" name="grhythm" value="g24"><br>
No strict rhythm <input type="radio" name="grhythm" value="gnostrict"><br>
Key: <br />
Stay in current key <input type="radio" name="gkey" value="gcurrent"><br>
Move to relative major (the dominant)<input type="radio" name="gkey" value="gmajor"><br>
Move to relative minor <input type="radio" name="gkey" value="gminor"><br>
Move to mediant key (a third above the current key)<input type="radio" name="gkey" value="gmediant"><br>
Play chromatically/without key <input type="radio" name="gkey" value="gnokey"><br>
<input type="submit" name="submit" value="Submit!">
</form>';
}//end function showForm
function processForm()
{
// test for the existance of the POSTed value (if its not filled in on the form, you may not have data )
// here I used the ternary operator (a fancy if the statement) to see if there is data and give it an empty string if no
// data, NULL may be more appropriate for your application
// ternary check is ( if condition )? is true : is false
$gvolume = (!empty($_POST['gvolume'])) ? $_POST['gvolume'] : "";
$gmood = (!empty($_POST['gmood'])) ? $_POST['gmood'] : "";
$grhythm = (!empty($_POST['grhythm'])) ? $_POST['grhythm'] : "";
$gkey = (!empty($_POST['gkey'])) ? $_POST['gkey'] : "";
// I added the mysql_error() function call here to tell you why the db is objecting to the sql you've passed
$status = mysql_query($query) or die ("Query has failed: ". mysql_error());
if($status){
echo "Query was sucessful";
}else{
echo "Query failed";
} // end if status reporting
Query has failed: Duplicate entry 'gmoderate' for key 1.
I'm guessing this means that MySQl sin't accepting duplicate entries into the fields. Is this normal? Surely not, seeing as many users may choose the same radio button, sending the same char string. Do you know of a way to combat this?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum