473,382 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help with php to MySql...

Hello --

I am trying to write to a a MySql database using php, and I seem to be
hitting a wall.

I am attaching my php file in case someone can look at it. When I run
it, I don't get any error messages and all my echoes come through but
nothing is written to my database. I think I am missing something
stupid. Any help would be appreciated.

Thanks,
Peter

May 31 '06 #1
10 1689

1) check that error reporting is enabled
2) check you don't have transactions on (you will need to commit by hand)
3) mysql_query can return a result. Capure it and analyse it
4) enable logging on the DB, and see what it gets. This often gives
a clue where the query breaks

And as much as PEAR::DB can kill performance, a query like that is
just begging to be automated via some kind of statement preparation.
You should also pay attention to escaping quotes and such, in your fields.

/marcin

Peschtra wrote:
Hello --

I am trying to write to a a MySql database using php, and I seem to be
hitting a wall.

I am attaching my php file in case someone can look at it. When I run
it, I don't get any error messages and all my echoes come through but
nothing is written to my database. I think I am missing something
stupid. Any help would be appreciated.

Thanks,
Peter

------------------------------------------------------------------------

Processed
"; $link = mysql_connect("db377.perfora.net", "dbo165086404",
"jxtJdnCJ") or die ('I cannot connect to the database because: ' .
mysql_error()); echo "Connected
"; mysql_select_db(db165086404) or die('Could not select database');
echo "db Selected
"; echo "Hi
"; mysql_query("INSERT INTO 2006_eval (overall,
overall_comments,difficult, difficulty_comments, homework,
homework_comments, pace, pace_comments, grading_structure,
grading_structure_comments, grading_fairness, grading_fairness_comments,
tests, tests_comments, labs, labs_comments, questions,
questions_comments, approach, approach_comments, fav_topic, fav_act,
least_fav_topic, least_fav_act, extra_topic, tests_prepared, didnt_get,
change, again, again_comments, general_comments, name, ip, year, math,
science, grade, number) VALUES ('$overall', '$overall_comments',
'$difficulty', '$difficulty_comments', '$homework',
'$homework_comments', '$pace', '$pace_comments', '$grading_structure',
'$grading_structure_comments', '$grading_fairness',
$grading_fairness_comments', '$tests', '$tests_comments', '$labs',
'$labs_comments', '$questions', '$questions_comments', '$approach',
'$approach_comments', '$fav_topic', '$fav_act', '$least_fav_topic',
'$least_fav_act', '$extra_topic', '$tests_prepared', '$didnt_get',
'$change', '$again', '$again_comments', '$general_comments', '$name',
'$ip', '$year', '$math', '$science', '$grade')"); ?> Inserted

May 31 '06 #2
take a close look at $grading_fairness_comments
Peschtra wrote:
Hello --

I am trying to write to a a MySql database using php, and I seem to be
hitting a wall.

I am attaching my php file in case someone can look at it. When I run
it, I don't get any error messages and all my echoes come through but
nothing is written to my database. I think I am missing something
stupid. Any help would be appreciated.

Thanks,
Peter

--------------030200090501090308020103
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
filename="eval.php"
X-Google-AttachSize: 3113

<html>
<body>

<?php

$overall =3D $_POST["overall"];
echo $overall;
$overall_comments =3D $_POST["overall_comments"];
echo $overall_comments;
$difficulty =3D $_POST["difficulty"];
$difficulty_comments =3D $_POST["difficulty_comments"];
$homework =3D $_POST["homework"];
$homework_comments =3D $_POST["homework_comments"];
$pace =3D $_POST["pace"];
$pace_comments =3D $_POST["pace_comments"];
$grading_structure =3D $_POST["grading_structure"];
$grading_structure_comments =3D $_POST["grading_structure_comments"];
$grading_fairness =3D $_POST["grading_fairness"];
$grading_fairness_comments =3D $_POST["grading_fairness_comments"];
$tests =3D $_POSTS["tests"];
$tests_comments =3D $_POST["tests_comments"];
$labs =3D $_POST["labs"];
$labs_comments =3D $_POST["labs_comments"];
$questions =3D $_POST["questions"];
$questions_comments =3D $_POST["questions_comments"];
$approach =3D $_POST["approach"];
$approach_comments =3D $_POST["approach_comments"];
$fav_topic =3D $_POST["fav_topic"];
$fav_act =3D $_POST["fav_act"];
$least_fav_topic =3D $_POST["least_fav_topic"];
$least_fav_act =3D $_POST["least_fav_act"];
$extra_topic =3D $_POST["extra_topic"];
$tests_prepared =3D $_POST["tests_prepared"];
$didnt_get =3D $_POST["didnt_get"];
$change =3D $_POST["change"];
$again =3D $_POST["again"];
$again_comments =3D $_POST["again_comments"];
$general_comments =3D $_POST["general_comments"];
$name =3D $_POST["name"];
$ip =3D GetHostByName($REMOTE_ADDR);
echo $ip;
$year =3D $_POST["year"];
echo $year;
$math =3D $_POST["math"];
$science =3D $_POST["science"];
$grade =3D $_POST["grade"];
echo $grade;

echo "<br />Processed <br />";

$link =3D mysql_connect("db377.perfora.net", "dbo165086404", "jxtJdnCJ") =
or die ('I cannot connect to the database because: ' . mysql_error());

echo "Connected <br />";

mysql_select_db(db165086404) or die('Could not select database');

echo "db Selected <br />";

echo "Hi <br />";

mysql_query("INSERT INTO 2006_eval (overall, overall_comments,difficult, =
difficulty_comments, homework, homework_comments, pace, pace_comments, gr=
ading_structure, grading_structure_comments, grading_fairness, grading_fa=
irness_comments, tests, tests_comments, labs, labs_comments, questions, q=
uestions_comments, approach, approach_comments, fav_topic, fav_act, least=
_fav_topic, least_fav_act, extra_topic, tests_prepared, didnt_get, change=
, again, again_comments, general_comments, name, ip, year, math, science,=
grade, number) VALUES ('$overall', '$overall_comments', '$difficulty', '=
$difficulty_comments', '$homework', '$homework_comments', '$pace', '$pace=
_comments', '$grading_structure', '$grading_structure_comments', '$gradin=
g_fairness', $grading_fairness_comments', '$tests', '$tests_comments', '$=
labs', '$labs_comments', '$questions', '$questions_comments', '$approach'=
, '$approach_comments', '$fav_topic', '$fav_act', '$least_fav_topic', '$l=
east_fav_act', '$extra_topic', '$tests_prepared', '$didnt_get', '$change'=
, '$again', '$again_comments', '$general_comments', '$name', '$ip', '$yea=
r', '$math', '$science', '$grade')");
?>

Inserted
</body>
</html>

--------------030200090501090308020103--


May 31 '06 #3
Marcin's right, 'a query like that is just begging to be automated'
but, in any event, writing the query something like this would make
those kind of mistakes much easier to spot;

$query = "INSERT INTO table
(
value1, //you can even add comments
value2,
value3
)
VALUES
(
'value1',
'value2',
'value3'
);";

mysql_query($query) etc

May 31 '06 #4
Peschtra wrote:
Hello --

I am trying to write to a a MySql database using php, and I seem to be
hitting a wall.

I am attaching my php file in case someone can look at it. When I run
it, I don't get any error messages and all my echoes come through but
nothing is written to my database. I think I am missing something
stupid. Any help would be appreciated.

Thanks,
Peter


Inserted


Instead of all those assignments fron $_POST, take a look at the PHP
extract() function.
May 31 '06 #5
Marcin --

Thanks for the reply. However, I don't know how to do most of what you
suggest. After I send this I am going to library to hopefully find a
book as I find most of the website confusing.

How does one enable error reporting?

I don't know understand what your statement about transactions or
committing by hand means. :(

I think I capture the mysql query with $res = mysql_query (INSERT, but I
don't know how to analyze it.

If I don't have the DB on my computer (it is on my hosts computer) can I
still enable logging?

Sorry for the questions but greatful for any help from anyone.

Peter Kupfer

Marcin Dobrucki wrote:

1) check that error reporting is enabled
2) check you don't have transactions on (you will need to commit by hand)
3) mysql_query can return a result. Capure it and analyse it
4) enable logging on the DB, and see what it gets. This often gives a
clue where the query breaks

And as much as PEAR::DB can kill performance, a query like that is
just begging to be automated via some kind of statement preparation. You
should also pay attention to escaping quotes and such, in your fields.

/marcin

Jun 1 '06 #6
Strawberry -

Thanks for your help.

I don't know what it means for something to be automated. :(

I changed my script as you suggested and found one missing ' (where you
suggested in your previous post), but still no luck.

Thanks again,

Peter

I don't know what

strawberry wrote:
Marcin's right, 'a query like that is just begging to be automated'
but, in any event, writing the query something like this would make
those kind of mistakes much easier to spot;

$query = "INSERT INTO table
(
value1, //you can even add comments
value2,
value3
)
VALUES
(
'value1',
'value2',
'value3'
);";

mysql_query($query) etc

Jun 1 '06 #7
OK, well try to narrow the possibilities down a bit. Add something like
the following to the top of your page:

<pre>
<?php
// Let's see what data is successfully passed to this page:

echo "GET";
print_r ($_GET);
echo "POST";
print_r ($_POST);
?>
</pre>

Then add an "or die" statement to the end of your query - something
like this:

$result = mysql_query($query) or die ("Couldn't INSERT");

and echo the query.

echo $query;

Peschtra wrote:
Strawberry -

Thanks for your help.

I don't know what it means for something to be automated. :(

I changed my script as you suggested and found one missing ' (where you
suggested in your previous post), but still no luck.

Thanks again,

Peter

I don't know what

strawberry wrote:
Marcin's right, 'a query like that is just begging to be automated'
but, in any event, writing the query something like this would make
those kind of mistakes much easier to spot;

$query = "INSERT INTO table
(
value1, //you can even add comments
value2,
value3
)
VALUES
(
'value1',
'value2',
'value3'
);";

mysql_query($query) etc


Jun 1 '06 #8
Did you have a look at the quoting strawberry suggesting in the
previous post?

'$grading_fairness', $grading_fairness_comments'

Notice the missing quotation mark...if that isn't all try doing a dummy
transaction using your MySQL front-end, by grabbing this code and
substituting values in or even better get php to echo the whole
statement on the page and cut and paste that directly into your MySQL
front-end, this should uncover any syntax errors etc. very quickly.
Peschtra wrote:
Strawberry -

Thanks for your help.

I don't know what it means for something to be automated. :(

I changed my script as you suggested and found one missing ' (where you
suggested in your previous post), but still no luck.

Thanks again,

Peter

I don't know what

strawberry wrote:
Marcin's right, 'a query like that is just begging to be automated'
but, in any event, writing the query something like this would make
those kind of mistakes much easier to spot;

$query = "INSERT INTO table
(
value1, //you can even add comments
value2,
value3
)
VALUES
(
'value1',
'value2',
'value3'
);";

mysql_query($query) etc


Jun 1 '06 #9
Also, "number" appears to be missing from the values. Maybe 'number' is
autoincremented - in which case the end of your statement should like
this:

'$science',
'$grade','')

And (less importantly) there is a name mismatch between "difficult" and
"difficulty". This doesn't matter at the moment but it could cause
problems when you get round to learning about generating this stuff
automatically!

Jun 1 '06 #10


Peschtra wrote:
Thanks for the reply. However, I don't know how to do most of what you
suggest. After I send this I am going to library to hopefully find a
book as I find most of the website confusing.

How does one enable error reporting?
You know, you could make a bit of an effort:
http://www.php.net/manual/en/functio...-reporting.php
I don't know understand what your statement about transactions or
committing by hand means. :(
http://dev.mysql.com/doc/refman/5.1/...nsactions.html
I think I capture the mysql query with $res = mysql_query (INSERT, but I
don't know how to analyze it.
http://www.php.net/manual/en/function.mysql-query.php

All you need to do is copy&paste the example to get the mysql error
out of your query (if such error occured)
If I don't have the DB on my computer (it is on my hosts computer) can I
still enable logging?


No, then probably you can't unless you can arrange it with the
privider. You can however print the queries onto the screen, then copy
them onto a locally installed db, and see what it complains about.

/m
Jun 2 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pancho | last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO on a Solaris 8 box - this module is needed to host some existing sites I will be migrating Note. I built PHP4 from source and...
0
by: root | last post by:
hi there, I've tried to install mysql-3.23.55.tar.gz but failed. Firstly, I've created directory /home/users/mysql and add group for mysql. Those are the command that I've used previously: ...
0
by: Richard Gabriel | last post by:
Hi everyone, Since we upgraded to MySQL 4.0.13 from 3.23, we have been getting table corruption often. It happens about twice per week (with about 500 queries per second average). I have even...
0
by: Ryan Schefke | last post by:
------=_NextPart_000_0077_01C34C8B.2B90C960 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit ..I just sent this out to the win32 distribution list but no one has...
0
by: Mark Adams | last post by:
I really need some help with this. MySQL will not start on boot despite everything I've done to make sure that it is set to do so. When I start it as root from a terminal with...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' ...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
1
by: DarkGiank | last post by:
Hi, im new to csharp and im trying to create a class that can change the application database without no rewriting all connection code... but cause some reason it is not working... it tells me that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.