Note that there are some explanatory texts on larger screens.

plurals
  1. POEntering data from form into database using php
    text
    copied!<p>I am trying to enter data into the database but I keep getting an error. I have no idea where the problem is. Here is the code:</p> <pre><code>&lt;?php $sql = "INSERT INTO $db_table (title,group,overlapok,userid,name,phone,email,description,managers,location,notify,notifyman, remind,remindman,appmsg,viewaccess,viewulist,viewclist,makeaccess,makeulist,makeclist,showappinfo) VALUES ('".mysql_real_escape_string(stripslashes($_REQUEST['txtTitle'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkGroupCal'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkAllowOverlap'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtUserID'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtOwner'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtPhone'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtEmail'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtDesc'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtManagers'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtLocation'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkNotifyMe'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkNotifyMgrs'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkRemind'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['chkRemindMan'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtAppText'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['selViewBlockRestr'])). "','".mysql_real_escape_string(stripslashes($_REQUEST['txtViewBlocksUserID'])) "','".mysql_real_escape_string(stripslashes($_REQUEST['txtViewBlocksCourseID']))."','".mysql_real_escape_string(stripslashes($_REQUEST['selMakeApptRestr']))."','".mysql_real_escape_string(stripslashes($_REQUEST['txtMakeApptUserID']))."','".mysql_real_escape_string(stripslashes($_REQUEST['txtMakeApptDptID']))."','".mysql_real_escape_string(stripslashes($_REQUEST['chkShowAppInfo']))."')"; if($result = mysql_query($sql,$db)) { echo '&lt;h1&gt;Thank you&lt;/h1&gt; Your information has been entered into our database&lt;br&gt;&lt;br&gt; &lt;p&gt; &lt;a href="viewcalendar.page.php"&gt; View Calendar &lt;/a&gt; &lt;/p&gt; &lt;img src="eDiary.jpg"'; } else { echo "ERROR: "; } ?&gt; </code></pre> <p>The form includes sections where there are check boxes that can be left blank. </p> <p>I followed your advice and used PDO. Kept returning the following error:Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argument (trying to connect via unix://) in /opt/lampp/htdocs/Scheduler/pages/enterCal.page.php on line 72 Connection Failed: SQLSTATE[HY000] [2002] Invalid argument Fatal error: Call to a member function exec() on a non-object in /opt/lampp/htdocs/Scheduler/pages/enterCal.page.php on line 80.</p> <p>I figured $db is not an object and that the connection is not being executed. How do I take care of that? I've tried Google but can't seem to come up with anything that works.</p> <pre><code> &lt;?php $dsn = 'mysql:host=localhost;dbname=eDiary'; $user = 'root'; $password = ''; try { $db = new PDO($dsn,$user,$password); $db -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $e) { echo 'Connection Failed: ' . $e-&gt;getMessage(); } $result = $db-&gt;exec("INSERT INTO wassCalendar(title, group, overlapok, userid, name, phone, email, description, managers, location, notify, notifyman, remind, remindman, appmsg, viewaccess, viewulist, viewclist, makeaccess, makeulist, makeclist, showappinfo) VALUES($txtTitle, $chkGroupCal, $chkAllowOverlap, $txtUserID, $txtOwner, $txtPhone, $txtEmail, $txtDesc, $txtManagers, $txtLocation, $chkNotifyMe, $chkNofityMgrs, $chkRemind, $chkRemindMan, $txtAppText, $selViewBlockRestr, $txtViewBlocksUserID, $txtViewBlocksCourseID, $selMakeApptRestr, $txtMakeApptUserID, $txtMakeApptDptID, $chkShowAppInfo)"; $insert_id = mysql_insert_id(); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload