-2

hello actually i have this problem .. this is my second time im doing system. ok now like my title .. so how im going to solve this problem? i have give my time about 2 days for this problem. this is my 1st time i see this problem.. last time everything is ok.. help me please

<?php
include ("config.php");

//select variable db         
if (isset($_POST["Submit"])) {

    $nama = $_POST["nama"];
    $add = $_POST["add"];
    $no_hp = $_POST["no_hp"];

    mysql_connect("localhost","root","");
    mysql_select_db("shimacookies");


    $s ="INSERT into cuporder(nama,no_hp,add) VALUES('".$nama."','".$no_hp."','".$add."')";
    if (mysql_query($s))
        echo "<b>Succesfully Save !!</b>";
    else
        echo mysql_error();
}

?>
frasertweedale
  • 5,424
  • 3
  • 26
  • 38

2 Answers2

3

Seeing that the other answer given has not signaled the use of the MySQL reserved word add, nor has the OP picked up on the duplicate question, have decided to re-open the question in order to show them, what is happening here.

You see the word "add" here in your query?

$s ="INSERT into cuporder(nama,no_hp,add) ...
                                     ^^^
  • "ADD/add" is a MySQL "reserved" word and it requires special attention, meaning that you MUST wrap that column in ticks.

I.e.: (and copy/paste exactly as shown. Ticks ` and quotes ' are 2 different animals altogether.

$s ="INSERT into cuporder(nama,no_hp,`add`) ...

The error you left in a comment under the other answer told you where it starts:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add) VALUES('','','')' at line 1

Notice near 'add)? There you go; that's where the biggest problem begins.

Or rename that column to something "other" than a reserved word.


Plus, you're open to an SQL injection. Use a prepared statement:

Plus, your POST arrays failed. You need to make sure your form has a POST method and that all elements hold the name attribute for them.

I.e.:

<form method="post" action="your_handler.php">
  <input type="text" name="nama">
  <input type="text" name="add">
  <input type="text" name="no_hp">
  <input type="submit" name="Submit">
</form>

Use error reporting.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.

If you're using your entire code (HTML form/PHP/SQL), then if you're not checking to see if they are "not empty", then that could be another reason why they are empty.

Also consult http://php.net/manual/en/tutorial.forms.php


Footnotes:

Reference for "ADD":

Example pulled from it:

If you want to add to a tableA a column existing in a tableB:

1) Create an empty column in the tableA:

ALTER TABLE tableA ADD color CHAR(20);

2) If you don't have an auto-incrementation in the two tables (tableB for exemple):

ALTER TABLE tableB ADD (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id));

3) Fill the columns with the values:

UPDATE tableA,tableB SET tableA.color=tableB.color WHERE tableA.id=tableB.id;
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
-2

Try it with this query:

$s ="INSERT into cuporder(nama,no_hp,add) VALUES('$nama','$no_hp','$add')"; 
Oldskool
  • 34,211
  • 7
  • 53
  • 66
origenes
  • 27
  • 2
  • 1
    `'".$poh-tay-toe."'` - `'$poh-tah-toe'` – Funk Forty Niner Nov 11 '15 at 01:24
  • i try already use that query but the error still the same,, my query is ok but is there have the problem with the version of my sql? "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add) VALUES('','','')' at line 1" this is the error that shows.. – Arif Tahir Nov 11 '15 at 15:55
  • variables seems to be empty. did you "echo" $s to see the query that mysql tries to execute? – origenes Nov 11 '15 at 17:25