Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Why doesn't my php script insert to sql table?

Reply  
Thread Tools
ajrobson's Avatar
Member with 254 posts.
 
Join Date: Aug 2006
01-Sep-2010, 02:19 PM #1
Why doesn't my php script insert to sql table?
PHP Code:
<?php
$con 
mysql_connect("localhost","Username","password");

if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
else
{
echo 
"connected";
mysql_select_db("MyDbName"$con);

mysql_query("INSERT INTO `MyDbName`.`Users`(Email, UserName, Password, DateJoined)
VALUES ('h', 'h', 'h', '2010-08-31')"
);

echo 
"a record added";
}
mysql_close($con);
echo 
"connection closed";
?>
If I go to the .php page on my website I just get a page saying connected a record added connection closed. So it is getting to the echo commands which I would expect it to do if it was working correctly. Nothing is put into my table but if I run the SQL query using php my admin an entry is correctly placed into my table.

Can anybody see what I have done wrong?
ajrobson's Avatar
Member with 254 posts.
 
Join Date: Aug 2006
01-Sep-2010, 03:24 PM #2
I've added more echo statements to get an output this is what my php scrpt looks like now:

PHP Code:
<?php
$con 
mysql_connect("localhost","Username","Password");
echo 
"con = ";
echo 
$con;

if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
else
{

$db mysql_select_db("MyDb"$con);
echo 
"<P>";
echo 
"db = ";
echo 
$db;

$mysql_query = ("INSERT INTO `MyDb`.`Users` (Email, UserName, Password, DateJoined) VALUES (g, g, g, 2010-08-31)");

echo 
"<P>";
echo 
"mysql = ";
echo 
$mysql_query;
}
mysql_close($con);
echo 
"connection closed";
?>
This is the output I get on the php page:

con = Resource id #1
db =

mysql = INSERT INTO `MyDb`.`Users` (Email, UserName, Password, DateJoined) VALUES (g, g, g, 2010-08-31)connection closed


When I use my php admin theres an option to create php code that gives

$sql = "INSERT INTO MyDb`.`Users` (`Email`, `UserName`, `Password`, `DateJoined`) VALUES (\'sd\', \'sd\', \'sd\', \'2010-09-22\');";

putting that into my php script doesn't work though.

Last edited by ajrobson; 01-Sep-2010 at 04:01 PM..
ajrobson's Avatar
Member with 254 posts.
 
Join Date: Aug 2006
01-Sep-2010, 05:50 PM #3
I just added a select query to the same php script, i can get a list of items in the table to display on the php page but cannot insert anything using my script.
Reply

Tags
php, sql

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: my app is vulnerable to sql injection Darshak77 Web Design & Development 3 29-Jun-2010 05:40 AM
PHP script wont execute... brodie1600 Web Design & Development 3 23-May-2010 03:41 PM
PHP Script to open MySQL DB alpeabody Web Design & Development 1 05-Mar-2010 05:08 PM
Solved: Why doesn't my phone work right in my dreams? hotskates Random Discussion 26 16-Dec-2005 12:37 AM
Why doesn't my CD-ROM drive autoplay in my HP laptop? joeAgain------ Hardware 1 15-Jul-2005 08:49 PM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:27 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.