get variable from url give error - php

I am using this code to get the variable iduser to use it in php as part of another url ( line2). But it gives me the following error "Parse error: syntax error, unexpected T_VARIABLE in" can you please show me my mistake.
<?php
$iduser=$_GET['iduser'];
$currsiteurl = 'http://graph.facebook.com/'$iduser;

You have a syntax error.
$currsiteurl = 'http://graph.facebook.com/' . $iduser;

<?php
$iduser = $_GET['iduser'];
$currsiteurl = "http://graph.facebook.com/${iduser}";
?>
should work hope this helps.

you forgot the concatination . between string and variable:
$currsiteurl = 'http://graph.facebook.com/' . $iduser;
should work

Use this code
<?php
$iduser=$_GET['iduser'];
$currsiteurl = 'http://graph.facebook.com/'.$iduser;
?>
You have to use '.' to join string in php

Related

PHP / SQL error, unexpected variable name

I get the following error:
Parse error: syntax error, unexpected '$studentNo' (T_VARIABLE)
Can somebody tell me what's wrong here? I've read about this kind of error and base on it, it usually happens when there's a missing bracket, parenthesis or semi-colon but in my case I don't think I missed any..Does it have something to do with the variable itself, perhaps?
if(isset($_POST['next'])){
$studentNo = $_POST['sn'];
if(!empty($_POST['sn'])){
$check = ("SELECT * FROM student_info WHERE SN="$studentNo"");
$check1 = mysqli_query($con, $check);
if(mysql_num_rows($check1) > 0){
$errors['sn'] = "Student number already exists";
}
}
}
Your problem is that you have to concatenate the string.
But, before doing this, make sure that your SQL library protects against SQL injections.
To do this, just do:
$check = "SELECT * FROM student_info WHERE SN=" . $studentNo . ";";
// Also, remember to add a semicolon at the end of your SQL query :)
The best way to do this is to use a prepared statement. This site explains it very well.

Parse error: syntax error, unexpected T_RETURN in C:\wamp\www\Nu-Bio\view_topic.php on line 77

Hello everybody~ I am getting this error (Parse error: syntax error, unexpected T_RETURN in C:\wamp\www\Nu-Bio\view_topic.php on line 77) when trying to run this little bit of code:
$idd = $rows['id'];
$thisql = "SELECT `locked` FROM `forum_question` WHERE `id` = '$idd'";
$mythisql = mysql_query($thisql);
$res1 = return($mythisql);
It's standalone, not in a function or anything. I'd give you more information, but I'm not sure what to give. I'm calling it with if ($res1 == 0) {. Thanks for any help I get!
(PS: I know I should be moving to mysqli. I WILL be doing that soon, please don't tell me to. I just want to make sure it works before changing it, as I'm almost done with my project)
What should this "return" do? Anyway it's wrong here and is your error at line 77.
$res1 = return($mythisql);
Solution:
$res1 = $mythisql;
or
$res1 = mysql_query($thisql);

Zend - Catchable fatal error

I am getting error while running following code
$value_sql = "SELECT test_fielf FROM `tbl_test` where `site_id`='".$sid."'";
$register_value = $db->fetchRow($value_sql);
echo $register_value;die();
The error : Catchable fatal error: Object of class stdClass could not be converted to string
you cannot use echo for printing objects
$value_sql = "SELECT test_fielf FROM `tbl_test` where `site_id`='".$sid."'";
$register_value = $db->fetchRow($value_sql);
print_r( $register_value);
die();
Assuming the code you posted is as-is, you're missing a closing double-quote on the first line.
$value_sql = "SELECT test_fielf FROM `tbl_test` where `site_id`='".$sid."'";
$register_value = $db->fetchRow($get_register_value_sql);
echo $register_value;die();
The error you're experiencing is due to $register_value = $db->fetchRow($get_register_value_sql); returning an object, not a string. If you wish to treat is as a string, then you can cast is as a string using:
$register_value = (string) $db->fetchRow($get_register_value_sql);
Try this:
$value_sql = "SELECT test_fielf FROM `tbl_test` where `site_id`='" . $sid . "'";
$register_value = $value_sql -> fetchRow(DB_FETCHMODE_ASSOC);
print_r($register_value);
die();

PHP echo href issue

I am trying to add a delete session option in my form, but I cannot get around the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /users/bfullilo/acme_dl_sessions.php on line 31
Here is my line 31
echo " Not $_SESSION[\"email\"]?";
I know that I'm not escaping everything I need to, but I've hit a wall. Any help?
It's slightly faster to use single quotes
echo ' Not ' . $_SESSION["email"] . '?';
change to either:
echo " Not $_SESSION[email]?";
or
echo " Not {$_SESSION['email']}?";

PHP giving variable error when using SESSION

All,
I'm trying to write a mySQL query but PHP is giving me an error. The line that is giving me an error is:
$qry = "Select * from vendor_options where vendor_option_id='$_SESSION[pav_vendor_categories_$i]'";
The above code is in a for loop so that is how the $i is getting populated. The error I'm receiving is:
Parse error: syntax error, unexpected T_VARIABLE, expecting ']'
Any ideas on what is wrong? Thanks!
$sVendorId = $_SESSION['pav_vendor_categories_' . $i];
$sQuery = "SELECT * FROM vendor_options WHERE vendor_option_id='{$sVendorId}'";
This your working code.
Build vendor option ID outside of query — this will make you code more readable.
Try this;
$qry = "Select * from vendor_options where
vendor_option_id='{$_SESSION["pav_vendor_categories_{$i}"]}'";
Demo: http://codepad.org/0nHsFZ8i
should be :
$qry = "Select * from vendor_options where vendor_option_id='".$_SESSION["pav_vendor_categories_".$i]."'";
but dont do it like that... read about sql injection
hope this helps

Categories