0

Currently, I am working on PHP to make an online shop.

I have my order table.

<?php
  $itemno = $_POST['itemno'];
  $qty = $_POST['qty'];
  $price = $_POST['price'];
  $orderno = rand(0,100);
  $firstname =  $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $streetaddress= $_POST['streetaddress'];
  $city = $_POST['city'];
  $state = $_POST['state'];
  $postcode2 = $_POST['postcode2'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];

  $dat=date("Y-m-d");

  include_once('config.php');
  $save_items = mysql_query("INSERT INTO orders (itemno,qty,price,orderno,firstname,lastname,streetaddress,city,state,postcode2,email,phone,dat)VALUES('$itemno','$qty','$price','$orderno','$firstname','$lastname','$streetaddress','$city','$state','$postcode2','$email','$phone','$dat')");

        if($save_items){
            echo '1';
        }else{
            echo '0';
        }
?>

Two things I need help:

  • I want to access the latest date order in top in order view page. Here is my mysql "select * from orders ORDER BY dat ". What change i should do so i get access the latest date order.

  • I got error in Phone number it comes like this "2147483647".

6
  • I got error in Phone number it comes like this "2147483647". What is the error? Commented May 19, 2016 at 9:47
  • @luweiqi i got this number 2147483647 in every order table of every phone number. Commented May 19, 2016 at 9:49
  • 1. ... ORDER BY dat DESC; 2. What's your expected output for phone number? Commented May 19, 2016 at 9:49
  • @RajdeepPaul the phone number which will post by customer . Commented May 19, 2016 at 9:50
  • Do echo $phone; before executing the query and see what output you're getting. Commented May 19, 2016 at 9:52

1 Answer 1

2

1) I want to access the latest date order in top in order view page. Here is my mysql "select * from orders ORDER BY dat ". What change i should do so i get access the latest date order.

You can order by id of table:

"select * from orders ORDER BY id DESC" -and this you will get latest order first

2) I got error in Phone number it comes like this "2147483647" .

Remove single quotes from $phone if it is integer column

$save_items = mysql_query("INSERT INTO orders (itemno,qty,price,orderno,firstname,lastname,streetaddress,city,state,postcode2,email,phone,dat)VALUES('$itemno','$qty','$price','$orderno','$firstname','$lastname','$streetaddress','$city','$state','$postcode2','$email',$phone,'$dat')");
Sign up to request clarification or add additional context in comments.

2 Comments

That ORDER by id is working... but Phone number is not coming.. any other solution.
Now its working.. I have changed the Phone number fron integer to varchar(20) ..Its all right now..Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.