Hi everyone hope you are ok
i have mistake in my php and i cant find it. please help me
I need to create 3 php . create table , insert_pdo ands select data.
That is my html:

`       <form action="" method="get"> <!-- Search box --> <input  type="text" name="search_text" id="search_text" placeholder="Search"/> <!-- Search button --> <input  type="image" name="search_button" id="search_button" src="search-button.png" /> </form><!-- search form end --> <!-- search end --> </ul> </nav><!-- end navigation --> <div class="clearer"></div> <!-- menu end --> </div> <!-- header end --> <div class="body"> <!-- body start --> <br> <br> <br> <!--   Jsfiddle.net. (2017). jQuery check uncheck all checkboxes - JSFiddle.
 [online] Available at: http://jsfiddle.net/NogginBox/ScnQT/1/ [Accessed 13 Mar. 2017].--> <h3 class="sub-h3">Preferences</h3> <form action="insert_pdo.php" method="POST" name="my-form" id="my-form" class="my-form"> <!-- heading 4 size -comunications --> <fieldset class="fieldset-sub"> <h4 class="sub-h4">Newsletter</h4> <!-- label and checkbox subscribe --> <p><label class="label-sub">Please enter your email to subscribe</label><input type="text" class="email" id="email" name="email" placeholder="NAME@EXAMPLE.COM" style="width:150px; margin-left:50px" > </p> <br><br><br> <!-- heading 4 size -comunications --> <h4>Communications</h4><br> <!-- select all checkbox --> <label><input type="checkbox" id="select-all" class="select-all" name="checkbox[]" value="select_all"/> Select all</label><br><br><br> <p><label class="label-sub">Email me when items in my wishlist drop in price</label><input type="checkbox" id="checkbox_subscribe" name="checkbox[]" value="checkbox_subscribe1" style="margin-left:290px;" /> </p> <br><br><br> <p><label class="label-sub"> Email me about the items in my wishlist</label><input type="checkbox"id="checkbox-subscribe" name="checkbox[]" value="checkbox_subscribe2" style="margin-left:340px;"/></p> <br><br><br> <p><label class="label-sub">Email me if I have items in my basket, and not completed checkout</label><input type="checkbox" id="checkbox[]" name="checkbox" value="checkbox_subscribe3" style="margin-left:194px;" /></p> <br><br> <p><strong><label class="label-sub">What kind of books you would like to subscribe</label></strong></p><br><br> <ul class="checkbox-grid"> <li><input type="checkbox" name="checkbox[]" value="art" /><label for="checkbox">Art</label> <li><input type="checkbox" name="checkbox[]" value="architecture" /><label for="checkbox">Architecture</label> <li><input type="checkbox" name="checkbox[]" value="biography" /><label for="checkbox">Biography</label> <li><input type="checkbox" name="checkbox[]" value="businessFinance" /><label for="checkbox">Business & Finance</label> <li><input type="checkbox" name="checkbox[]"  value="scienceFiction" /><label for="checkbox">Science fiction</label> <li><input type="checkbox" name="checkbox[]"  value="drama"/><label for="checkbox">Drama</label> <li><input type="checkbox" name="checkbox[]"  value="romance" /><label for="checkbox">Romance</label> <li><input type="checkbox" name="checkbox[]"  value="mystery" /><label for="checkbox">Mystery</label> <li><input type="checkbox" name="checkbox[]"  value="horror" /><label for="checkbox">Horror</label> <li><input type="checkbox" name="checkbox[]"  value="history" /><label for="checkbox">History</label> <li><input type="checkbox" name="checkbox[]"  value="dictionaries" /><label for="checkbox">Dictionaries</label> <li><input type="checkbox" name="checkbox[]"  value="fantasy" /><label for="checkbox">Fantasy</label> <li><input type="checkbox" name="checkbox[]"  value="journals" /><label for="checkbox">Journals</label> <li><input type="checkbox" name="checkbox[]"  value="children" /><label for="checkbox">Children's</label> <li><input type="checkbox" name="checkbox[]"  value="science" /><label for="checkbox">Science</label> <li><input type="checkbox" name="checkbox[]"  value="poetry" /><label for="checkbox">Poetry</label> </ul> <br><br><br> <!-- save preferences button --> <button class="submit" id="submit"  style=" width:150px; margin-left:1000px;">Safe preferences</button> <br><br><br>`

Create table:

<?php

include "connect_pdo.php";

$sql = "CREATE TABLE IF NOT EXISTS preferences (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(200) NOT NULL,
 checkbox VARCHAR(200) NOT NULL)";

$sq = $pdo->query($sql);

if  ($sq) {
    echo 'created';
}
?>

Insert_pdo

<?php
$email = $_POST['email'];
$checkbox = $_POST['checkbox'];

// You have to loop through the array of checked box values ...
$check="";
foreach($check as $entry){
$check .= $entry.",";
}

try {
include "connect_pdo.php";

$query = $pdo->prepare('INSERT INTO preferences (email, checkbox) VALUES(:email,:check)');

header("Location: preferences.html");
}
catch(PDOException $e) {
echo 'Error: ' .$e->getMessage();
}
?>

select_data php

<?php

include "connect_pdo.php";

$query = $pdo->prepare("SELECT * FROM preferences");
$query->execute();
$query->setFetchMode(PDO::FETCH_NUM);
echo"<table border=\"1\" width\100\">";
while($r = $query->fetch()){

  $test1 = $r[1];
  $test2 = $r[2];
  $test3 = $r[3];

echo"<tr><td>$test1</td><td>$test2</td><td>$test3</td><</tr>";

}
echo"</table>";
?>

Recommended Answers

All 3 Replies

There are several mistakes before we even get to your question.

  1. You posted the title in ALL CAPS WHICH IS KIND OF RUDE (I corrected that)
  2. You posted a mess of unformatted html and expected us to wade through it
  3. You didn't give any indication as to what error you are seeing

Hi sorry abouty the tittle.
Sorry how i posted the html and php i am trying to learn it
i think the error is in create_table.php or insert_pdo.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.