I have the following code in a PHP file so I can Update some items from a database (I'm using webhost for the database)
<?php
include_once 'conexao.php';
$Name = $_GET['Name'];
$Type = $_GET['Type'];
$Size = $_GET['Size'];
$Quantity = $_GET['Quantity'];
$Cost = $_GET['Cost'];
$ID = $_GET['ID'];
$sql = "UPDATE MenClothDB SET Name = '$Name', Type = '$Type', Size = '$Size', Quantity = '$Quantity', Cost = '$Cost' WHERE ID = '$ID'";
if ($dbcon->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
?>
and if I try typing the whole url (for example, https://xxx.000webhost.com/UpdateCloth.php?Name=Example.....&ID=6) it works perfectly fine, the row gets updated. But when I try using that in App Inventor (code/blocks shown below) the Response Code is "400 Bad Request"
Related
Hi i am getting the problem of adding the record in to the database.when i insert the record into the database. message display record insert failed. i double checked the coding and programming syntax all were fine.but i didn't get any errors while was running what was the problem. can some one fix the problem do get the error. exception handing also i have put but unfortunate it doens't help for me to display the error.
<?php
if (isset($_POST['submit'])) {
$bassname = $_POST['bassname'];
$cat = $_POST['cat'];
$p_img1 = $_FILES['p_img1']['name'];
$p_img2 = $_FILES['p_img2']['name'];
$p_img3 = $_FILES['p_img3']['name'];
$temp_name1 = $_FILES['p_img1']['tmp_name'];
$temp_name2 = $_FILES['p_img2']['tmp_name'];
$temp_name3 = $_FILES['p_img3']['tmp_name'];
move_uploaded_file($temp_name1, "product_images/$p_img1");
move_uploaded_file($temp_name2, "product_images/$p_img2");
move_uploaded_file($temp_name3, "product_images/$p_img3");
$mobile = $_POST['mobile'];
$address = $_POST['address'];
$job_desc = $_POST['job_desc'];
$work_video = $_POST['work_video'];
$insert_product = "insert into
bass_registation(
bassname,
category,
job_image1,
job_image2,
job_image3,
mobile,
address,
job_des,
video
) values (
'$bassname',
'$cat',
'$p_img1',
'$p_img2',
'$p_img3',
'$mobile',
'$address',
'$job_desc',
'$work_video'
)";
$run_product = mysqli_query($con, $insert_product);
try {
if ($run_product) {
echo "<script>alert('Data has been inserted successfully')</script>";
} else {
echo "<script>alert('Data has been Failed')</script>";
}
}
catch (Exception $e) {
echo 'Message: ' . $e->getMessage();
}
}
?>
I keep getting a 'Resource id # 6' failure when submitting a script on my website. The code I'm using is the same type of code I use for registering for the website and that works but this script doesn't work at all. What my code does is send a booking request with the fields as shown to the database. I keep getting a Resource id#6 error , and I've googled what that is but I can't seem to figure out whats wrong. I am a beginner at php , so any tips on whats to look for to avoid a resource id # 6 error would be a lot of help
<?php
//$pattern="/^.+#.+/.com/";
//error_reporting(0);
if(isset($_POST["submit"])){
$Name_of_Person = $_POST['Name_of_Person'];
$Name_of_Group = $_POST['Name_of_Group'];
$room = $_POST['room'];
$How_Many_People = $_POST['How_Many_People'];
$Date_of_Booking = $_POST['Date_of_Booking'];
$End_time = $_POST['End_time'];
$Purpose = $_POST['Purpose'];
$Contact_Number = $_POST['Contact_Number'];
$Contact_Email = $_POST['Contact_Email'];
$Alcohol = $_POST['Alcohol'];
$Security = $_POST['Security'];
$Projector = $_POST['Projector'];
$Extra_Chairs = $_POST['Extra_Chairs'];
$Extra_Info = $_POST['Extra_Info'];
$Activated = '0';
$con = mysql_connect('localhost','root','test123') or die("couldn't connect");
mysql_select_db('bookerdb') or die("couldn't connect to DB");
//if(filter_var($email, FILTER_VALIDATE_EMAIL)){//(preg_match($pattern, $_POST['Contact_Email'])){
$query = mysql_query("SELECT * FROM `booking_table` WHERE Date_of_Booking='".$Date_of_Booking."' AND room='".$room."'");
$numrows = mysql_num_rows($query);
echo $query;
if($numrows==0){
$sql="INSERT INTO `booking_table` (Name_of_Person,Name_of_Group,room,How_Many_People,Date_of_Booking,End_time,Purpose,Contact_Number,Contact_Email,Alcohol,Security,Projector,Extra_Chairs,Extra_Info, Activated) VALUES ('$Name_of_Person','$Name_of_Group','$room','$How_Many_People','$Date_of_Booking','$End_time','$Purpose','$Contact_Number','$Alcohol','$Security','$Projector','$Extra_Chairs','$Extra_Info',$Activated)";
$result = mysql_query($sql);
if($result){
echo "Sent to be approved";
$redirect_page = '../ASC.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}else{
echo "Failed";
}
}else{
echo"There is already a requested booking on that date & time";
$redirect_page = '../EAR.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}
/*}else{
echo "error";
$redirect_page = '../EWF.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}*/
}
?>
You have error in your second SQL query. You try to insert 14 values into 15 columns (in values you forgot $Contact_Email).
$sql="INSERT INTO `booking_table` (Name_of_Person,Name_of_Group,room,How_Many_People,Date_of_Booking,End_time,Purpose,Contact_Number,Contact_Email,Alcohol,Security,Projector,Extra_Chairs,Extra_Info, Activated) VALUES ('$Name_of_Person','$Name_of_Group','$room','$How_Many_People','$Date_of_Booking','$End_time','$Purpose','$Contact_Number','$Contact_Email','$Alcohol','$Security','$Projector','$Extra_Chairs','$Extra_Info',$Activated)";
Than remove echo $query from your code, line 30.
In $query isn't query, but mysql result object. You can't work with that by this way, you can't echo it.
I couldn't find any error. I tried the query on phpmyadmin and it works well but when I do in php page, it couldn't update into DB. The following code below:
$registerID = ($_POST['registerID']);
$firstName = ucwords(htmlspecialchars($_POST['firstName']));
$lastName = ucwords(htmlspecialchars($_POST['lastName']));
$emailAddress = htmlspecialchars($_POST['emailAddress']);
$mainAddress = ucwords(htmlspecialchars($_POST['fullAddress']));
$updateCity = ucwords($_POST['userCity']);
$updateCountry = $_POST['userCountry'];
$postalCode = strtoupper(htmlspecialchars($_POST['userZip']));
$profilePic = $_POST['pic'];
$updateProf = " UPDATE register_user
SET firstName='$firstName',
lastName='$lastName',
emailAddress='$emailAddress',
mainAddress='$mainAddress',
registerCity='$updateCity',
registerCountry='$updateCountry',
postalCode='$postalCode'
WHERE registerID = '$registerID'";
if (mysqli_query($mysqli, $updateProf)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($mysqli);
}
In the end, there are no errors after I updated on the webpage, it just show Record updated successfully. But it didn't update into DB. Any ideas?
UPDATED CODING
$checkProfile = "SELECT * FROM register_user where emailAddress = '$emailAddress'";
$editProfile = mysqli_query($mysqli,$checkProfile);
if ($editProfile) {
if (mysqli_num_rows($editProfile) > 0) {
header("Location: event?error=That name of email has already been taken");
} else {
$updateQuery = "UPDATE register_user
SET firstName = '$firstName',
lastName = '$lastName',
emailAddress = '$emailAddress',
mainAddress = '$mainAddress',
registerCity = '$updateCity',
registerCountry = '$updateCountry',
postalCode = '$postalCode'
WHERE registerID = '$registerID'";
$updateResult = mysqli_query($mysqli,$updateQuery);
header("Location: profileUser");
}
}
After I updated, it still doesn't work after I am using prepared statement. Any ideas?
Try executing the query first, saving it into a variable.
then, check if the query executed by doing:
if(!$query) echo "Query error : " . $mysqli->error;
This will give you more detailed error report.
This code runs when a user hits a delete button on my form. I am trying to copy a file, $picfile, from "/pics/" to "/pics/deletedrecordpics/" and then delete the orginal. Finally, delete the record from the database. Deleting the record from the databse works, but copying the file and deleting the original does nothing. There are no errors in the error log, so I am really confused as to why this code isn't running as I think it should.
if ($allowdelete==true && $thepassword == $password)
{
//delete record that delete was set to by button
//$sql = ("DELETE FROM $table WHERE id=$id");
$sql = ("select picfile,title,author from $table where id=$delete");
$file=mysql_query($sql);
$resrow = mysql_fetch_row($file);
$picfile = $resrow[0];
$title = $resrow[1];
$author = $resrow[2];
if (file_exists("/pics".$picfile)){
copy("/pics/".$picfile,"/pics/deletedrecordpics/".$author."-".$title."-".$picfile);
unlink("/pics/".$picfile);
echo $available = "image is available.";
$sql = ("DELETE FROM $table WHERE id=$delete");
$result = mysql_query($sql);
if ($result){
echo "Your Picture has been removed from our system.";
Die($available);
}
else{
echo "There was an error in removing your picture.";
$Delete = "";
Die();
}
}
else{
echo $available = "image is not available.";
}
}
The weird part is a have almost the same code in a delete button on my control panel located in "/adminpanel" and it works perfectly. The code for that is the same except I use $id instead $delete and "../" before all the "pics/" because it's in the adminpanel folder. The permissions are right and the folder exists because the code works with that page. And I know $delete is getting set because the record gets deleted from the database. I know picfile, author and title are getting set because I appended them to the print statement and they were all right. Really confused. Any ideas?
Here is the code for the working page
q = ("select picfile,title,author from $table where id=$id");
$file=mysql_query($q);
$resrow = mysql_fetch_row($file);
$picfile = $resrow[0];
$title = $resrow[1];
$author = $resrow[2];
copy("../pics/".$picfile,"../pics/deletedrecordpics/".$author." - ".$title." - ".$picfile);
unlink("../pics/".$picfile);
$file=mysql_query($q);
$q = ("DELETE FROM $table WHERE id=$id");
$file=mysql_query($q);
why is this line repeated twice $file=mysql_query($q); ?
Try this
$file_path = $_SERVER["DOCUMENT_ROOT"]."/pics/";
if (file_exists($file_path.$picfile))
{
copy($file_path.$picfile, $file_path."/deletedrecordpics/".$author."-".$title."-".$picfile);
unlink($file_path.$picfile);
}
else
{
echo "File not found!!!!!!!!";
}
I am trying to set a session variable after first successful insert query. I have a javascript Confirm to check if the user wants to add more data. If user wants to add more Products then I don't have to insert into the first table so keep the session value. If not then clear out the session data. I am not sure this is is right way of doing it. Could you please let me know if there are any suggestions.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
session_start();
if (empty($_SESSION['new_id']))
{
$first = $_POST["first"];
$first = mysql_real_escape_string($first);
$last = $_POST["last"];
$last = mysql_real_escape_string($last);
$insertsql = "INSERT INTO Table1(FirstName,LastName) VALUES ('".$first."', '" .$last. "')";
$result1 = mysql_query($insertsql) or die(mysql_error());
$new_id = MySql_Insert_Id();
$_SESSION['new_id'] = $new_id;
}
$prodName = $_POST["prodName"];
$prodName = mysql_real_escape_string($prodName);
$prod_details = $_POST["prod_details"];
$prod_details = mysql_real_escape_string($prod_details);
$insertSQl2 = "INSERT INTO Table2($_SESSION['new_id'], Product_Name, Product_Details) VALUES ('".$new_id."', '" .$prodName. "', '" .$prod_details. "')";
$Result2 = mysql_query($insertSQl2) or die(mysql_error());
}
?>
<form>
//controls here
</form>
<?php
if($Result2 == true)
{
echo "Data saved Successfully";
echo '<script type="text/javascript">' , 'if confirm("Would like to add more Products?") ' , '</script>';
}
?>