Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Code won't post to DB (newbie question)

Status
Not open for further replies.

MikeMV

MIS
May 15, 2006
131
US
I am trying to learn php to manipulate MySQL data. I setup a simple input form and a script to insert a record to the database. I tried the code in a working web site and it works fine, but when I try it in my local practice machine it won't insert the record, but I do not receive any errors. Since it works in a live web site I am thinking it could be something with the MySQL setup. I wonder if ideas of things that could stop this from working? The 2 scripts are:

<form action="process.php" method="post">
Your ID: <input type="int(4)" name="id"><br>
Date: <input type="date" name = "day"><br>
Clock In: <input type="time" name = "clockin">
Clock Out: <input type="time" name = "clockout">
<br>
<input type="submit" value="Submit">
</form>

<?
$id=$_POST['id'];
$day=$_POST['day'];
$clockin=$_POST['clockin'];
$clockout=$_POST['clockout'];
mysql_connect("localhost", "john", "Maintenance1") or die(mysql_error());
mysql_select_db("comptechdev") or die(mysql_error());
mysql_query("INSERT INTO clocks (id,day,clockin,clockout) VALUES ('$id', '$day', '$clockin','$clockout')");
Print "Your information has been successfully added to the database.";
?>

The message Print ... never posts, all I get is a blank screen.

I am using Apache 2.22, MySQL 5.6.10, PHP 5.4.13 and phpMyAdmin 3.5.8. I can insert records manually using phpMyAdmin and all tests indicate that my setup is working properly.

I will greatly appreciate any feedback, I know this is vague, but I figure there may be some setting I am missing.

Mike.
 
The first thing to check is if your practice setup has the errors set to be shown.

The easiest way to do this is to deliberately insert an error.

Just remove semi colon form one of your lines and you're sure to get an error. If no error shows, then your setup simply does not have the errors set to be shown.

For starters add the following to the top of your PHP script:

Code:
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);

Though I would strongly suggest for a practice machine to always have errors be shown, and never suppress anything using the @ symbol.

Open your php.ini file and set the following directives:
Code:
error_reporting = E_ALL & ~E_DEPRECATED

...

display_errors = on



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
r937,

Good idea, I'll post it in the PHP forum as well.

What makes me suspect a setting in the MySQL setup is that the code works as is in a live web server. I also tried querying the test database after I posed the message and it works, this tells me that at least the connection to the DB is working, but just not letting me insert a record. Here is what I used to query the DB

<?php

// Make a MySQL Connection
mysql_connect("localhost", "john", "Maintenance1") or die(mysql_error());
mysql_select_db("comptechdev") or die(mysql_error());

// Retrieve all the data from the "clocks" table
$result = mysql_query("SELECT * FROM clocks")
or die(mysql_error());

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry

echo "ID: ".$row['id'];
echo " Date: ".$row['day'];
echo " In: ".$row['clockin'];
echo " Out: ".$row['clockout'];

?>

This returns the one record I inserted manually.

I'll turn on error reporting and see if there is anything that tells me what the problem is.

Thanks.
 
Phil,

There is something strange going on. I turned on error reporting in php.ini and also added your suggested code to the process.php. I even went as far as removing a semi-colon to introduce an error, but still when I click on the Process button, the process.php tries to run, but still get a blank screen.

On the other hand I introduced an error in my query.php to see if it reports it and it did come up on the screen with an error. Something is stalling the process.php script. I'll post in the PHP forum and see if anyone has any ideas.

Thanks for your feedback.
 
O.k. post a link here to the new thread in the forum434 so future users can follow.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Ohh, and also remember to restart the Apache server after you modify the PHP.ini file. so it gets reloaded.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks Phil,

Here is the link to the post in PHP

From what I can see the process.php script never runs, I tried introducing an error on the first line and I never get the error. On the other hand I introduced an error in the query.php script, that throws the error on the screen as well as saving it to the log file.

I am beginning to suspect a difference in the version of PHP that GoDaddy runs and that explains why it works on the live web site, but not in my Apache/MySQL/PHP on Windows 7 64 Bit test install. What I know about the GoDaddy server is that it is a Linux server, Php 5.3 and it seems it is running Apache, but I am not sure.

Thanks again for your prompt feedback.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top