sql bs

In this excerpt, sql is deciding not to be very friendly and is returning no errors but will not execute correctly. newquery works fine, its newquery2 I am having an issue with. In newquery 2 Ive put quotes around $username, removed them, put single quotes removed them, as well the same with just username. Does anyone know what the issue is?

[php]<?php
if($cartrow[‘cart’] == no){
echo "You currently have no cart
build cart,


" ; }elseif($cartrow['cart'] == yes){ echo "wood:" . $rrow['wood']; } ?>
<?php $username = $_SESSION['user']['username'];

if(isset($_POST[‘submit’])){
$newquery = mysqli_query($conn, “UPDATE users SET cart = ‘yes’ WHERE username=’$username’”) or die(mysqli_error($conn));

$newquery2 = mysqli_query($conn, “INSERT INTO resources (username) VALUES ($username)) or die(mysqli_error($conn)”);

header(“Refresh:0; url=home.php”);

}
?>[/php]

also in resources its just

id [int] [ai]
username [varchar] [25]
wood [int] [255]

Prepared statements would actually fix your quotation issue.

Look closely,
[php]“INSERT INTO resources (username) VALUES ($username)) or die(mysqli_error($conn)”[/php]

I’ve done it this way

[php] “INSERT INTO resources (username) VALUES ($username)) or die(mysqli_error($conn)” [/php]

and this way

[php] “INSERT INTO resources (username) VALUES (’$username’)) or die(mysqli_error($conn)” [/php]

and this way

[php] “INSERT INTO resources (‘username’) VALUES ($username)) or die(mysqli_error($conn)” [/php]

and finally this way

[php] “INSERT INTO resources (‘username’) VALUES ‘($username’)) or die(mysqli_error($conn)” [/php]

none of which have worked

Look at the forums syntax highlighting… You should see a difference between the coloring of the two lines…

…check that double quote at the end of statement - it should be placed somewhere else…(similarly like in $newquery)…

Sponsor our Newsletter | Privacy Policy | Terms of Service