473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Why isn't my script inserting info into my mysql database?

Ajm113
161 100+
Ok, when I was new to this I had this problem and I bet a lot of other people did when they where new to PHP and Mysql. So this mite be your question;
"Ok, no errors or warnings in mysql and php so why isn't the script entering info into my row?".

Well to awnser your question most servers that you pay for monthly or own will have a anti mysql injection attack. So it will not allow the injection to enter in your database for your protection and theirs.

"Whats a mysql injection attack and how does it happen?"

Lets say you made a emailer for your first project or a comments area and you wanted the user to enter anything he or she wants on your comments area. But if they enter in single qoutes into your textarea/input field that means they can do anything they want to your database! Using simple mysql commands if they wanted. So that means big trouble to you when you do this kind of stuff so befor you jump off your seat and start publishing stuff like a comments system it is best to protect it.

"Ok, so whats best to protect this ordeal?"

Well their are two ways that will work or not. One way is the mysql_escape_string function. Which works perfect for me that is...

"This function will escape the unescaped_string, so that it is safe to place it in a mysql_query(). This function is deprecated.

This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting."


As you can see it is simmulare to the real_escape function.

The real_escape string works great, but sometimes servers arn't configured to this function so if you get errors that you think are unfixable that envolve this function then go with the mysql_escape_string. It will usauly something like "Cannot connect to nobody@localhost on mysql-real-escape-string." Something like that I forgot how it said it, but it is something like that.

It is also best and wise since html can sometime convert spaces or single quotes into slashes or browser friendly text like a url you mite want to use the stripslashes

Example of inserting data into a database the good way:

[PHP]<?php

require('connect.php'); //use the mysql_connect function in this file

$text = htmlentities(stripslashes(mysql_escape_string($_PO ST['text'])));

mysql_query("INSERT INTO table (stories) VALUES ('$text')");

?>[/PHP]

Sorry if I forgot something, but this is what I know and do with all my scripts.
Jun 7 '07 #1
1 1631
Wrong session to post,:)
Jun 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: danubian | last post by:
Hi, I'm a newbie in php/mysql programming,really am. I'm working on a web-site that allows registration and posterior logging in. Already registered user logs in with valid username and...
1
by: E | last post by:
I have two tables and i want join the two of the primary id's in to one table. the database is mysql. ex. Table Item (ID int(10) NOT NULL auto_increment) Table Actor(ID int(10) NOT NULL...
5
by: news | last post by:
I have a new situation I'm facing and could use a suggestion or two, as I don't seem to be able to think in the abstract very well. We have a local server which holds all of our image files. We...
4
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was...
4
by: Markus | last post by:
Hello I use a table to cache some informations which need lots of resources to be composed. The first time the info is needed, it will be composed and written to the cache table ($db in the...
6
by: rhaazy | last post by:
I have to create a script to install a database, and one of the tables has about 200 rows of static data... I dont want to have to manually type in 200 insert statements, so is there a better way...
10
by: Jerim | last post by:
I am attempting to put together one script that pulls data from one database on its own server, and data from another database on its own server, which is off-site. Server 1 - Only allows shared...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.