Unable to retain non-numeric characters

Is it possible to store the value 12345 in a database column?

<?php $favid = '12345';?>

<img id="button" name="button0" src="images/0.jpg" onclick="addremove('<?php echo $favid;?>')" width="150" height="35">

However, when attempting to store:

<?php $favid = 'abcdf';?>

<img id="button" name="button0" src="images/0.jpg" onclick="addremove('<?php echo $favid;?>')" width="150" height="35">

The column type is VARCHAR, so both should be storable, right? Could the problem be with onclick="addremove('abcdf')? What modifications are needed to allow storing non-numeric values?

Answer №1

The issue, among others, resides in:

 $query = mysql_query("SELECT * FROM ajaxfavourites
 WHERE user=$user AND favid=$favid

In this code snippet, $favid is queried without quotes, limiting the SELECT operation to numeric values only.

Furthermore, your code appears highly susceptible to SQL injection attacks. Consider exploring php-pdo (complete with easy-to-follow examples on php.net) for enhancing the security of your code.

Answer №2

During my wait, the solution came to me. I realized that single quotes were omitted:

$query = mysql_query("SELECT * FROM ajaxfavourites WHERE user='$user' AND favid='$favid'");

Now it functions correctly as intended.

I am aware that the code is outdated and plan to update it soon. Appreciate all the assistance!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an online store checkout system with JavaScript?

Recently, I have been experimenting with the PayPal HTML code to create my own shopping cart from scratch instead of using a pre-made system. My current approach involves storing the items added to the cart in an array, although ideally I would like to st ...

Confusing postback phenomena in ASP.NET web forms

I have developed a small script that successfully maintains the focused element during an async postback. However, I encountered an issue when tabbing through controls generated inside an asp:Repeater, where a full postback is unexpectedly triggered. Below ...

Getting the value of a sibling select element when a button is clicked

Trying to retrieve the selected option value on button click has become a challenge due to multiple groups of buttons and select elements. The key seems to be using siblings somehow, but the exact method remains elusive... <div class="form-group" ng-re ...

Choosing between direct imports and package imports in JavaScript

Question: Seeking feedback on the preferred import/export/usage system in TypeScript. While direct imports (#1) are common, which approach is considered best practice in well-established production codebases? Context: Having worked on large-scale projects ...

Utilizing AJAX to retrieve data from a MySQL database upon clicking a button

Hello everyone, I am fairly new to the world of PHP and AJAX, so please bear with me. I am currently attempting to retrieve MySQL results using AJAX. I have made some progress thanks to the information I have gathered from various sources on the internet. ...

Is there a way to create a mobile-exclusive slideshow using JavaScript?

I am trying to create a slideshow on my website, but whenever I add JavaScript it seems to break the desktop version. I want these three pictures to remain static and only start sliding when viewed on a mobile device. I have searched for resources on how t ...

Is there a way to retrieve an HTML index from the provided HTML data using Selenium with Python?

As a newcomer to selenium, I am eager to click on collapsed tabs within dynamic websites. Currently, I am utilizing //a[@href[contains(.,"Text")]] to search for specific text on the page. In a scenario where I retrieve 3 tags containing the desired text ...

Ways to apply Position Fixed to a particular Div element and subsequently eliminate that class while scrolling

Check out my current Jsfiddle project here I am working on a task that involves adding a class to a specific div when scrolling and then removing that class. Below is the JavaScript code I have written for this functionality: var targetDiv = $(".mainwra ...

Generate an array containing all N-digit numbers with a sum of digits equal to S

I encountered a problem with my code translation process. Despite finding solutions in other languages, when I converted them to javascript, the expected array was not created. const find_digits = (n, sum, out, index) => { if (index > n || sum & ...

Issues with the functionality of AJAX response values

I have been attempting to enhance a feed by adding new content when a user reaches the bottom of the page, but I am encountering issues with retrieving the content. Below is the jQuery/Javascript code I am using: $(window).scroll(function(){ if($( ...

Utilizing express.js to access an HTML document

var express = require("express"); var fs = require('fs'); var sys = require('sys'); var app = express(); app.use(express.logger()); app.get('/', function(req, res){ fs.readFile('/views/index.html'); }); ap ...

The file name is not compatible with 'eslint' functionality

I attempted to use the solution provided in this Stack Overflow thread for the error message 'eslint' is not recognized as an internal or external command. I successfully created a .eslintrc.json file with the following content: { "extends" ...

ng-options values are set as objects rather than strings

I am in the process of developing a small Angular (1.5) application that includes two linked drop-down menus. The options in the second drop-down menu are dynamically updated based on the selection made in the first drop-down menu. Everything functions as ...

Struggling to access a nested object within JSON using dot notation

Currently, I am utilizing mongoose and express to interact with data stored in MongoDB. I am able to view the JSON data when I reference the database. However, I encounter an issue when attempting to specifically target an object nested within the data, as ...

"Scotchy McScotchface's to-do list application powered

How is the index.html (frontend Angular) being triggered? The tutorial mentioned that by including one of the following routes in route.js, the frontend gets called app.get('*', function(req, res) { res.sendfile('./public/index.html&ap ...

Sending data to <nuxt-link> component without using parameters or passing hidden information to the router without using parameters

Presently, I am utilizing nuxt and vue routing for my web application. In my view, I'm creating my link in the following manner: <nuxt-link :to="'/article/' + article.id"> Afterwards, I extract this article ID on my article page by r ...

What causes certain images to have unspecified height and width measurements?

Currently, I am in the process of extracting image sizes from a website using a module called scraperjs. Most images have their height and width attributes defined, but some do not, resulting in the returned value being "undefined". How can I retrieve the ...

Getting the UTC time using JavaScript's new Date() method

Despite my thorough search, I have been unable to find a satisfactory solution. My requirement is to obtain the current time in UTC and then subtract a specified number of days (let's say 2 days). For instance, if today is March 25th, I want to retrie ...

Extending the href value using jQuery at the end

Can someone help me with this link: <a id="Link" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2745425453424b4b524940674e0a4355464e4909494253">[email protected]</a>?subject=I-Drain Bestellung& ...

When integrating the Google Drive API with Node.js, the default filename assigned to uploaded files is typically 'Untitled'

Having trouble uploading a file to Google Drive without it getting saved as an 'Untitled' file. Any solutions? If your answer works, I'll accept it. Is there anyone out there who can help with this? Thanks in advance. Here is the code snippe ...