Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL PHP update db table information through html form
    text
    copied!<p>Thanks in advance.</p> <p>I am trying to update information in my db but am having no luck and no error messages. </p> <p>Here is the page code (the pid or post_id is in the URL):</p> <pre><code>&lt;?php include('page with functions.php'); if (isset($_GET['pid'], $_POST['title'], $_POST['body'])){ if (edit_post($_GET['pid'], $_POST['title'], $_POST['body'])){ header("Location: blog_edit.php?pid={$_GET['pid']}"); }else{ header("Location: some location.php"); } die(); } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Blog Edit&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;?php if (isset($_GET['pid']) ===false || valid_pid($_GET['pid']) === false){ echo 'Invalid post ID'; }else{ $post = get_post($_GET['pid']); ?&gt; &lt;h2&gt;&lt;?php echo $post['title']; ?&gt;&lt;/h2&gt; &lt;hr /&gt; &lt;p&gt;&lt;?php echo $post['body']; ?&gt;&lt;/p&gt; &lt;hr /&gt; &lt;form action="" method="post"&gt; &lt;p&gt; &lt;label for="title"&gt;Title&lt;/label&gt; &lt;input type="text" name="title" id="title" value="&lt;?php echo $post['title']; ?&gt;"/&gt; &lt;/p&gt; &lt;p&gt; &lt;textarea name="body" rows="20" cols="60"&gt;&lt;?php echo $post['body']; ?&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="Edit Post" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is the function (the pid or post_id is in the URL):</p> <pre><code>// edits a blog entry function edit_post($title, $body){ $title = mysql_real_escape_string(htmlentities($title)); $body = mysql_real_escape_string(nl2br(htmlentities($body))); mysql_query("UPDATE `posts` (`post_title`, `post_body`) SET `post_title` = '{$title}' AND `post_body` = '{body}' WHERE `post_id` = {$pid}"); } </code></pre> <p>Any help would be great thanks! FYI I am new to PHP MYSQL so please be kind.</p>
 

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