INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

INSERT INTO (table) SET .....

INSERT INTO (table) SET .....

(OP)
Just created a db with no problems but I cant insert any data. This code is not inserting into my db and I cannot find the reason.
No errors messages are received. The connect info, password, name, etc., is all correct.
I have tried other syntax versions but to no avail.
$sql = "
INSERT INTO books
SET
book_number = '$book_number',
author_sn = '$author_sn',
author_fn = '$author_fn',
title = '$title',
price_e = '$price_e',
price_c = '$price_c',
type = '$type',
image = '$image',
conditi = '$conditi',
postage = '$postage'";

Thanks.

RE: INSERT INTO (table) SET .....

Hi

I am pretty sure the problem is in the unposted part of your code. Because what you posted, worked fine for me in MySQL 5.6.27.

By the way, that is executed from PHP, right ? If so, using which module ( mysql, mysqli, PDO ) ? Are you sure errors are not suppressed ?

Feherke.
feherke.ga

RE: INSERT INTO (table) SET .....

(OP)
Thanks for the reply. I'm using MySql.
Here's the complete module.
<?php

include("sales_includes/db.inc.php");

include("sales_includes/misc.inc");

$connection = mysql_connect($host,$user,$password)
or die ("No connection");

$db = mysql_select_db($database,$connection)
or die ("No selection");

//********************************************************************
// New book
//********************************************************************
$book_number = $_GET['book_number'];
$author_sn = $_GET['author_sn'];
$author_fn = $_GET['author_fn'];
$title = $_GET['title'];
$price_e = $_GET['price_e'];
$price_c = $_GET['price_c'];
$image = $_GET['image'];
$type = $_GET['type'];
$conditi = $_GET['conditi'];
$postage = $_GET['postage'];

//********************************************************************
// Update books database
//********************************************************************

$sql = "
INSERT INTO books
SET
book_number = '$book_number',
author_sn = '$author_sn',
author_fn = '$author_fn',
title = '$title',
price_e = '$price_e',
price_c = '$price_c',
type = '$type',
image = '$image',
conditi = '$conditi',
postage = '$postage'";
echo here, $test;

include 'list_books_input.html.php';
exit();

?>

Hope you see something here. Thanks.

RE: INSERT INTO (table) SET .....

Hi

Just the evident invitation for Bobby Tables.

Try to mysql_real_escape_string() the data :

CODE --> PHP ( fragment )

$book_number = mysql_real_escape_string($_GET['book_number']);
$author_sn = mysql_real_escape_string($_GET['author_sn']);
$author_fn = mysql_real_escape_string($_GET['author_fn']);
$title = mysql_real_escape_string($_GET['title']);
$price_e = mysql_real_escape_string($_GET['price_e']);
$price_c = mysql_real_escape_string($_GET['price_c']);
$image = mysql_real_escape_string($_GET['image']);
$type = mysql_real_escape_string($_GET['type']);
$conditi = mysql_real_escape_string($_GET['conditi']);
$postage = mysql_real_escape_string($_GET['postage']); 

If still no works, replace echo here, $test; with echo 'here', $sql; and try to execute the outputted SQL statement "manually" in the mysql command-line tool, PHPMyAdmin or some other database management tool.

Feherke.
feherke.ga

RE: INSERT INTO (table) SET .....

And where exactly are you executing that query?

Nowhere in that code can I see you calling mysql_query() to actually run the query.

http://php.net/manual/en/function.mysql-query.php


Also note, that the original mysql API has been deprecated, and will stop being available in future versions of PHP. Try using mysqli or PDO instead.

http://php.net/manual/en/book.mysqli.php

http://php.net/manual/en/set.mysqlinfo.php







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: INSERT INTO (table) SET .....

(OP)
Hi all. Many thenks for all the help and suggestions but the problem was at the providers end. There system allowed me to connect but not to update. Solved now but what a bummer.
Btw the coding as I wrote works.
Thanks again. Mike

RE: INSERT INTO (table) SET .....

This situation illustrates a good reason to troubleshoot queries through a MySQL client like phpmyadmin, direct interface, etc (without first assuming it is your PHP). You would have likely seen the specific MySQL error describing the cause.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close