Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Database INSRT works but does not show up in PHP MyAdmin
Old 08-20-2009, 11:31 AM Database INSRT works but does not show up in PHP MyAdmin
Average Talker

Posts: 29
Trades: 0
Hi everyone,

Seems I've had a couple purplexing problems the past couple days. The latest one is on a form that posts information to the database. When run, the script does not present any errors; however, the result does not show up when I browse the table in PHP MyAdmin. Any ideas? The code is below:

PHP Code:
//  Check for form submission

if (isset($_POST['submit'])) {
    
    
// form was submitted, check required fields
    
if ($_POST['tbEmail'] == '' or $_POST['Need_Help_With'] == '' or isValidEmail($_POST['tbEmail']) == false) {
        
// Show error to user
        
$errtxt "Please make sure you have entered information in the required fields and that your email is valid.";
    }
    
    
// if no error, post submission to db
    
if ($errtxt == '') {
        
// include db connection
        
require_once 'resources/includes/dbconn.php';

        
// Build the query vars
        
$Email mysql_real_escape_string($_POST['tbEmail']);
        
$FirstName mysql_real_escape_string($_POST['tbFirstName']);
        
$LastName mysql_real_escape_string($_POST['tbLastName']);
        
$Address mysql_real_escape_string($_POST['tbAddress']);
        
$City mysql_real_escape_string($_POST['tbCity']);
        
$State mysql_real_escape_string($_POST['tbState']);
        
$Zip mysql_real_escape_string($_POST['tbZip']);
        
$Phone mysql_real_escape_string($_POST['tbPhone']);
        
$Seeking mysql_real_escape_string($_POST['rbSeekingFor']);
        
$OtherCity mysql_real_escape_string($_POST['Someone_Else_City']);
        
$WhatHelpWith mysql_real_escape_string($_POST['Need_Help_With']);
        
$ContactType mysql_real_escape_string($_POST['Contact_By']);
        
$howheard mysql_real_escape_string($_POST['Referral_From']);
        
$TheDate date("F j Y g:i a");  
        
$Updates mysql_real_escape_string($_POST['Electronic_Updates']);
        
$ip=$_SERVER['REMOTE_ADDR'];
        
        
// Change "on" to "yes" for the checkbox value
        
if ($Updates == 'on') { $Updates 'yes'; } else {$Updates 'no '; };
        
        
// Buidl the insert query string
        
$query "INSERT INTO info_requests (email, firstname, lastname, address, city, state, zip, phone, infofor, othercity, whathelpwith, contacttype, howheard, thedate, updates) VALUES ('$Email', '$FirstName', '$LastName', '$Address', '$City', '$State', '$Zip', '$Phone', '$Seeking', '$OtherCity', '$WhatHelpWith', '$ContactType', '$howheard', NOW(), '$Updates')";
        
        
// Insert the query into the db
        
        
$result mysql_query($query) or die('failed because '.mysql_error());
        if (!
$result) {
            
$errtxt "Could not successfully run query ($query) from DB: " mysql_error();
            exit;
        } else {
            
$errtxt "Thank you, your submission has been sent.";
        } 
__________________

Please login or register to view this content. Registration is FREE

Great Web Hosting just $9/mo. Includes free domain and renewals. Free 7 day trial.
bunchjesse is offline
Reply With Quote
View Public Profile Visit bunchjesse's homepage!
 
 
Register now for full access!
Old 08-20-2009, 12:04 PM Re: Database INSRT works but does not show up in PHP MyAdmin
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
No error isn't always the same as it's working, obviously
Are you sure the query is run at all? If you print the $errtxt message at the end, does it hold the "Thank you, your ..." message?

I'm asking because it doesn't seem your $errtxt variable is iniciated. So the variable doesn't exists when you check if it's set to '' (empty string). Right now I can't remeber how php reacts on this situation but you could try changing it.

Another idea, are you using transactions?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-20-2009, 12:53 PM Re: Database INSRT works but does not show up in PHP MyAdmin
Average Talker

Posts: 29
Trades: 0
Well what I forgot to mention is that when I run a select query in the same script and print out the rows returned, the written data shows up. But, in PHP MyAdmin, no dice. It doesn't even increment the row count. This is so weird.
__________________

Please login or register to view this content. Registration is FREE

Great Web Hosting just $9/mo. Includes free domain and renewals. Free 7 day trial.
bunchjesse is offline
Reply With Quote
View Public Profile Visit bunchjesse's homepage!
 
Old 08-20-2009, 12:55 PM Re: Database INSRT works but does not show up in PHP MyAdmin
Average Talker

Posts: 29
Trades: 0
Quote:
Originally Posted by lizciz View Post
Are you sure the query is run at all? If you print the $errtxt message at the end, does it hold the "Thank you, your ..." message?
Yes, I check for text inside the $errtxt variable and display it to the user. It serves two purposes: 1) To alert the user of submission errors and 2) Alert the user of a successful submission.
__________________

Please login or register to view this content. Registration is FREE

Great Web Hosting just $9/mo. Includes free domain and renewals. Free 7 day trial.
bunchjesse is offline
Reply With Quote
View Public Profile Visit bunchjesse's homepage!
 
Old 08-20-2009, 01:52 PM Re: Database INSRT works but does not show up in PHP MyAdmin
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
What if you manually make the changes in phpMyAdmin?
And again, are you using transactions? If you are you must commit any changes before they are made permanent, otherwise all changes will be "rewinded" when the script terminates.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-20-2009, 01:55 PM Re: Database INSRT works but does not show up in PHP MyAdmin
Average Talker

Posts: 29
Trades: 0
I can manually add a new row in PHP MyAdmin. And I am not implicitly using transactions. Now, i'm not that familiar with transactions. How could I tell if they are enabled? Maybe the client I'm working for has it enabled?
__________________

Please login or register to view this content. Registration is FREE

Great Web Hosting just $9/mo. Includes free domain and renewals. Free 7 day trial.
bunchjesse is offline
Reply With Quote
View Public Profile Visit bunchjesse's homepage!
 
Old 08-20-2009, 02:47 PM Re: Database INSRT works but does not show up in PHP MyAdmin
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Well im not that familiar with transactions myself. I've only used them once for quite some time. Although you have to run a command (some php function) to start the transaction yourself.

You can also check what storage engine your MySQL uses. The standard one is MyISAM I believe and with it you can't use transactions. So if that's the case then you don't need to worry about transactions.

Unfortunately though, I'm running short of ideas to your problem.

This may be a stupid question, but since you can select the inserted data in your script, are you sure you're looking at the correct database and table in phpMyAdmin?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366

Last edited by lizciz; 08-20-2009 at 02:52 PM..
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-20-2009, 07:10 PM Re: Database INSRT works but does not show up in PHP MyAdmin
Average Talker

Posts: 29
Trades: 0
Well I have ruled out transactions because the data table is of type MYISAM. Also, yes I am looking at the correct table in MyAdmin. However, I did find out that if I drop the table, the script still works. So I wonder why the error handling is not working?
__________________

Please login or register to view this content. Registration is FREE

Great Web Hosting just $9/mo. Includes free domain and renewals. Free 7 day trial.
bunchjesse is offline
Reply With Quote
View Public Profile Visit bunchjesse's homepage!
 
Old 08-20-2009, 07:27 PM Re: Database INSRT works but does not show up in PHP MyAdmin
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I must ask you to please take another look at your database connection file that you include, and carefully check that you are connecting to and choosing the right database, the same one that you are viewing in phpMyAdmin. Because the only thing I can think of is that it's not the same table.

If you drop the table and still try to make an insertion MySQL must give you an error, there is no other option. Or perhaps you have accidentally made two identical tables with only slighly different names?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Database INSRT works but does not show up in PHP MyAdmin
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38312 seconds with 12 queries