Jump to content

Input differs from output?


eduard

Recommended Posts

An integer is a number without decimal points: 5, -12, 4002.A "sign" is a plus or minus (+ or -). If an integer is "unsigned" it will not have a "sign" so there won't be negative numbers because there is no minus.An unsigned integer is an integer that can only have positive values. This is useful if you're expecting to have really large numbers, because signed integers only use half the range for positive numbers, the other half of the range is used for the negative numbers.
Thank you very much for your clearly explanation!
Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Well, I guess you could use a loop, if it makes whatever you're trying to do easier. Ask a vague question, get a vague answer. I'm trying to get you to ask specific questions to demonstrate that you understand what you're asking about.

Link to comment
Share on other sites

Well, I guess you could use a loop, if it makes whatever you're trying to do easier. Ask a vague question, get a vague answer. I'm trying to get you to ask specific questions to demonstrate that you understand what you're asking about.
So, if I ask specific questions I don´t need a loop?
Link to comment
Share on other sites

Now that the serial number is set up as a unique key in the database (it may be better to make it a primary key instead of just unique), then all you need to do is add the serial number to the insert query. You submit the serial number from the form but you don't do anything with it in PHP, it's not in the insert query.That's the first step. The second step is to do error checking. With the serial number being unique, if you try to insert one that already exists you'll get a MySQL error. Since you don't want your users to see MySQL errors, before you insert the new record you need to look up the serial number to see if it already exists and then show a message if it does instead of trying to add it.Do the first step first. Add the serial number to the query and verify that you can type any number into the serial number field and it will show what you added. After that works, move to the second step and do your duplicate check before the insert. Once the duplicate check works, then the next step is to validate the data. Since the serial number field in your database is an unsigned integer, you need to make sure that the serial number that was submitted is a positive number. It can't contain any characters other than numbers.
Do you mean like this:?$sql = "CREATE TABLE Persons (personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID),FirstName varchar(15),LastName varchar(15),Age int)";mysql_query($sql,$con);Do I have to create a new table?
Link to comment
Share on other sites

So, if I ask specific questions I don´t need a loop?
If you ask a question about a specific part, then I can help you figure out if you need a loop for that part or not.
Do I have to create a new table?
No, you can set a primary key on an existing table. Use the other topic you started for primary keys, keep this topic about the issue you started with in the first post.
Link to comment
Share on other sites

If you ask a question about a specific part, then I can help you figure out if you need a loop for that part or not.No, you can set a primary key on an existing table. Use the other topic you started for primary keys, keep this topic about the issue you started with in the first post.
Ok. thanks!
Link to comment
Share on other sites

I changed my code, but still it isn´t allright!<html><body><?php$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con){die('Could not connect: ' . mysql_error());}$description = $_POST["description"];$price = $_POST["price"];$quantity = $_POST["quantity"];mysql_select_db("eduardli_company", $con) or die(mysql_error());mysql_query ("INSERT INTO Products (serialno. description, price, quantity) VALUES ('$serialno', $description', '$price', '$quantity')") or die(mysql_error());$latest="select * from Products order by serialno desc limit 0,1";$result = mysql_query($latest,$con) or die(mysql_error());$row = mysql_fetch_array($result);{echo $row['serialno'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];echo "<br />";}mysql_close($con);?></body></html>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 '', '3', '4')' at line 2

Link to comment
Share on other sites

Do you mean like this:?$sql = "CREATE TABLE Persons (personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID),FirstName varchar(15),LastName varchar(15),Age int)";mysql_query($sql,$con);Do I have to create a new table?
Altough I haven´t to create a new table, do I need to use a code like this?
Link to comment
Share on other sites

you would if the table didn't exist yet. once it exists, there's no reason to have that code execute anymore. typically that's why the database and tables are designed in something like phpMyAdmin, and then the scripts just worry about INSERT/UPDATE/etc.why aren't you trying to fix your code as JSG suggested? I know we've told you this before, but you need to be more specific about your problems when you present code back to the forum. You can't just keep saying "it doesn't work". What exactly about it doesn't work? What should it be doing instead? You need to provide details and context.

Link to comment
Share on other sites

Also this message I don´t understand!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 '', '3', '4')' at line 2

Link to comment
Share on other sites

Also this message I don´t understand!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 '', '3', '4')' at line 2
Check your query, character by character, letter by letter, and you will find the mistakes.
Link to comment
Share on other sites

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 '', '3', '4')' at line 2
Error messages like that generally mean that either there is a problem with the first character it's showing you, or that there's a problem right before that. In that case it's showing you that this is the problem:', '3', '4')So the problem is either that first quote, or something that is before that. Look at your INSERT query where that type of thing would be, and look at what's before that part. This is where your insert query is:
mysql_query ("INSERT INTO Products (serialno. description, price, quantity) VALUES ('$serialno', $description', '$price', '$quantity')") or die(mysql_error());

Link to comment
Share on other sites

Error messages like that generally mean that either there is a problem with the first character it's showing you, or that there's a problem right before that. In that case it's showing you that this is the problem:', '3', '4')So the problem is either that first quote, or something that is before that. Look at your INSERT query where that type of thing would be, and look at what's before that part. This is where your insert query is:
mysql_query ("INSERT INTO Products (serialno. description, price, quantity) VALUES ('$serialno', $description', '$price', '$quantity')") or die(mysql_error());

Your replies are constructive! Unfortunately there are many forum members who think that the only thing I´m doing is eating out of my nose! Does this mean when I solve this (little) problem I finally get what I want (Input=output)?
Link to comment
Share on other sites

My insert.php is ok, but I still get an error message:Column count doesn't match value count at row 1How do I solve this problem?

Link to comment
Share on other sites

I get another time this message:Column count doesn't match value count at row 1So I suggest firt the code must be perfect and then phpMyAdmin must be perfect!

Link to comment
Share on other sites

It means that the amount of values you're inserting is not the same as the amount of fields you're inserting to. Check your SQL query to see what might be causing it. If you look closely you should see it.

Link to comment
Share on other sites

I am really fed up with this problem which I´m trying to solve for a long time!First, Is my question clear? (get the latest result of the data I insert of my html form of my website www.eduardlid.com?)How about the code of my insert.php?<html><body><?php$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con){die('Could not connect: ' . mysql_error());}$serial_no = $_POST["serial_no"];$description = $_POST["description"];$price = $_POST["price"];$quantity = $_POST["quantity"];mysql_select_db("eduardli_company", $con) or die(mysql_error());mysql_query ("INSERT INTO Products (serial_no. description, price, quantity) VALUES ('$serial_no', '$description', '$price', '$quantity')") or die(mysql_error());$latest="select * from Products order by serialno desc limit 0,1";$result = mysql_query($latest,$con) or die(mysql_error());$row = mysql_fetch_array($result);{echo $row['serialno'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];echo "<br />";}mysql_close($con);?></body></html>How about my database? (phpMyAdmin)-- phpMyAdmin SQL Dump-- version 3.3.10.2-- http://www.phpmyadmin.net---- Host: localhost-- Generation Time: Jul 23, 2011 at 07:17 PM-- Server version: 5.0.92-- PHP Version: 5.2.6SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;---- Database: `eduardli_company`---- ------------------------------------------------------------ Table structure for table `Products`--CREATE TABLE IF NOT EXISTS `Products` ( `serial_no` int(11) unsigned NOT NULL, `description` text NOT NULL, `price` int(11) NOT NULL, `quantity` int(11) NOT NULL, PRIMARY KEY (`serial_no`), UNIQUE KEY `serialno` (`serial_no`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `Products`--

Link to comment
Share on other sites

This query has a mistake and it shouldn't be hard to find.

mysql_query ("INSERT INTO Products (serial_no. description, price, quantity)VALUES ('$serial_no', '$description', '$price', '$quantity')") or die(mysql_error());

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...