Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO (table) SET .....

Status
Not open for further replies.

MikeHayes85

Programmer
Nov 11, 2015
3
0
0
NL
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.
 
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
 
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.
 
Hi

Just the evident invitation for Bobby Tables.

Try to [tt]mysql_real_escape_string()[/tt] the data :
Code:
[navy]$book_number[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'book_number'[/green][/i][teal]]);[/teal]
[navy]$author_sn[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'author_sn'[/green][/i][teal]]);[/teal]
[navy]$author_fn[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'author_fn'[/green][/i][teal]]);[/teal]
[navy]$title[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'title'[/green][/i][teal]]);[/teal]
[navy]$price_e[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'price_e'[/green][/i][teal]]);[/teal]
[navy]$price_c[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'price_c'[/green][/i][teal]]);[/teal]
[navy]$image[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'image'[/green][/i][teal]]);[/teal]
[navy]$type[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'type'[/green][/i][teal]]);[/teal]
[navy]$conditi[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'conditi'[/green][/i][teal]]);[/teal]
[navy]$postage[/navy] [teal]=[/teal] [COLOR=orange]mysql_real_escape_string[/color][teal]([/teal][navy]$_GET[/navy][teal][[/teal][i][green]'postage'[/green][/i][teal]]);[/teal]

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


Feherke.
feherke.ga
 
And where exactly are you executing that query?

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



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.









----------------------------------
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
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top