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 which is hosted on GoDaddy and it works fine, but when I try it in my local practice machine it won't insert the record and I do not receive any errors. From what I have seen the process.php script never starts running I introduced an error on the first line, but I don't get the error, when I click on Process in the inputform.php script it gives me a blank page with the process.php name on the address back.
I wonder if you have any idea as to why process.php does not seem to run? The 2 scripts are:
inputform.php:
<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>
process.php:
<?
$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.";
?>
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 setup the query.php as below and it does return results, I tried introducing an error in this query script by removing a semi-colon and I do get the error on the screen and see it in the log file, this seems to point out that the setup is working correctly.
<?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'];
?>
I will greatly appreciate your response.
I wonder if you have any idea as to why process.php does not seem to run? The 2 scripts are:
inputform.php:
<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>
process.php:
<?
$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.";
?>
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 setup the query.php as below and it does return results, I tried introducing an error in this query script by removing a semi-colon and I do get the error on the screen and see it in the log file, this seems to point out that the setup is working correctly.
<?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'];
?>
I will greatly appreciate your response.