zaneosak Posted November 20, 2008 Share Posted November 20, 2008 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"; } ?> Quote Link to comment Share on other sites More sharing options...
n3ightjay Posted November 20, 2008 Share Posted November 20, 2008 you have a typing error "msysql_connect()" should be "mysql_connect()" Quote Link to comment Share on other sites More sharing options...
zaneosak Posted November 20, 2008 Author Share Posted November 20, 2008 well that was rather dumb, thanks for the heads up. I fixed it and my output is my error message here: if(!$report) { die("Error in retrieving information"); } which I am guessing means its not inserting the information into the table at all, am I correct in that assumption? Quote Link to comment Share on other sites More sharing options...
zaneosak Posted November 20, 2008 Author Share Posted November 20, 2008 Not letting me edit my original post but here is the code that actually seems to output something, but all I get is my error that the record wasnt added to the table in the database <? $time=$_POST["time"]; $person=$_POST["user"]; $conn = mysql_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"; } ?> Output: Error retieving information Quote Link to comment Share on other sites More sharing options...
n3ightjay Posted November 24, 2008 Share Posted November 24, 2008 I think you have to quote you values in your SQL Query IE... $addrecord = "INSERT INTO regtable (Time, User) VALUES ('".$_POST["time"]."' , '".$_POST["user"]."')"; try that ... A little trick i sometimes use when im having troubles with SQL is to echo out the statement then run it on in the database itself to see if it's processing and if not it will tell you where the error is Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.