Page 1 of 1
$result = mysql_query ($query);
Posted: Thu Feb 03, 2005 12:45 pm
by comtek
Below is a snip that I am playing with... everything appears to be working except:
$result = mysql_query ($query);
I get results from the $_POST and $query usig the print_r but nothing for the $results
Am I coding something wrong?
Code: Select all
if (isset($_POSTї'submit'])) {
require_once ('dbconnect.php'); // Connect to the database.
$query = "INSERT INTO patients (firstname, initial, lastname, dob, ) VALUES ('$firstname', '$initial', '$lastname', '$dob', NOW())";
$result = mysql_query ($query);
echo '<pre>';
print_r ($result);
echo '</pre>';
echo '<pre>';
print_r ($query);
echo '</pre>';
echo '<pre>';
print_r ($_POST);
echo '</pre>';
Posted: Thu Feb 03, 2005 12:47 pm
by feyd
you have an error in your SQL query... you did not name the field for which NOW() should be inserted into.
Posted: Thu Feb 03, 2005 2:01 pm
by Deemo
a good way to check whats wrong is to change the $result line to:
$result = mysql_query($query) or die("Could Not Execute Query: ".mysql_error());
Posted: Thu Feb 03, 2005 9:17 pm
by comtek
OK I changed the NOW() . Also part of my problem was in the dbconnect file... I had a mysql_close command at the end of the file.
Now i get the following message on my page:
DB SelectedColumn count doesn't match value count at row 1
I am not sure what this means.
Also, I have more $_POST array values that are not in the INSERT command... would that cause any problems?
Here is the script as it is now:
Code: Select all
<?php
include ('includes/header.html');
echo '<pre>';
print_r ($_POST);
echo '</pre>';
if (isset($_POSTї'submit'])) {
require_once ('dbconnect.php'); // Connect to the database.
$query = "INSERT INTO patients (firstname, initial, lastname, dob) VALUES ('$firstname', '$initial', '$lastname', '$dob', date=NOW())";
$result = mysql_query ($query) or die(mysql_error());
echo '<pre>';
print_r ($result);
echo '</pre>';
echo '<pre>';
print_r ($query);
echo '</pre>';
}
if (isset($firstname)) {
print "$firstname ";
}
if (isset($initial)) {
print "$initial ";
}
if (isset($lastname)) {
print "$lastname <br>";
}
if (isset($dob)) {
print "$dob ";
}
if (isset($social)) {
print "$social ";
}
if ($address2 < null) {
print "Address: $address2 ";
}
include ('includes/footer.html');
?>
Posted: Thu Feb 03, 2005 9:23 pm
by comtek
seems to be comming from here:
Code: Select all
$select = mysql_select_db(DB_NAME);
if (!$select) {
die ('Could not select the database: ' . mysql_error());
}
echo 'DB Selected';
Above is part of my dbconnect.php
Posted: Thu Feb 03, 2005 9:37 pm
by comtek
Below is what I get on my screen:
Array
(
[MAX_FILE_SIZE] => 2524288
[firstname] => tommy
[initial] => w
[lastname] => bbaa
[dob] => 11-11-1
[address1] => 21212 ain
[address2] =>
[city] => jdoiaisd
[state] => dsa
[zip] => oskdoaska
[social] => 12121
[phone] => 121212
[submit] => Submit
)
Connected successfully
DB SelectedColumn count doesn't match value count at row 1
Posted: Thu Feb 03, 2005 9:42 pm
by comtek
Sorry... Its late and I am stupid.
I was reading the message wrong.
My problem was that did not complete everything that the NOW needed.
It seems to be working now.
Posted: Fri Feb 04, 2005 9:34 pm
by comtek
Everything is working now, thanks to your help. Just one question though.
This bit of code:
Code: Select all
$query = "INSERT INTO patients (patient_num, gender, status, firstname, initial, lastname, dob, ss, address1, address2, city, state, zip, phone, employer, employer_addy, health_ins, pharm_cov, hourly_wage, weekly_hours, annual_salary, other_income, date) VALUES ( '$patient_num', '$gender', '$status', '$firstname', '$initial', '$lastname', '$dob', '$ss', '$address1', '$address2', '$city', '$state', '$zip', '$phone', '$employer', '$employer_addy', '$health_ins', '$pharm_cov', '$hourly_wage', '$weekly_hours', '$annual_salary', '$other_income', NOW())";
$result = mysql_query ($query) or die(mysql_error());
echo '<pre>';
echo "This is the result : <br>" ;
print_r ( $result);
echo '</pre>';
echo '<pre>';
echo "This is the query : <br>" ;
print_r ( $query);
echo '</pre>';
}
if (isset($firstname)) {
print "$firstname ";
}
if (isset($initial)) {
print "$initial ";
}
if (isset($lastname)) {
print "$lastname <br>";
}
if (isset($dob)) {
print "$dob ";
}
if (isset($social)) {
print "$social ";
}
if ($address2 < null) {
print "Address: $address2 ";
}
Returns the following:
===============================================
...
[hourly_wage] => 4 carrots
[weekly_hours] => 40
[annual_salary] => 25000
[other_income] => 123
[submit] => Continue
)
Connected successfully
DB Selected
This is the result :
1
This is the query : INSERT INTO patients (patient_num.....
Bugs I Like Carrots Bunny
1922-12-3
============================================
The part that says "This result:
1
Is that coming from the "or die(mysql_error());" part of $result
Just curious as to what it means.
Thanks
Posted: Fri Feb 04, 2005 9:57 pm
by feyd
it's from the print_r($result)
insert queries return true/false.