Hello, I created a php program last week that took in a time from a drop down menu and a persons name from a text box and store it in a text file. Also when submitted the form echo'd the Time and Persons name or echo'd if either the time was already taken or the name was already taken. The names and times were stored in a text file.
I am trying to make the same program but using a MySQL database in place of the text file. I am kind of new using MySQL with PHP but thought maybe someone could steer me in the right direction. Basically transforming 1 PHP program into the same one with a different method. Below is the code from the working program using the text file and the new one I am currently working on.
Any help would be appreciated, but currently I am getting an "Call to undefined function: msysql_connect()" error but I also know the rest isnt going to work as totally intended.
Using just PHP working as inteded
<?
$time=$_POST["time"];
$person=$_POST["user"];
if (file_exists("register.txt"))
{
$fileCheck = file("register.txt");
}
else {
$fileCheck = array();
}
$file = fopen("register.txt", "a+");
$newperson = "$time , $person\n";
$infile = false;
foreach ($fileCheck as $line)
{
if (stristr($line, $time) !== false)
{
echo "The timeslot is taken";
$infile = true;
}
if (stristr($line, $person) !== false)
{
echo "The name is taken";
$infile = true;
}
}
if (!$infile) {
fwrite($file, $newperson);
echo "<br>Time: $time";
echo "<br> Name: $person";
}
?>
Attempting to use MySQL to do the same thing:
<?
$time=$_POST["time"];
$person=$_POST["user"];
$conn = msysql_connect("localhost", "username");
if (!$conn)
die("Error in connecting to MySQL database server");
@mysql_select_db("database", $conn) or
die("Error in selecting database");
$addrecord = "INSERT INTO regtable (Time, User) VALUES (".$_POST["time"]." , ".$_POST["user"].")";
$report = mysql_query($addrecord, $conn);
if(!$report) {
die("Error in retrieving information");
}
if($report) {
echo "<br>Time: $time";
echo "<br>Name: $person";
}
?>