PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



MySQL not recieving data from seemingly functional php...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General
View previous topic :: View next topic  
Author Message
kitty



Joined: 24 Feb 2008
Posts: 6
Location: London

PostPosted: Sun Feb 24, 2008 6:26 pm    Post subject: MySQL not recieving data from seemingly functional php... Reply with quote

Hello all,

I am new to mySQL, php etc as of the last few weeks and this is my first post (probably of many Smile)...

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.

Cheers,
Kit
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5574
Location: toronto, canada

PostPosted: Sun Feb 24, 2008 9:02 pm    Post subject: Reply with quote

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

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
kitty



Joined: 24 Feb 2008
Posts: 6
Location: London

PostPosted: Mon Feb 25, 2008 7:22 pm    Post subject: Reply with quote

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...

Ta,

Kitty
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5574
Location: toronto, canada

PostPosted: Tue Feb 26, 2008 4:17 am    Post subject: Reply with quote

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());

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
kitty



Joined: 24 Feb 2008
Posts: 6
Location: London

PostPosted: Wed Feb 27, 2008 5:34 pm    Post subject: Reply with quote

Hello again,

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.

Kitty.
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5574
Location: toronto, canada

PostPosted: Wed Feb 27, 2008 5:40 pm    Post subject: Reply with quote

Please show the code...the warning you got is related to you not defining a variable before attempting to use it...
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
kitty



Joined: 24 Feb 2008
Posts: 6
Location: London

PostPosted: Wed Feb 27, 2008 5:56 pm    Post subject: Reply with quote

Here's my code....it's pretty simple...

Code:

<?php
error_reporting(E_ALL);
$db_username = "kate";
$db_password = "buttercup";
$db_host = "localhost";
$db_database = "test";
require_once( 'DB.php' );
$connection = DB::connect( "mysql://$db_username:$db_password@$db_host/$db_database");
if(!$connection){
die ("Can't connect to database: <br />".DB::errorMessage());
};
?>
<html>
<head>
      <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
      <title>Radio Button Test</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])){
?>
<form action="" method="post">
Volume:<br />
Very Loud<input type="radio" name="gvolume" value="gveryloud"><br>
Moderate<input type="radio" name="gvolume" value="gmoderate"><br>
Quiet<input type="radio" name="gvolume" value="gquiet"><br>
Silent<input type="radio" name="gvolume" value="gsilent"><br>
Mood: <br />
Agressive<input type="radio" name="gmood" value="gagressive"><br>
Calm/Placid<input type="radio" name="gmood" value="gcalm"><br>
Cheerful<input type="radio" name="gmood" value="gcheerful"><br>
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>
<?php
} else {
$gvolume = $_POST['gvolume'];
$gmood = $_POST['gmood'];
$grhythm = $_POST['grhythm'];
$gkey = $_POST['gkey'];
$query = "INSERT INTO `dirguitar` (gvolume, gmood, grhythm, gkey) VALUES ('$gvolume','$gmood','$grhythm','$gkey')";
$status = mysql_query($query) or die ("Query has failed");
if($status){
echo "Query was sucessful";
}else{
echo "Query failed";
}
};
?>
</body>
</html>


And here's a screen shot of the mysql database...



Kitty
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5574
Location: toronto, canada

PostPosted: Wed Feb 27, 2008 7:14 pm    Post subject: Reply with quote

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

Code:

<html>
  <head>
   <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
   <title>Radio Button Test</title>
  </head>
<body>
   
<?php
  error_reporting(E_ALL);
  $db_username = "kate";
  $db_password = "buttercup";
  $db_host     = "localhost";
  $db_database = "test";
  require_once( 'DB.php' );
  $connection = DB::connect( "mysql://$db_username:$db_password@$db_host/$db_database");
 
  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

function showForm()
{
 
echo '
   <form action="" method="post">
   
   Volume:<br />
   Very Loud<input type="radio" name="gvolume" value="gveryloud"><br>
   Moderate <input type="radio" name="gvolume" value="gmoderate"><br>
   Quiet    <input type="radio" name="gvolume" value="gquiet"><br>
   Silent   <input type="radio" name="gvolume" value="gsilent"><br>
   
   Mood: <br />
   Agressive   <input type="radio" name="gmood" value="gagressive"><br>
   Calm/Placid <input type="radio" name="gmood" value="gcalm"><br>
   Cheerful    <input type="radio" name="gmood" value="gcheerful"><br>
   
   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']     : "";
   
   
   $query   = "INSERT INTO `dirguitar` (gvolume, gmood, grhythm, gkey) VALUES ('$gvolume','$gmood','$grhythm','$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
   
}// end function processForm
?>
</body>
</html>

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
kitty



Joined: 24 Feb 2008
Posts: 6
Location: London

PostPosted: Wed Feb 27, 2008 7:42 pm    Post subject: Reply with quote

Thankyou so much Lostboy -

The code shows this error:

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?

Cannot thank you enough for being so helpful Smile

Kit
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5574
Location: toronto, canada

PostPosted: Wed Feb 27, 2008 8:17 pm    Post subject: Reply with quote

try adding in a primary key autonumber to the table

you may also want to look at using phpmyadmin to administer the database...makes life easier
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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






Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum