Jump to content

Recommended Posts

$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!

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956381
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956386
Share on other sites

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']; 

?>

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956389
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956429
Share on other sites

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')");


?>

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956450
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/181298-solved-mysql-insert/#findComment-956451
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.