Page 1 of 1

Problem with Insert data.

Posted: Thu Mar 22, 2007 2:21 pm
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]

Posted: Thu Mar 22, 2007 2:22 pm
by 303tech
ahh, i also just noticed ' in the name too Rosie's Diner.

is this the problem then?

Posted: Thu Mar 22, 2007 2:47 pm
by 303tech
okay so it is the apostrophe....what kind of field can i use in my database to let it accept this?

Posted: Thu Mar 22, 2007 4:09 pm
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?

Posted: Thu Mar 22, 2007 4:21 pm
by feyd

Posted: Thu Mar 22, 2007 6:42 pm
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.

Posted: Thu Mar 22, 2007 6:47 pm
by feyd
You need to fetch the record(s) in the resultant query result set.

Posted: Thu Mar 22, 2007 7:06 pm
by 303tech
sorry i dont follow you.

Posted: Thu Mar 22, 2007 7:15 pm
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.