Jump to content

rx3mer

Members
  • Posts

    46
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Interests
    Web

rx3mer's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey, I haven't done the checks for each input but the script should work. PHP file <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $selection = $_POST['selection']; $comment = $_POST['comment']; $to = "[email protected]"; $subject="XXX Web Inquiry"; $message=""; $message.= "Hello,<br><br>\n"; $message.="<b>Name:</b> ".$name.".<br><br>\n"; $message.="<b>Email:</b> ".$email."<br><br>\n"; $message.="<b>Phone:</b> ".$phone."<br><br>\n"; $message.="<b>Selection:</b> ".$selection."<br><br>\n"; $message.="<b>Comment:</b> ".$comment."<br><br>\n"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From:".$name."<".$email.">\r\n"; $headers .= "Reply-To:".$name."<".$email.">\r\n"; $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n"; $headers .= "X-Priority: 1"; mail($to,$subject,$message,$headers); if (isset($HTTP_REFERER)) { echo "Your email has been send! | <a href='$HTTP_REFERER'>back</a>"; } else { echo " Your email has been send! | <a href='javascript:history.back()'>back</a>"; } ?> You don't need to change anything in the html file.
  2. I had to slightly modify the code to make it work without errors, but I am still having the same issue. INSERT INTO data (user_id, identifier_name, pos_x, pos_y, window_width, window_height, status) VALUES (1, '.testimonial', '1119', '316', '1663', '608', 'ok') INSERT INTO data (user_id, identifier_name, pos_x, pos_y, window_width, window_height, status) VALUES (1, '#header', '723', '66', '1663', '608', 'ok') New record created successfully Only the last INSERT has been done: Updated code: <?php $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "clickmap"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $clicks = '.testimonial;1119;316;1663;608;#header;723;66;1663;608'; $keys = array('identifier_name', 'pos_x', 'pos_y','window_width','window_height'); $arr = explode(';', $clicks); $data = array_chunk($arr, 5); foreach ($data as $rec) { $sql = "INSERT INTO data (user_id, " . join(', ', $keys) . ", status) VALUES "; $sql .= "(1, '" . join("', '", $rec) . "', 'ok')";; echo $sql . '<br>'; } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> Really strange
  3. I am using AJAX to send an array of values to a PHP page that will insert the data into MySQL database. For some reason only the last 5 values are inserted into the MySQL database and I am woundering how to fix that. I am using foreach loop. AJAX Request: Array: [".testimonial", 1119, 316, 1663, 608, "#header", 723, 66, 1663, 608] Posting the array: Sending Array Parameters using " ; " to split. clicks .testimonial;1119;316;1663;608;#header;723;66;1663;608 Source Sent: clicks=.testimonial%3B1119%3B316%3B1663%3B608%3B%23header%3B723%3B66%3B1663%3B608 PHP Page <?php $clicks = $_GET["clicks"]; $clickArray = explode(";",$clicks); $arrays = array_chunk($clickArray, 5); $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "clickmap"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $keys = array('postIdentifier', 'postPos_x', 'postPos_y','postWindowWidth','postWindowHeight'); foreach ($arrays as $array_num => $array) { $values = array(); foreach ($array as $item_num => $item) { $values[] = $item; } $data = array_combine($keys, $values); extract($data); // now your variables are declared with the right values http://php.net/manual/en/function.extract.php $sql = "INSERT INTO data (user_id, identifier_name, pos_x, pos_y, window_width, window_height, status) VALUES ('1', '$postIdentifier', '$postPos_x', '$postPos_y','$postWindowWidth','$postWindowHeight', 'ok')"; } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> Is this the correct way of coding it, and why does it post only the last 5 values? Any help would be much appreciated!
  4. PHP problems...

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.