INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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.

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

thought about posting in the php forum? that's likely where the problem is

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

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

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

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

(OP)
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.

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

(OP)
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.

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

O.k. post a link here to the new thread in the forum434: PHP 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

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

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

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

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close