Android post values to MySQL with PHP [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I work on an Android project, in which I use AsyncTask to send nameValuePairs to webservice.
I use PHP code below to send data from application to database:
<?php
require_once('dbConnect.php');
$studentid = $_POST['name'];
$classid = $_POST['classid']
$studentid = $_POST['studentid'];
$start = $_POST['start'];
$end = $_POST['end'];
$startsig = $_POST['startsig'];
$endsig = $_POST['endsig'];
$sql = "insert into signature (studentid,classid,start,end,startsig,endsig) values ('$studentid','$classid','$start','$end','$startsig','$endsig')";
if(mysqli_query($con,$sql)){
echo 'success';
}
else{
echo 'failure';
}
mysqli_close($con);
?>
Values in dbConnect.php file are correct. Database schema looks like this.
I checked, application sends out data successfully, but when I try to access PHP file above from browser I get a HTTP 500 error.
What else should I check in this case?

There are two problems I noticed in your code you didn't put a semicolon after
$classid = $_POST['classid']
And also why are you assigning two different post values to same phpvariable $studentid = $_POST['name']; and $studentid = $_POST['studentid'];.Anyways $studentid will have the last assigned value $_POST['studentid']
Try debugging for more errors

Related

cannot insert into localhost(mysql) database using php [duplicate]

This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 3 years ago.
I can't insert the registration form data into my localhost database.
I am using xampp server, running mysql 5, php 7 and apache2. I've provided the code that can insert the form data into the database. The database is connected. I have also restarted the xampp server but it shows the same problem.
<?php
$active='Account';
include("includes/header.php");
?>
//html form with correct name values
<?php
if(isset($_POST['register'])){
$c_name = $_POST['c_name'];
$c_email = $_POST['c_email'];
$c_pass = $_POST['c_pass'];
$c_country = $_POST['c_country'];
$c_city = $_POST['c_city'];
$c_contact = $_POST['c_contact'];
$c_address = $_POST['c_address'];
$c_image = $_FILES['c_image']['name'];
$c_image_tmp = $_FILES['c_image']['tmp_name'];
move_uploaded_file($c_image_tmp,"customer/customer_images/$c_image");
$insert_customer = "insert into customers (customer_name,customer_email,customer_pass,customer_country,customer_city,customer_contact,customer_address,customer_image,customer_ip) values ('$c_name','$c_email','$c_pass','$c_country','$c_city','$c_contact','$c_address','$c_image','$c_ip')";
$result = mysqli_query($con,$insert_customer);
$sel_cart = "select * from cart where ip_add='$c_ip'";
$run_cart = mysqli_query($con,$sel_cart);
$check_cart = mysqli_num_rows($run_cart);
if($check_cart>0){
$_SESSION['customer_email']=$c_email;
echo "<script>alert('User is already present');</script>";
echo "<script>window.open('checkout.php','_self')</script>";
}else{
$_SESSION['customer_email']=$c_email;
echo "<script>alert('You have been Registered Sucessfully')</script>";
echo "<script>window.open('index.php','_self')</script>";
}
}
?>
The data should be inserted into the db when I refresh the phpmyadmin page.
Check $con variable where you define. Connection variable should be define on page and call with mysqli function.
$result = mysqli_query($con,$insert_customer);

Insert data to maria db using php [duplicate]

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
How can I prevent SQL injection in PHP?
(27 answers)
Closed 4 years ago.
Having trouble getting the data to insert into Maria DB. While attempting this project I have used about every source I can think of and I'm resorting to posting a question online. Below is my code and the error it produces is "Fatal error: Call to undefined method mysqli::mysqli_prepare() in C:\xampp\htdocs\scripts\insert.php on line 12". Been mulling over this for a couple days and so far I have found nothing at all on youtube or stackoverflow.
<?php
//Set up credentials
$servername = "localhost";
$username = "root";
$password = "";
$database = "test";
$db = new PDO("mysql:host=localhost;dbname=test;","$username","$password");
// Create connection
$link = new mysqli($servername,$username,$password,$database) or die($mysqli->error);
$a = $_POST["a"];
$sql = "INSERT INTO ass (asdf) VALUES('$a')";
$result = $link->mysqli_prepare($sql);
$stmt = $database->mysqli_prepare($sql);
$stmt->execute(array($_POST['a']));
$stmt->close();
?>

What is the proper way to find an 'internal server error 500' in php? [duplicate]

This question already has answers here:
How do I get PHP errors to display?
(27 answers)
Closed 5 years ago.
I am continuously having this internal server error to a very simple php code working with JSON. The values I am logging from the code is absolutely correct, yet when in action I am getting an internal server error 500 from this particular code. I had a similar code working previously. What am I doing wrong? or how should I proceed with debugging the error?
<?php
$var2 = $_POST['phn'];
$phone_received = json_decode($var2);
$adb = PearDatabase::getInstance();
$query1 = "SELECT addressid FROM address WHERE mobile = ?";
$leadID = $adb->pquery($query1, array($phone_received));
$row= $adb->num_rows($leadID);
if ($row != 0) {
$result = 'This number has already been used in the system.';
echo json_encode($result);
}else{
$result = 'Good to go!';
echo json_encode($result);
}
?>
Did you try to add true parameter to your json_decode call? I suppose the problem is with the $phone_received param. I also suggest you line by line debugging: try to retrun some dummy result after each line of code step by step so you can detect the place where the error occurs.

Can't execute PHP Mysql query, doesn't even open the page [duplicate]

This question already has answers here:
How do I get PHP errors to display?
(27 answers)
Closed 6 years ago.
So, I have some bug in this code that will not execute the query, it just says The localhost page isn’t working - localhost is currently unable to handle this request. And that error shows only when there's some bug in the code, so it won't execute it. I don't know what's the problem here, as I tried to connect to database and that's all ok. Problem lies in lines underneath the connect.php.
if($_POST) {
include('connection.php');
$id_broj = $_POST['id_num'];
$password = $_POST['password'];
$query=mysqli_query("SELECT id,id_broj,ime,prezime FROM zaposleni");
$result=mysqli_query($conn,$query);
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
echo 'Passed';
}
Need to write only query in $query Variable as:
if($_POST) {
include('connection.php');
$id_broj = $_POST['id_num'];
$password = $_POST['password'];
$query="SELECT id,id_broj,ime,prezime FROM zaposleni";
$result=mysqli_query($conn,$query);
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
echo 'Passed';
}

Insert form data into database glitch [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Alright so I am currently trying to make a system to take applications and it was working until I added the rest of the questions :
<?php
include_once('db.php');
$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']
if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('$user','$job','$active','$why','$le','$skype')"))
echo"successfully inserted";
else
echo "failed";
?>
But when I have it like that I get this error
Parse error: syntax error, unexpected '$le' (T_VARIABLE) in C:\xampp\htdocs\app_insert.php on line 8
Keep in mind I am using xampp with Apache and Mysql, anyone know whats happening?
You missed out the semi-colon, ; for:
$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']
It should be:
$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype'];
You are missing the semi-colon and the insert SQL statement seems incorrect. You are passing the string to SQL statements instead of the value
<?php
include_once('db.php');
$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype']
if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('{$user}','{$job}','{$active}','{$why}','{$le}','{$skype}')"))
echo"successfully inserted";
else
echo "failed";
?>

Categories