473,659 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to add new record to database

Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com","drt spo_tedted","or eo8157")))
die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSERT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted
Nov 17 '08 #1
6 2160
yes.

die(mysql_error ());
Nov 17 '08 #2
te*******@gmail .com wrote:
Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com","drt spo_tedted","or eo8157")))
die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSERT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted
My approach is this (usually for more complex queries than that):

1 - Have a side window open and running phpMyAdmin on that database
2 - Put a print statement to print out $sql
3 - Try running that $sql in the sql tab of phpMyAdmin.

That tells me right away what any error is and playing around with the
query in phpMyAdmin to get it to work is usually much faster than first
modifying the php code.

BTW, make sure the "die"s are removed when you go live. Instead, use
ifs and set messages but keep the app moving.

My guess is that either you don't have field in table orders call fname
or you do not have privilege to write to the database. Just for kicks,
try this:

if (!($results=mys ql_query($sql,$ dblink)))

Finally, you don't really need those back-ticks.
Nov 18 '08 #3
te*******@gmail .com wrote:
Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com","drt spo_tedted","or eo8157"
)))
die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSERT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted
Could the issue be that you're using a statement that won't return a
result set with a query statement? In PHP is there an execute() or
update() function that should be used instead?

--
George Sexton
MH Software, Inc. - Home of Connect Daily Web Calendar
http://www.mhsoftware.com/connectdaily.htm
Nov 18 '08 #4
George Sexton wrote:
te*******@gmail .com wrote:
>Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com","dr tspo_tedted","o reo8157"

)))
> die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSERT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted

Could the issue be that you're using a statement that won't return a
result set with a query statement? In PHP is there an execute() or
update() function that should be used instead?
No. mysql_query() always returns non-false for a request which works,
and false for a failure.

Macca's answer is correct - he needs to use mysql_error() to determine
what the error is.

And Sheldon is correct - you should almost never use die() in production
code. Handle the error and complete your script's processing.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 18 '08 #5
Jerry Stuckle wrote:
George Sexton wrote:
>te*******@gmail .com wrote:
>>Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com","d rtspo_tedted"," oreo8157"

)))
>> die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSER T INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted

Could the issue be that you're using a statement that won't return a
result set with a query statement? In PHP is there an execute() or
update() function that should be used instead?

No. mysql_query() always returns non-false for a request which works,
and false for a failure.
Ummmmm. Technically, you are correct in saying "non-false" -- but that
statement can be confusing to a newbie. On failure, mysql_query always
returns false. On success, a delete, insert or update returns true,
while a select returns a resource. IOW, if it is something to further
process, it returns a resource.

>
Macca's answer is correct - he needs to use mysql_error() to determine
what the error is.

And Sheldon is correct - you should almost never use die() in production
code. Handle the error and complete your script's processing.
Nov 18 '08 #6
sheldonlg wrote:
Jerry Stuckle wrote:
>George Sexton wrote:
>>te*******@gmail .com wrote:
Hi,
I have the following code
<?php
//DatabaseConnect ();
if (!($dblink = mysql_connect(" drt-
sport.com"," drtspo_tedted", "oreo8157"

)))
die(" could not connect to mysal");

if (!$dbconn = mysql_select_db ("drtspo_zc1",$ dblink))
die(" Could not connect to databse ");

$sql="INSE RT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysq l_query($sql,$d blink))
die("<brcould not query database");

print("new item inserted");
?>

The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????

-Ted

Could the issue be that you're using a statement that won't return a
result set with a query statement? In PHP is there an execute() or
update() function that should be used instead?

No. mysql_query() always returns non-false for a request which works,
and false for a failure.

Ummmmm. Technically, you are correct in saying "non-false" -- but that
statement can be confusing to a newbie. On failure, mysql_query always
returns false. On success, a delete, insert or update returns true,
while a select returns a resource. IOW, if it is something to further
process, it returns a resource.

Which is why I said "non-false" instead of "true".
>>
Macca's answer is correct - he needs to use mysql_error() to determine
what the error is.

And Sheldon is correct - you should almost never use die() in
production code. Handle the error and complete your script's processing.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 18 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3575
by: HolaGoogle | last post by:
hi all, can you please tell me what i should do to avoid session timeout when displaying my database info in my asp form (DisplayUserDatabase.asp)??? ** actualy it does load and display the database randomly....otherwise it's always runs into a session time out.... **Also when i save new account info (You'll notice that i've been asked to put a save button near each record...so, it's not one global save it's by record), i'd like to be...
1
9476
by: RayP | last post by:
I'd appreciate some help I'm having trying to run a cursor. First, some background. The Status field of all records on Table A needs changing from 1 to 0 where there is no corresponding record on Table B. For each record that is changed the PWE, Staff Number and Status needs to be output to the screen. I have successfully run the SELECT statement but can't output anything to the screen. I've tried outputting the value of the table...
5
1721
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold Fusion script to upload the cleaned up files and then import the records they contained into the database, though obviously, the process took friggin' forever, and could have been done 500x quicker had I done it directly on the server. My SQL...
0
2724
by: Frances | last post by:
Hi All, I'm having a problem trying to add a record to a simple Access 2000 db (db is very similar to an address book but with more info than the usual address, phone, etc.). The database is one table, 36 fields. The record_id field is an autonumber field (long int) and primary key. The rest of the fields comprise of 30 text fields, 3 memo fields, 1 date field and 1 currency field. Text fields vary in number of characters allowed. ...
6
5660
by: DebbieG | last post by:
I have created a database for a client and was told that it was to be a one-user database. Well, you know the next statement ... now they want 3 people to be able to use the database. (FYI, I have never created a database for multiusers. I've done some searching but not finding what I want.) I have split the database. In Tools, Options, I have set the following: Default open mode = Shared Default record locking = Edited Record
2
1349
by: Wayne | last post by:
This is a copy of a message I previously posted in a Microsoft Access Newsgroup, but it was suggested to me that my problem is ASP related and not Access, and hence I'm posting in this newsgroup now instead. Hi everyone, I've got quite a specific query that I'm trying to resolve with Microsoft Access and I'm hopeful someone out there can offer a solution to my problem. I have records that I'm displaying on a web page from an Access...
7
1278
by: lmnorms1 | last post by:
Hello, I am trying to update an access database record date field that matches a specific date. The code is not working. Anyone have any advice? Here is the code: Dim gConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Customer development\VBNET\CSFV\CSFV.mdb;" Dim Conn As New OleDbConnection(gConnString) 'Actual Connection to database. Conn.Open()
12
1818
by: TS | last post by:
If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference? if an exception, i would imagine i should catch this and display a message to the user? thanks
0
1501
by: rmcpherson | last post by:
Can someone please help with this problem? I'm trying to go to the last record, make a new record, and save it the database. It just gives me "OleDbException was unhandled" error at da.Update(ds, "Phone") line. Thanks in advance. Public Class PhoneReport Inherits System.Windows.Forms.Form Dim inc As Integer Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As...
1
4020
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.