Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble posting to database with a form
    primarykey
    data
    text
    <p>I have a simple form with some PHP code to post to a database some simple information.</p> <p>The connection to the database is just fine because it display items I have manually entered exactly how I want it to; however. I cannot get it to post from the form into the database. I have tinkered with a lot of code with no luck. Anyone see anything I'm missing? Here is the code:</p> <pre><code>&lt;center&gt; &lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="POST"&gt; &lt;strong&gt;&lt;h2&gt;&lt;br&gt;&lt;br&gt;Enter in my guestbook!&lt;/h2&gt;&lt;/strong&gt;&lt;br&gt; &lt;h3&gt;Nickname:&lt;/h3&gt;&lt;input type="text" name="guestbook_name" maxlength="25"&gt;&lt;br&gt; &lt;h3&gt;Write About Your Day:&lt;/h3&gt;&lt;textarea name="guesbook_message" rows="6" cols="60" maxlength="255"&gt;&lt;/textarea&gt;&lt;br&gt; &lt;input type ="submit" value="POST"&gt; &lt;/form&gt; &lt;br&gt; &lt;hr&gt; &lt;br&gt; &lt;?php if (mysql_connect('localhost', 'root', 'root') &amp;&amp; mysql_select_db('mydb')) { //echo 'Connected to the database!'; $time = gmdate("l dS \of F Y h:i:s A"); $errors = array(); if (isset($_POST['guestbook_name'], $_POST['guestbook_message'])) { echo 'Set data!'; $guestbook_name = mysql_real_escape_string(htmlentities( $_POST['guestbook_name'])); $guestbook_message = mysql_real_escape_string(htmlentities( $_POST['guestbook_message'])); if (empty($guestbook_name) || empty($guestbook_message)) { $errors[] = 'All fields are required.'; } if (strlen($guestbook_name)&gt;25 || strlen($guestbook_message)&gt;250){ $errors[] = 'One or more fields exceeded the character limit!'; } if (empty($erros)) { $insert = "INSERT INTO guestbook VALUES ('','$time','$guestbook_name','$guestbook_message')"; if (mysql_query($insert)){ header ('Location: '.$_SERVER['PHP_SELF']); } else { $errors[] = 'Something went wrong. Try again.'; } } else { foreach($errors as $error) { echo'&lt;p&gt;&lt;strong&gt;'.$error.'&lt;/strong&gt;&lt;/p&gt;'; } } } // display entries $entries = mysql_query("SELECT timestamp, name, message FROM guestbook ORDER BY timestamp DESC"); if (mysql_num_rows($entries)==0){ echo 'No entries, yet.'; } else { //echo 'Entries found.'; while ($entries_row = mysql_fetch_assoc($entries)){ $entries_timestamp = $entries_row['timestamp']; $entries_name = $entries_row['name']; $entries_message = $entries_row['message']; echo '&lt;p&gt;&lt;strong&gt;Posted by '.$entries_name.' on '.$entries_timestamp.'&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;'.$entries_message.'&lt;/p&gt;&lt;br&gt;&lt;br&gt;'; } } } else { echo 'Could not connect at this time.'; } ?&gt; &lt;/center&gt; </code></pre> <p>My main issue is the submitting the database, any help would be great, thanks!</p> <p>Kyle B.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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