HELP php HELP NEEDED ASAP!!!
8 posts
Page 1 of 1
Hello guys
i am working on a site along with @visualtech but he is my php guru and has had to go for a month and now i am left with an error and i dont know how to fix it.
if you go to this page and scroll down you should see a button saying submit comment.
but when we attempt to finlize and submit it says their is an error and i dont have a clue were or how to fix it.
here is the code
i am working on a site along with @visualtech but he is my php guru and has had to go for a month and now i am left with an error and i dont know how to fix it.
if you go to this page and scroll down you should see a button saying submit comment.
but when we attempt to finlize and submit it says their is an error and i dont have a clue were or how to fix it.
here is the code
Code: Select all
I have changed the username and password to save people loging into my accounts but yh if anyone could help me out ASAP :P<?php
header('Access-Control-Allow-Origin: *');
error_reporting(E_ALL ^ E_DEPRECATED);
$dbHost = "localhost";
$dbUser = "username";
$dbPass = "password";
$dbName = "aboutdiego";
$dbTable = "comments";
$mysql = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
if ($mysql->errno > 0){
die("Error: " + $mysql->errno);
}
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$base64_pic = null;
$pic_mime = null;
if (isset($_FILES['pic'])) {
$uploadOk = 0;
$check = getimagesize($_FILES["pic"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
$pic_mime = $check['mime'];
} else {
$uploadOk = 0;
}
if ($uploadOk == 1) {
$temp_name = substr(sha1(time() * rand()), 0, 44);
$target = "./temp/$temp_name";
if (move_uploaded_file($_FILES["pic"]["tmp_name"], $target)) {
$base64_pic = base64_encode(file_get_contents($target));
unlink($target);
}
}
}
$base_stm = "INSERT INTO `$dbTable` (`name`, `comment`, `act_code`";
$values = "VALUES (?, ?, ?";
$stm = "";
$bind_count = 3;
if ($base64_pic !== null) {
$base_stm .= ", `picture`, `pic_mime`";
$values .= ", ?, ?";
$bind_count++;
$bind_count++;
}
if (isset($email)) {
$base_stm .= ", `email`";
$values .= ", ?";
$bind_count++;
}
$stm = $base_stm . ") " . ($values . ")");
if ($statement = $mysql->prepare($stm)) {
$act_code = substr(hash('sha512', (time() * rand())), 0, 64);
if ($bind_count === 3) {
$statement->bind_param("sss", $name, $message, $act_code);
} else if ($bind_count === 5) {
$statement->bind_param("sssss", $name, $message, $act_code, $base64_pic, $pic_mime);
} else if ($bind_count === 6) {
$statement->bind_param("ssssss", $name, $message, $act_code, $base64_pic, $pic_mime, $email);
}
if ($statement->execute()) {
echo "200";
$to = "YOUR EMAIL";
$from = "no-reply@diegosaurs.net";
$headers = "From: " . $from . "\r\nContent-type: text/html\r\n";
$url = "http://localhost:5110/index.php?action=activate&code=$act_code";
$message_to_send = "Message: $message <br><br> Click <a href=\"$url\">here</a> to confirm.";
if (mail($to, "New Comment - Diegosaurs" , $message_to_send, $headers)) {
echo "MAILED!";
}
} else {
echo "-100 : " . $mysql->error;
}
} else {
echo ($mysql->error);
}
}
switch ($_GET['action']) {
case 'get':
$result = $mysql->query("SELECT * FROM `$dbTable` WHERE act_stat='1'");
$return = array("total_length" => $result->num_rows);
$objects = array();
while (($row = $result->fetch_assoc())) {
$name = $row['name'];
$comment = $row['comment'];
$pic = $row['picture'];
$mime = $row['pic_mime'];
$arr = array('name' => $name, 'comment' => $comment);
if (isset($pic) && $pic !== null && $pic !== "") {
$arr['pic'] = $pic;
$arr['mime'] = $mime;
}
array_push($objects, $arr);
}
$return['objects'] = $objects;
$return = json_encode($return);
die ($return);
break;
case 'activate':
$code = $_GET['code'];
if ($statement = $mysql->prepare("UPDATE `$dbTable` SET act_stat='1' WHERE act_code=?")) {
$statement->bind_param("s", $code);
if ($statement->execute()) { die("DONE!"); }
}
break;
}
?>
Could you post the error in question? It could help to get a better sense as to what's going wrong cooll;
Notice: Undefined index: action in /home/richardjmanning/public_html/comments.php on line 121
http://diegosaurs.net/About.html also their is the link dont know why it didnt post in the first time
Code: Select all
PHP leads to an invalid function.switch ($_GET['action']) {
I'm not that well advanced into PHP, but some of the experts should be able to shed some light on your problem.
It seems to be that you don't pass an "action" parameter to comments.php once you submit the form.
To make sure the switch statement doesn't execute unless there's an "action" parameter, you can use isset(), like so:
To make sure the switch statement doesn't execute unless there's an "action" parameter, you can use isset(), like so:
Code: Select all
if(isset($_GET['action'])){
switch($_GET['action']) {
//Stuff here
}
}
could somone please fix the code for me not it does not give any errors bit it does not work either.
if anyone could help me either on this or if its more convient add me on skype rman180 and help me their were i can give you access to servers etc..
if anyone could help me either on this or if its more convient add me on skype rman180 and help me their were i can give you access to servers etc..
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023