PHP - If() And * Syntax Problem
I want to check to see if two variables are NOT empty and if so- assign a new variable
Code: [Select] if(!empty($net_op_call) and !empty($f_name)){ $net_start = 'Yes'; } Is this syntax correct as it is not setting the variable - $net_start Similar TutorialsHi.. I create mysql syntax for query testing before i input to my php code here is my mysql code: Code: [Select] set @t = 0; set @rqty=31968; SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN @t+OUTPUT_QTY > @rqty THEN @rqty -@t ELSE OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (@t < @rqty); and i attach the sample output of the above query. Now that query test is work i will input that code to my php codes. $sql = "SELECT SKUCode, Materials, Comp, Qty FROM bom WHERE SKUCode = '$SKUCode'"; $res = mysql_query($sql, $con); ($row = mysql_fetch_assoc($res)); $Materials = $row['Materials']; $Qty = $row['Qty']; $Comp = $row['Comp']; //P28 //-----Compute Req Qty and Save to table---// $ReqQty = $Qty * $POReq; // 31968 $sql = "UPDATE bom SET ReqQty = '$ReqQty' WHERE SKUCode = '$SKUCode' AND Materials = '$Materials'"; $resReqQty = mysql_query($sql, $con); $t = 0; $sql = "SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN $t+OUTPUT_QTY > $ReqQty THEN $ReqQty -$t ELSE OUTPUT_QTY END as qty, $t := $t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '$Comp' AND ($t < $ReqQty)"; when I echo the query: I got this: SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN 0+OUTPUT_QTY > 31968 THEN 31968 -0 ELSE OUTPUT_QTY END as qty, 0 := 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (0 < 31968) then I run it to the sql and I got an error: Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':= 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '' at line 1 (0 ms taken) Any help is highly appreciated Thank you so much I am using the code below to attempt to show stored value only when data is present in the record set. Code: [Select] $results[] = " if ({$row['MapLocation']} != NULL ){ echo <a href=\"{$row['MapLocation']}\" target=_blank>Map</a>} "; $i++;What I see on the page is: if ( != NULL ){ echo Map} with Map being a link. I know there is a syntax error somewhere but can't find it. Open to suggestions. Thanks for your help I'm trying to call a PDO fetch from within a class I'm writing, however I have never used PDO and the documentation @ php.net is somewhat...crap. It's probably fine for people who just need a refference, but navigating it as a learning resource isn't the easiest. Anyway, I keep getting Quote Fatal error: Call to undefined method PDO::fetch() in C:\xampp\htdocs\eclipse\src\connect.php on line 85 I can post up the class if you like, but it's something of a mess to follow. This is the method that's calling the fetch : public function get($method='ASSOC'){ if($this->temp !== null){ $this->run(); //performs PDOexecute and returns resourcce to $this->resource $qry = $this->resource; if($this->rdbs == 'mysql'){ $fetch= "FETCH_".strtoupper($method); //builds the fetch type from parameter, or uses ASSOC as default. /*Ln85------------>>*/ $this->result = $this->dbo->fetch(PDO::$fetch); //performs the PDO search using the $this->dbo which is the public class PDO Object }// the stuff under here isn't used (yet) and isn't in PDO, since MS SQL Server is not supported by PDO elseif($this->rdbs == 'mssql'){ $fetch = "SQLSRV_FETCH_".strtoupper($method); $this->result = sqlsrv_fetch_array($qry, $fetch); $this->num_rows = sqlsrv_num_rows($qry); } } I built the call to mirror what I could find on the php.net site, but obviously that's not what's happening here. Can anyone point out what part of this I have screwed up? (I don't mind if the answer's all of it, so long as it comes with an explination ) ok im building facebook app and im just back to php after months not touched it. this is the code: $image = $facebook->api_client->photos_get(null,null, echo $uid); print_r ($image); echo "<BR>"; echo $image[0]["src"]; the problem is that echo $uid i tried every variation and it does not work! i maybe forget something that i should have done? the $uid containing user id numbers so what i did wrong and if im not wrong i wanted the numbers($uid) Wrapped in quotation marks so i tried: echo ." $uid ". and alot of other please help tnx My delete button will not work for some reason. I have created a loop, ordered my database entries with $i and have gotten closer, but not 100% of the way to making it work. I am trying to delete rows from my database individually. Not sure where I am going wrong with my syntax, but something is not working. The entries are not deleting nor am I receiving any errors. I am stumped. Here is the code. I shortened it for readability. Code: [Select] <?php // database connection information include('connection.php'); $query = "SELECT * FROM FORUM_MESSAGE ORDER BY MSG_DATE DESC"; $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i < $num) { $subject = mysql_result ($result, $i, "SUBJECT"); $message_text = mysql_result ($result, $i, "MSG_TEXT"); echo '<form method="POST" name="subject">'; echo '<input type="hidden" name="update" value="<?php echo $subject; ?>" />'; echo '<input type="submit" name="update" value="Update" />'; echo ' '; echo '<input type="hidden" name="delete" value="' . $subject . '" />'; echo '<input type="submit" value="Delete" />'; echo '</form>'; $i++; } if (isset($_POST['delete'])) { include ('connection.php'); mysql_query("DELETE FROM FORUM_MESSAGE WHERE SUBJECT = " . $subject); } ?> </body> </html> Thanks again! Ryan Having issues with a small piece of script. Trying to delete entries from a database. First, the essentials: the button being clicked is named 'delete' the columns in the actual table are 'INDEX' 'SUBJECT' 'MSG_TEXT' and 'MSG_DATE' Here is the code: Code: [Select] <?php if($_POST['delete']) // from button name="delete" { for($i=0;$i<$count;$i++) { $del_id = $i; $sql = "DELETE FROM FORUM_MESSAGE WHERE id='$del_id'"; $result = mysql_query($sql) or die (mysql_error()); } if($result) { header('Location: message-deleted.php'); } } ?> Thanks again! Ryan Ok I solved the problem, this was my initial query which didn't work: $query3 = "INSERT INTO user (avatar) VALUES ('$avatar') WHERE user_id = '$dbuser_id'"; but this one works: "UPDATE user set avatar = '$avatar' WHERE user_id = '$dbuser_id'"; Can anyone tell me what's wrong with this particular part of my php code? $handle = fopen(''lovell.txt, ''a''); That was the line it said there was an issue with, and I'm new and can't seem to figure it out. I have been looking at this code most of the morning and do not have a clue what is wrong with the code. I am hoping its not a stupid mistake, can someone please help me out? thank you
<title>Inputing Travel Detials</title> <header> <h1 align="center"> Adding Travel Detials </h1> <body> <p> <center><img src="cyberwarfareimage1.png" alt="Squadron logo" style="width:200px;height:200px" style="middle"></center> <table border="1"> <tr> <td><a href="index.php"> Home Page </a></td> <td><a href="administratorhomepage.html">Administrator Home Page </a></td> <td><a href="viewhomepage.html">View Home Page </a></td> <td><a href="Inputhomepage.html">Input Home Page </a></td> <td><a href="traveldetials.html">Enter More Travel Detials </a></td> </table> </p> <?php include "connection.php"; $Applicant_ID = $_POST["Applicant_ID"]; $Method_Of_Travel = $_POST["Method_Of_Travel"]; $Cost = $_POST["Cost"]; $ETA = $_POST["ETA"]; $Main_Gate_Advised = $_POST["Main_Gate_Advised"]; $query = ("UPDATE `int_board_applicant` SET `Method_Of_Travel`=`$Method_Of_Travel', `Cost`=`$Cost', `ETA`='$ETA', `Main_Gate_Advised`='$Main_Gate_Advised' WHERE `Applicant_ID`='$Applicant_ID'"); $result = mysqli_query($dbhandle, $query) or die(mysqli_error($dbhandle)); if($result){ echo "Success!"; } else{ echo "Error."; } // successfully insert data into database, displays message "Successful". if($query){ echo "Successful"; } else { echo "Data not Submitted"; } //closing the connection mysqli_close($dbhandle) ?> Ok this is puzzleing. I am geting "Could not delete data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being.
<?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?> Hi guys
I have this code below and all works fine when submitting this online application apart from when someone types either ' # & into one of the comment fields in which it throws up the error. Have tried various fixes from across the internet but no joy. Can anyone offer suggestions?
<?php
$con = mysql_connect("localhost:3306","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('sfapp', $con);
$sql="INSERT INTO 'sfapp' ('surname_add','forename_add','dob_add','hometele_add','mobiletele_add','homeadd_add','siblings_add','schoolname_add','headname_add','schooladd_add','schooltele_add','schoolem_add','alevel_add','personstate_add','nameprovided_add','pe_add','se_add','PredGrade_Art','PredGrade_AScience','PredGrade_BusStudies','PredGrade_Electronics','PredGrade_EnglishLang','PredGrade_EnglishLit','PredGrade_French','PredGrade_German','PredGrade_Geog','PredGrade_Graphics','PredGrade_History','PredGrade_Maths','PredGrade_SepScience','PredGrade_ProductDesign','PredGrade_Spanish','PredGrade_Other','Gender_Male','Gender_Female','Sub_EnglishLit','Sub_Maths','Sub_FurtherMaths','Sub_Biology','Sub_Chemistry','Sub_Physics','Sub_French','Sub_German','Sub_Spanish','Sub_Geography','Sub_History','Sub_RE','Sub_FineArt','Sub_Business','Sub_Computing','Sub_GlobPersp','Sub_DramaAndTheatre','Sub_PE','Sub_Dance','Sub_Politics','Sub_Psychology','Sub_Sociology','readprospect_chk','Sib_Yes','Sib_No','Current_Student_Yes','Current_Student_No','I_Understand_chk','Current_Education_chk','Local_Care_chk','Staff_Cwhls_chk','Sub_Film')
VALUES
('$_POST[surname_add]','$_POST[forename_add]','$_POST[dob_add]','$_POST[hometele_add]','$_POST[mobiletele_add]','$_POST[homeadd_add]','$_POST[siblings_add]','$_POST[schoolname_add]','$_POST[headname_add]','$_POST[schooladd_add]','$_POST[schooltele_add]','$_POST[schoolem_add]','$_POST[alevel_add]','$_POST[personstate_add]','$_POST[nameprovided_add]','$_POST[pe_add]','$_POST[se_add]','$_POST[PredGrade_Art]','$_POST[PredGrade_AScience]','$_POST[PredGrade_BusStudies]','$_POST[PredGrade_Electronics]','$_POST[PredGrade_EnglishLang]','$_POST[PredGrade_EnglishLit]','$_POST[PredGrade_French]','$_POST[PredGrade_German]','$_POST[PredGrade_Geog]','$_POST[PredGrade_Graphics]','$_POST[PredGrade_History]','$_POST[PredGrade_Maths]','$_POST[PredGrade_SepScience]','$_POST[PredGrade_ProductDesign]','$_POST[PredGrade_Spanish]','$_POST[PredGrade_Other]','$_POST[Gender_Male]','$_POST[Gender_Female]','$_POST[Sub_EnglishLit]','$_POST[Sub_Maths]','$_POST[Sub_FurtherMaths]','$_POST[Sub_Biology]','$_POST[Sub_Chemistry]','$_POST[Sub_Physics]','$_POST[Sub_French]','$_POST[Sub_German]','$_POST[Sub_Spanish]','$_POST[Sub_Geography]','$_POST[Sub_History]','$_POST[Sub_RE]','$_POST[Sub_FineArt]','$_POST[Sub_Business]','$_POST[Sub_Computing]','$_POST[Sub_GlobPersp]','$_POST[Sub_DramaAndTheatre]','$_POST[Sub_PE]','$_POST[Sub_Dance]','$_POST[Sub_Politics]','$_POST[Sub_Psychology]','$_POST[Sub_Sociology]','$_POST[readprospect_chk]','$_POST[Sib_Yes]','$_POST[Sib_No]','$_POST[Current_Student_Yes]','$_POST[Current_Student_No]','$_POST[I_Understand_chk]','$_POST[Current_Education_chk]','$_POST[Local_Care_chk]','$_POST[Staff_Cwhls_chk]','$_POST[Sub_Film]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['pe_add'])) {
//Email information
$admin_email = $_REQUEST['pe_add'];
$forename = $_REQUEST['forename_add'];
$email = "autoreply@testing.com";
$subject = "Application";
$desc =
"Dear $forename
Thank you for submitting your online application, we will be in touch shortly.
"
;
//send email
mail($admin_email, "$subject", "$desc", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
If you are seeing this, you need to go back and fill out the Personal Email section!
<?php
}
header("location:complete.php");
mysql_close($con)
?>
Thanks in advance.
My error happens on line #81 Code: [Select] <?php if (!isset($_POST['submit'])) { ?> <h2>Todays Special</h2> <p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="day"> <option value="1">Monday/Wednesday <option value="2">Tuesday/Thursday <option value="3">Friday/Sunday <option value="4">Saturday </select> input type="submit" name="submit" value="Go"> </form> <?php // get form selection $day = $_POST['day']; // check value and select appropriate item switch ($day) { case 1: $special = 'Chicken in oyster sauce'; break; case 2: $special = 'French onion soup'; break; case 3: $special = 'Pork chops with mashed potatoes and green salad'; break; default: $special = 'Fish and chips'; break; } ?> Which of the below syntax is the better to be using? $bal = 100; if($bal > 100) { echo "you have over 100 pounds; } else { echo "you have less than 100 pounds"; } if ($bal > 100); echo "you have over than 100"; else ; echo "you have less than 100"; endif; The issue is there seems to be NO syntax error. 1. There is no relevant code before or after this line. 2. Yes, one would think a ! should be there as did I (I didn't write the code), however, even with the ! it still gives the same error. if (function_exists('gzcompress')) die(FUNCTION_NOT_FOUND); is giving me a syntax error, unexpected 'if', expecting 'function' or 'const' I am updating this code from PHP5.3 to PHP7.4 and I can't figure out what the syntax problem is since PHP allows this. I am using Eclipse PHP to do the conversion. Hi there, I was trying to modify the code from the tutorial "PHP Basic Database Handling" and the code uses something I haven't seen before, but looks intriguing. Can someone explain how to use this: echo <<<SOMELABEL stuff SOMELABEL; Or let me know why my code didn't work? The error is an unexpected end statement on the last line of the file. My Code: Code: [Select] <?php $mystring = $_GET['FirstLast']; if($mystring == "") { echo "You reached this page by mistake, click on the link in your email"; }else { //echo $mystring; // connect to db $conn = mysql_connect('localhost','user','pw') or trigger_error("SQL",E_USER_ERROR); $db = mysql_select_db('tsec',$conn) or trigger_error("SQL",E_USER_ERROR); $sql = "SELECT `First Name`, `Last Name`, `Title`, `Org Parameter 1`, `Org/Person Name`, `Attendee Parm Value 1`, `Attendee Parm Value 2`, `Attendee Parm Value 3`, `Attendee Parm Value 4`, `Attendee Parm Value 5`, `Attendee Parm Value 6`, `Attendee Parm Value 7`, `Attendee Parm Value 8` FROM `attendees` WHERE FirstLast = '$mystring'"; $result = mysql_query($sql,$conn) or trigger_error("SQL", E_USER_ERROR); $list = mysql_fetch_assoc($result); echo <<<LISTNAME <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <table border = '1'><tr><td colspan = '2'>{$list['First Name']} {$list['Last Name']}</td></tr> <tr><td>Title</td><td><input type = 'text' name = 'Title' value = {$list['Title']}</td></tr> </table></form> LISTNAME; mysql_close($conn); } ?> Thanks. Is this proper syntax? if (($news['accounttyperaw'] !== 0) || ($news['accounttyperaw'] !== 1)) I just came up with a line of code that I am not able to understand what's it doing. The code is: Code: [Select] function cost() { return $this->costStrategy->cost($this); } here costStrategy is a class property which holds a reference to the object of type CostStrategy class and cost() is a method defined in CostStrategy. Code: [Select] <?php /* Register footer widget */ if (function_exists('register_footercounter') ) register_footercounter(array( 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); ?> How exactly does this syntax work. I am not use to seeing this. It is an if statement without brackets. It uses a function inside of it with an array. So, I do not exactly understand what is happening here. I have used php for a long time and just now started working with Wordpress awhile back, and reviewing how to do themes, and I am seeing this kind of funky syntax all over the place. Thanks again. |