PHP and ADODB - ADODB throwing an error when uploading content - php

I have the following code (truncated a touch as the css is irrelevant) that I am trying to submit to my MSSQL server. Problem is, it just throws up an error every thing I try. The code is split over 2 PHP pages. Page 1 has the form and Page 2 has the connection data and string.
Page 1 (I have a js function that duplicates the text in the span sections so you get a preview of it before you submit which is why theres the extra at the bottom):
<form action="create.php" name="frmAdd" method="post">
<div class="news"><a id="news1"></a>
<div class="newstitle">
<h3>
<input id="headline" type="text" maxlength="50" name="headlinetxt" />
</h3>
</div> <em><h5>
<input id="timestamp" type="text" name="timestamptxt" />
</h5></em>
<div class="divider"></div>
<p>
<textarea id="news" type="text" name="newstxt"></textarea>
</p>
</div>
</div>
<div class="news"><a id="news1"></a>
<div class="newstitle">
<h3>
<span id="headlinedisp" /></span>
</h3>
</div> <em><h5>
<span id="timestampdisp" /></span>
</h5></em>
<div class="divider"></div>
<p><span id="newsdisp" /></span>
</p>
</div>
</div>
<div id="button" onClick="document.forms['frmAdd'].submit();">Submit</div>
</form>
Page 2:
<head>
<title>News Edit</title>
</head>
<body>
<?php
include('/adodb5/adodb.inc.php');
$db = NewADOConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=sage;Database=live;";
$db -> Connect($dsn,'user','pass');
$strSQL = "INSERT INTO website_news VALUES ('".$_POST["headlinetxt"]."','".$_POST["timestamptxt"]."','".$_POST["newstxt"]."') ";
$upld = $db->Execute($strSQL);
If($upld)
{
echo("Complete");
}
else
{
echo("Error");
}
$db->Close();
$db = null
?>
</body>
Does anyone have any ideas as to why this may not be connecting? I assume it is an issue with line 10 of my page 2 (where it compiles the SQL) as this was giving me seperate errors earlier in my debug. I do have a unique ID in column 1, but this should be auto-populated in theory although dont know if I will need to add this in with something like ...IDENTITY,'".$POST_["headline.... etc. as really that should not be necessary. Is there a better way to debug different parts of the code rather than just showing Error too? (EDIT: Found out last night I can use objErr the same way I can use Err in VB. Didn't think of it at all. Will test that and see what I get)
(PS. A slight side question that I will post seperately if requested. I have the duplicate function working fine in theory (i.e. it works in JSFiddle), but as soon as I take it and put it into place I cannot get it to work on the site itself, running in Chrome, running the same spec jQuery as the fiddle. Fiddle is here: http://jsfiddle.net/bmgh1985/XcScd/)

Never mind. I figured it out (realised I could use Err.Description as in VB)

Related

What is required to work PHP post form method?

I am new to php so help me to make it work. Required action completed by opening the ready.php file but entered form data is not displaying in ready.php file.
i AM USING THIS CODE in index.php for form.
<form method="post" action="ready.php">
<div class="enter-name">
<input class="animated pulse infinite" type="name" required="" maxlength="50" name="n" placeholder="๐Ÿ‘‰ Enter Your Name Here">
<button class="btn animated shake infinite" type="submit"><span>๐Ÿ‘‰</span> Go</button>
</div>
code for ready.php
<figure>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
or
<div class="busi"><br><img src="4.png" height="35px" width="35px"/>
I am not getting what the problem with that.
You don't need a database connection for this, but you do need to be running/have access to some sort of server with php functionality (apache is a good choice).
Regarding the code, I'm no expert, but you could try adding the "name" attribute, because that's what the php script is going to look for. I added it below (name = "name"). You also need to change the input type to text (type="text"):
<input class="animated pulse infinite" type="text" name="name" required="" maxlength="50" name="n" placeholder="๐Ÿ‘‰ Enter Your Name Here">
in your php script, you can find the name variable from the textbox by using this code:
$myName = $_POST['name'];
The name will be inside the variable $myName.
Good luck!
i resolve my above problem by applying this code
<?php echo $_REQUEST['n'];?>

google recaptcha response is null [PHP, localhost]

I need a little help for a problem with Google Recaptcha in a site I am developing in my pc (so localhost) before transferring to the open internet.
I signed up for Google Recaptcha and got a pair of keys. I created this form in a php page:
<div>
<form action="" method="POST" name="formEmail">
<section>
<ul class="formMail" id="ulMsg">
<li>
<label for="msg">Messagge</label>
</li><li>
<textarea class="datoForm autoExpand" name="msg" id="msg" placeholder="Type Msg" rows='3' data-min-rows='3'></textarea>
</li>
</ul>
</section>
<div class="formMail" id="captchaContainer">
<div class="g-recaptcha" data-sitekey="[Public_Key]"></div>
</div>
<br/><input type="button" value="Invia" onclick="formSubmit();">
</form>
</div>
Instead of a submit button I call a JS file to validate user input, if everything is fine I submit data to another php page which checks captcha too. Source of this php page is:
if(isset($_POST['g-recaptcha-response'])){$captcha=$_POST['g-recaptcha-response'];}
$secretKey = "[Private_Key]";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
Here is the problem: I don't get anything! I tried
var_dump($responseKeys);
but all I get is NULL. I do not get any other error, the captcha shows fine in the form and seems to work regularly. I am working in localhost, so my IP is 127.0.0.1, this should help but is useless. I do not have an "open" site to paste it and try, what am I doing wrong?
Just had the same problem. It was a <div> tag causing the problem.
My form was within a main <div> used to format the general layout of the form. The <form> tag doesn't HAVE to be within the main <div> I was using for the form layout. I moved the <form> tag just before my form layout <div> tag and it started working perfectly.
The same can happen with <table> tags. You need to start the <form> tag before any tables used for formatting the form.
So your problem is the <div> just before the <form>:
<div>
<form action="" method="POST" name="formEmail">
Just reverse the 2 tags and it will work fine:
<form action="" method="POST" name="formEmail">
<div>
According to the Google recaptcha documentation:
Method: POST
But you are sending a GET request on this line:
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
A solution has already been proposed here.
Inside HTML Tags :
<head>
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>
<form action="" method="POST">
<div class="g-recaptcha" data-sitekey="PublicKey"></div>
<input type="submit" name="submit" value="Post comment">
</form>
</body>
Inside PHP Tags :
<?php
if(isset($_POST['submit'])) {
if( isset($_POST['g-recaptcha-response']) && !empty( $_POST['g-recaptcha-response'] ) ) {
$secret = 'PrivateKey';
$verifyResponse=file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
var_dump($responseData); //this line returns Null Value
if($responseData->success) {
// Logical Code
}
else {
echo 'Robot verification failed, please try again.';
}
}
}
?>

one field keeping SQL UPDATE statement from working

This has consumed my Saturday. Please help.
I have a large form that I need to update a record in a MySQL database table hosted on a GoDaddy shared account. There are 18 records I'm trying to update when the form is submitted, but so far I've only gotten 17 to do so. The 2nd to last field, "blackTowellCount", causes problems when I include it in the UPDATE statement.
If I exclude the field in question from the SQL statement, ALL 18 fields successfully POST the data to the PHP file and the 17 listed in the SQL statement upload just fine. When I include the blackTowellCount field, the UPDATE stops working and the form no longer POSTS the data to the PHP form. WTF?!
You'll also notice that there's a nearly identical field, "whiteTowellCount" that updates just fine.
portion of the form:
<div class="well">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-2">
<label for="blackTowellCount" class="pull-right">Black Towells</label>
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="blackTowellCount" name="blackTowellCount" placeholder="black towell #"/>
</div>
<div class="col-md-2">
<label for="whiteTowellCount" class="pull-right">White Towells</label>
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="whiteTowellCount" name="whiteTowellCount" placeholder="white towell #"/>
</div>
<div class="col-md-1">
</div>
</div>
</div>
Functional SQL:
$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());
Broken SQL:
$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', blackTowellCount='".$blackTowellCount."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());
portion of .PHP file:
$bathTowellCount = $_POST['bathTowellCount'];
$breakfastCount = $_POST['breakfastCount'];
$lunchCount = $_POST['lunchCount'];
$dinnerCount = $_POST['dinnerCount'];
$breakfastRestriction = $_POST['breakfastRestriction'];
$lunchRestriction = $_POST['lunchRestriction'];
$dinnerRestriction = $_POST['dinnerRestriction'];
$arrivalDate = $_POST['arrivalDate'];
$arrivalTime = $_POST['arrivalTime'];
$needTransport = $_POST['needTransport'];
$blackTowellCount = $_POST['blackTowellCount'];
$whiteTowellCount = $_POST['whiteTowellCount'];
$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());
}
Hi First of all as all suggested your code is open to SQL injections, Use PDO instead . Second php has its functions to display errors include them if you got nothig to do.
add these lines at top of your page
error_reporting(E_ALL);
ini_set('display_errors',1);
also you have not given mysqli_error() its parameter
Replace die(mysqli_error()); with die(mysqli_error($link));
There was a space in front of "blackTowellCount" in the database. I hate programming.

How to pass php variable to modal window

I am making a simple page and I have found this little problem. I have this in my template:
<?php foreach ($this->vypis_serie as $value) : ?>
<div class="serie">
<div id="serie_header">
<?= $value['nazev_cviceni'] ?>
</div>
<div id="serie_info">
<p>Number of excercises: TODO</p>
<p>Sport type: <?= $value['typ'] ?></p>
<p>KCal summary: <?= $value['kcal'] ?></p>
</div>
<div class="button_upravit">Edit</div>
<div class="button_smazat">Delete</div>
</div>
<?php endforeach; ?>
basically it is a block that fills in information about particular exercise (it is a sport app). SO If I have 3 entries in DB, it will print this code three times with corresponding info.
The problem I have is with the edit button, which upon clicking opens modal window. It is made purely with CSS, so no Javascript.
When I click the button, it jumps to this code:
<div id="openModal_edit" class="modalDialog">
<div>
X
<div id="editace">
<form id="platba" action="serie/edit/" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Edit serie</legend>
<ol>
<li>
<label for="name">Name of the series</label>
<input id="name" name="nazev_cviceni" type="text" required autofocus>
</li>
<li>
<label for="typ">Sport type</label>
<select name="typ">
<option value="Kolo">Bike</option>
<option value="Bฤ›hรกnรญ" selected="selected">Running</option>
</select>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit">Save</button>
</fieldset>
</form>
</div>
</div>
</div>
But since I jump to div id and I am not using a new page where I could choose a controller and pass a variable, I need somehow to pass the variable (id of the exercise) to the modal window, so I can know which of the possible buttons I have clicked. Is there any way to do it, without the need to rewrite all other pages where I have used this modal window?
I can't use another foreach like in the first part, because the modal window is always a single object that appears, unlike all the entries on the page that are there as many times as there are entries in the DB.
Hope that it is understandable, sorry for my English :)
The simplest way to do this using a single modal window involves adding some javascript code to your page.
First, add the relevant information to the edit link, with a new data-serie-<name> for each piece of data you want to pass:
<a href="#openModal_edit" data-serie-name="<?= $value['nazev_cviceni'] ?>" ...>
Next, add an onclick event handler to that same link. This handler will extract the embedded data from the <a> element and inject it in the modal window. The dataset element provides access to the data-* attributes from javascript
// Example
onclick="serieName=this.dataset.serieName;document.querySelector('#openModal_edit input#name').value = serieName;return true;"

edit text from/to an XML file : it works in localhost but not on internet? (php, xml)

i try to edit the text of an XML file from my page edit.php. It works fine if i test it in "localhost", the xml file is updated as expected.
But, when i put the files on internet, and i try to edit the text from there, it seems to be ok, but then i refresh the page, and the text in the edit.php is still the same as before, and nothing has been updated. Do you know where this comes from? is there a problem with my "form" ?
here is my code :
<body>
<?php
/* READ */
$dom = new DomDocument();
$dom->load('edition.xml');
$_haut = $dom->getElementsByTagName('haut')->item(0);
$haut = $_haut->firstChild->nodeValue;
/* WRITE */
if ( isset($_POST['cache']) ){
$haut = stripslashes($_POST['haut']);
$_haut->firstChild->nodeValue = $haut;
$dom->save('edition.xml');
}
?>
<div>
<h4 style="float:left;">Update the text</h4>
<div style="clear:both;"></div>
<form method="post" action="edition.php">
<p>
<label for="textarea1">the text : </label><br />
<textarea rows="14" cols="80" name="haut" id="textarea1"><?php echo $haut ?></textarea>
</p>
<input type="hidden" id="cache" name="cache"/>
<p><input type="submit" value="Envoyer" /></p>
</form>
</div>
</body>
Thanks for your help
My best guess is the user php is running as does not have the permissions to do so.

Categories