Problem with Insert data.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Problem with Insert data.

Post by 303tech »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I figured it might have something to do with the space in the name so i tried to use text as the field for unitname. I can insert other $string just fine, or just plain text. However it will not input the unitname from the $tring when i try this code. any ideas?

Thanks,
Nick

Code: Select all

<?php
$ini = parse_ini_file('Aloha.ini');

$unitname=$ini['UNITNAME'];

$connection=mysql_connect("localhost","tech303_bec","password") or die("Could not connect to the database server");
$db= mysql_select_db("tech303_bec",$connection) or die ("Unable to select database.");  
$sql="INSERT INTO customer (unitname) VALUES ('$unitname')";
mysql_query($sql,$connection) or die ('Could not insert data'); 
echo('Data inserted successfully.'); 
mysql_close($connection); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

ahh, i also just noticed ' in the name too Rosie's Diner.

is this the problem then?
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

okay so it is the apostrophe....what kind of field can i use in my database to let it accept this?
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

okay...so i used str_replace....to get rid of the apostrophe, but is it possible to store this char in MYSQL db?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

I now am testing to see if i can pass the sec1 entry to $keyresult.

Code: Select all

$keycheck="SELECT sec1 FROM customer WHERE sec1='$sec1'";
$keyresult=mysql_query($keycheck);
echo $keyresult;
this only prints Resource Id #2
rather than, the sec1 entry.

Also, id like to check to see if an entry exists already in the table = sec1. ive tried already to do this but getting stuck also.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You need to fetch the record(s) in the resultant query result set.
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

sorry i dont follow you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$keyresult is a reference to an internal resource. In order to retrieve information from that resource, you must use one of the fetch functions provided by the MySQL API. There are several to choose from: mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_assoc() and mysql_fetch_row(). There's also mysql_result(), but I can rarely recommend using that over one of the other fetch functions.
Post Reply