Cooper94 Posted November 12, 2009 Share Posted November 12, 2009 $sql = "SELECT * FROM items WHERE `Item ID` = '{$_GET['id']}'"; I am trying to select items where Item ID = what everis in the id = area. Now when I do this in the browser it shows up blank. Is there a way to make it so that php knows there is a space in that row? Thank you for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/ Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 what do you mean make it so php knows there is a space in that row? where is this space coming from? Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956376 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 In phpmyadmin I created the table called items and than I created a table name Item ID. Now I want it so that when I call the select function and tell it where to search which is Item ID now in the database the name of the table is Item ID with that space in the middle but when I put the space in the sql select code it dosnt do anything. It just shows the page being blank. Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956381 Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 are you echoing something? need to see more code. didn't know you could have spaces in table names... but thats all wrong anyways. the table name goes after the FROM keyword, not the WHERE keyword. Column names go after the WHERE keyword. are you sure you didn't create a column named Item ID? Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956386 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 Yes it was the column I am sorry I couldnt find that word in my head lol. Here is the whole php file. <?php $dbhost = 'localhost'; $dbusername = 'lidjcom_invent'; $database_name = 'lidjcom_invent'; $dbpasswd = '147171'; $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database_name", $connection) or die("Couldn't select database."); $sql = "SELECT * FROM items WHERE 'Item ID' = '{$_GET['id']}'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $row['Cost']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956389 Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 well of course the page is blank... you never echo anything. perhaps you meant echo $row['Cost']; Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956394 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 I am so sorry for wasteing your time, somtimes I just fly right by those simple things. Since it was common sinse I would never thing it would be that, lol. Yet again I am sorry for wasteing your time. Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956395 Share on other sites More sharing options...
sasa Posted November 12, 2009 Share Posted November 12, 2009 $sql = "SELECT * FROM items WHERE `Item ID`= '".$_GET['id']."'"; Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956398 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 I know I just made this solved but one more thing about multipling. $price = $row['Cost']; $box = $_GET['amount']; $finalprice = $box * $price; I have tested out the variables by echoing them out to make sure they had a number and they both do but when entered into the database it returns a value of 0. Any help would be great, thank you again for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956429 Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 can i see that code that enters them into the database?- Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956443 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 There you go thank you again for all the help! <?php $dbhost = 'localhost'; $dbusername = 'lidjcom_invent'; $database_name = 'lidjcom_invent'; $dbpasswd = '147171'; $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database_name", $connection) or die("Couldn't select database."); $sql = "SELECT * FROM `items` WHERE `Item ID` = '{$_GET['id']}'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $price = $row['Cost']; $box = $_GET['amount']; $finalprice = $box * $price; mysql_query("INSERT INTO cart (`Item`, `Item ID`, `Box Amount`, `Cost`) VALUES ('{$row['Item']}', '{$_GET['id']}', '{$_GET['amount']}','$finalprice')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956450 Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 try removing the single quotes around $finalprice, IE mysql_query("INSERT INTO cart (`Item`, `Item ID`, `Box Amount`, `Cost`) VALUES ('{$row['Item']}', '{$_GET['id']}', '{$_GET['amount']}',$finalprice)"); what I suspect is happening is you are passing a string value into an integer column, and strings that are coerced to integer values become 0. at least thats how PHP handles it, but I think MySQL does that same Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956451 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 Hmm that didnt fix the probelm.... It was really confusing to me as well. Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956456 Share on other sites More sharing options...
Cooper94 Posted November 12, 2009 Author Share Posted November 12, 2009 In the database I added a $ symbol so that was what was causing this problem. Once again I will put this topic as to solved and I thank everyone for their help! Quote Link to comment https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.