Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I got this error
Parse error: syntax error, unexpected '}' in C:\wamp\www\widget_corp\public
\create_subject.php on line 24
when I clicked on my "Creae Subject" button.
I have tried to fix it all day but really can't find what the problem is.
<?php require_once ("../includes/session.php"); ?>
<?php require_once ("../includes/db_connection.php"); ?>
<?php require_once ("../includes/functions.php"); ?>
<?php require_once ("../includes/validation_function.php"); ?>
<?php
if (isset($_POST['submit'])) {
// Process the form
$menu_name = mysql_prep($_POST["menu_name"]);
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
// Validations
$required_fields = array("menu_name", "position", "visible");
validate_presences($required_fields);
$fields_with_max_lengths = array("menu_name" => 30);
validate_max_lengths($fields_with_max_lengths);
if (!empty($errors)) {
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php")
} <-------- THIS IS ROW 24! ----------->
$query = "INSERT INTO subjects (";
$query .= " menu_name, position, visible";
$query .= ") VALUES (";
$query .= " '{$menu_name}, {$position}, {$visible}";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result) {
// Success
$_SESSION["message"] = "Subject created!";
redirect_to("manage_content.php");
} else {
// Failure
$_SESSION["message"] = "Subject creation failed";
redirect_to("new_subject.php");
}
} else {
// This is probably a GET request
redirect_to("new_subject.php");
}
?>
<!-- Close database connection -->
<?php if (isset($connection)) { mysqli_close($connection); } ?>
Missing semicolon on the line above the brace.
redirect_to("new_subject.php")
A lot of times you have to look at the line above the one given in the error to see what the problem is.
you have missed semicolon in this line:
redirect_to("new_subject.php");
try this:
if (!empty($errors)) {
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php");
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
<?php
if (isset($_POST['submit'])) {
$title = $_POST['title'];
if (isset($_FILES['images']['name'])) {
$image_name = $_FILES['images']['name'];
echo($image_name);
$image_path = $_FILES['images']['tmp_name'];
echo($image_path);
$destination_path = 'location:'.SITEURL.'images/category/'.$image_name;
// echo($destination_path);
$upload = move_uploaded_file($image_name, $destination_path);
echo($upload);
if ($upload==0) {
$_SESSION['upload_image_category'] = "<div class='error'>failed to upload image </div>";
header('location:'.SITEURL.'admin/add-category.php');
die();
}
}
else{
$image_name = "";
}
if (isset($_POST['featureyon'])) {
$feature = $_POST['featureyon'];
}
else{
$feature = "No";
}
if (isset($_POST['a_yes'])) {
$active = $_POST['a_yes'];
}
else{
$active = "No";
}
# code...
$sql = "INSERT INTO tbl_category SET
title = '$title',
image_name='$image_name',
featured='$feature',
active='$active'
";
$res = mysqli_query($conn, $sql);
if ($res == True) {
$_SESSION['add_category'] = "<div class='success'>New category added</div>";
header('location:'.SITEURL.'admin/manage_category.php');
}
else{
$_SESSION['add_category'] = "<div class='error'>failed to add New category </div>";
header('location:'.SITEURL.'admin/add-category.php');
}
}
?>
the first
$destination_path should be a real pathname on the server, not a URL. Like this :- $destination_path = '../images/category/'.$image_name;
the second
move_uploaded_file(source_path, destination_path) Like this :-
$upload = move_uploaded_file($image_path, $destination_path);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to save multidimensional array in database using json_encode. if i echo json string its showing right output but in database string is changed after insert.
here is my code:
$email=$_POST['email'];
$watchlist=$_POST['watchlist'];
$watchshow=$_POST['watchshow'];
$yearshow=$_POST['yearshow'];
$quer = "SELECT email FROM users WHERE email = '$email'";
$q = mysqli_query($conn, $quer);
$count=0;
while($row = mysqli_fetch_array($q)){
$email = $row['email'];
$count++;
}
if($count==1) //if user already exist change greeting text to "Welcome Back"
{
$quer = "SELECT watchlist FROM users WHERE email = '$email'";
$q = mysqli_query($conn, $quer);
while($row = mysqli_fetch_array($q)){
$watch = $row['watchlist'];
}
$data = json_decode($watch, TRUE);
array_push($data,$watchlist);
$add=array();
array_push($add,$watchshow);
array_push($add,$yearshow);
$data[] = $add;
$t = json_encode($data , JSON_FORCE_OBJECT);
$sql = "update users set watchlist='$t' WHERE email='$email'";
if ($conn->query($sql) === TRUE) {
echo'updated';
} else {
echo'error';
}
}
else {
$new=array();
array_push($new,$watchlist);
$add=array();
array_push($add,$watchshow);
array_push($add,$yearshow);
$new[] = $add;
$name = json_encode($new);
$sql1 = "INSERT INTO users (email,watchlist)
VALUES ('$email','$name')";
if ($conn->query($sql1) === TRUE) {
echo 'success';
} else {
echo "Error: " . $sql1 . "<br>" . $conn->error;
}
}
if i echo $name output is
{"0":{"0":"Stranger Things","1":2017}}
but after insert it's showing this in database
{"0":"Stranger Things","1":{"0":"Stranger Things","1":"2017"}}
what i am doing wrong here?
You placed echo to unnecessary variable somewhere in your code thats why it prints name 2 times.. check it properly and remove it.
{"0":"Stranger Things","1":{"0":"Stranger Things","1":"2017"}}
This is happening most probably due to $new[] = $add; when you are using Loop and passing some value inside $new[i].
In first Loop its proper {"0":"Stranger Things","1":2017}
Now in second loop when i will be 1.
So, in position of 1 , {"0":"Stranger Things","1":2017} this is getting inserted again and making final array as {"0":"Stranger Things","1":{"0":"Stranger Things","1":"2017"}}
Show the complete code as it is, to identify the error.
As per the code you have provided, output must be correct.
$email= "abc#gmail.com";
$watchshow="Stranger Things";
$yearshow= 2017;
$new=array();
$add=array();
array_push($add,$watchshow);
array_push($add,$yearshow);
$new[] = $add;
$add=array();
array_push($add,$watchshow);
array_push($add,$yearshow);
$new[] = $add;
echo $name = json_encode($new, true);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying for user login and registration forms in Android. From past 5 days, I am trying it. I am not able to get it. Can anyone help me please? This is my code user_control.php. I am including the connection.php in user_control.php.
<? php
class user {
private $db;
private $connection;
/* The below one is the consttructor*/
function __construct() {
header('Content-Type: application/json'); /* used for including json format*/
require_once 'connection.php';
$this->db = new DB_Connection();
$this->connection = $this->db->get_connection();
}
public function does_user_exist($email,$password) {
$query = "Select * from userss where email ='$email' and password = '$password'";
$result = mysqli_query($this->connection,$query);
if(mysqli_num_rows($result) > 0){
$json['success'] = 'welcome'.$email;
echo json_encode($json);
mysqli_close($this->connection);
} else {
$query = " Insert into userss(email,password) values ('$email','$password')";
$is_inserted = mysqli_query($this->connection, $query);
if($is_inserted == 1) {
$json['success'] = 'Account created, welcome '.$email;
} else {
$json['error'] = 'Wrong password';
}
echo json_encode($json);
mysqli_close($this->connection);
}
}
}
$user = new user();
if(isset($_POST['email'],$_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
if(!empty($email) && !empty($password)) {
$encrypted_password = md5($password);
$user -> does_user_exist($email,$encrypted_password);
} else {
echo json_encode("You must fill both fields");
}
}
While I am running with postman software by Chrome I am getting the error as I am getting syntax error:
unexpected 'header' (T_STRING) in http://localhost:80/opt/lampp/htdocs/user_control.php
Remove the space in your line 1. Should looks like:
<?php
Try to comment:
//header('Content-Type: application/json'); /* used for including json format*/
Source: https://stackoverflow.com/a/20620606/2381906
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I write this but it doesnt work, can`t find the error.
this server side code get the the variable $cpu & $display and use it in select from the data base. when the variable is not important "*" will be sent.
<?php
if (isset($_REQUEST['action']))
{
$action = $_REQUEST['action'];
}
else
{
echo "Invalid Data";
exit;
}
if ($action == "read")
{
readData();
}
function connectToDatabase()
{
$connection = mysqli_connect("localhost", "root", "", "project_pro");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
return $connection;
}
function readData()
{
$connection = connectToDatabase();
$cpu = $_REQUEST['cpu'];
$display = $_REQUEST['display'];
This is the part that problem exists:
$sql = "Select * From phones WHERE";
if ($cpu == "*")
{
}
else
{
$sql+= " phone_cpu='$cpu'";
}
if ($display == "*")
{
}
else
{
$sql+= " AND phone_display='$display'";
}
$output = array();
while ($row = mysqli_fetch_array($result))
{
$record = array();
$record['phone_id'] = $row['phone_id'];
$record['phone_cpu'] = $row['phone_cpu'];
$output[] = $record;
}
echo json_encode($output);
mysqli_close($connection);
}
The concatenation operator in PHP is . not +. So change += to .=.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have an error within this PHP else if statement (which is part of an if statement):
Parse error: syntax error, unexpected '}' in /home1/tony1964/public_html/2v2tournaments/action.php
The place where the unexpected '}' is at the end of the code below. I can't figure out why this doesn't work. Thanks in advance for any help.
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
include('php-riot-api.php');
$summoner_name_input = $_POST['summonername'];
$summoner_name = str_replace(' ', '_', $summoner_name_input);
$summoner_region = $_POST['summonerregion'];
$verify_code_input = $_POST['verify_code'];
$verify_code = str_replace(' ', '_', $verify_code_input);
$instance = new riotapi($summoner_region);
$grab_data = $instance->getSummonerByName($summoner_name);
$decode_data = json_decode($grab_data);
$grab_id = $decode_data->{'id'};
var_dump($grab_id);
$grab_runes = $instance->getSummoner($grab_id,'runes');
$decode_runes = json_decode($grab_runes);
$rune_check = $decode_runes->{'name'};
if ($rune_check = $verify_code) {
$logged_user = $_SESSION['logged_user'];
if (!($stmt = $con->prepare("INSERT INTO `verified_summoners` (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
die( "Error preparing: (" .$con->errno . ") " . $con->error);
}
$stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);
if($stmt->execute()) {
echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";
} else {
echo "Unsuccessful INSERT, Contact Support or Try again...";
}
$stmt->close();
}
} else {
echo "O Dear, It didn't work! Try Again!";
}
}
Formatting your code would answer your question for you.
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
include('php-riot-api.php');
$summoner_name_input = $_POST['summonername'];
$summoner_name = str_replace(' ', '_', $summoner_name_input);
$summoner_region = $_POST['summonerregion'];
$verify_code_input = $_POST['verify_code'];
$verify_code = str_replace(' ', '_', $verify_code_input);
$instance = new riotapi($summoner_region);
$grab_data = $instance->getSummonerByName($summoner_name);
$decode_data = json_decode($grab_data);
$grab_id = $decode_data->{'id'};
var_dump($grab_id);
$grab_runes = $instance->getSummoner($grab_id,'runes');
$decode_runes = json_decode($grab_runes);
$rune_check = $decode_runes->{'name'};
if ($rune_check = $verify_code) {
$logged_user = $_SESSION['logged_user'];
if (!($stmt = $con->prepare("INSERT INTO `verified_summoners` (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
die( "Error preparing: (" .$con->errno . ") " . $con->error);
}
$stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);
if($stmt->execute()) {
echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";
} else {
echo "Unsuccessful INSERT, Contact Support or Try again...";
}
$stmt->close();
} else {
echo "O Dear, It didn't work! Try Again!";
}
}
-
$stmt->close();
}
}
Should be
$stmt->close();
}