kvarnerexpress
Feb 14 2006, 12:37 PM
Im having trouble getting my PHP to work. Basically i have a form with a button linking to a php file. When i click submit it calls this file and is suppost to add the data to a database. Im using a my sql databse and it connects fine. Unfortunately when i click submit all i get is the "Inspection did not add". From this i know i have made a connection with the database and im absolutely 100% sure that all field names are correct on the forms and database. Any ideas? Heres the script.... PHP Code: CODE <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head>
<body>
</body>
<?php $host="localhost"; $username="***"; $password="***"; $db_name="***"; $tbl_name="InspectionRequest";
// Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql);
// Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row
mysql_query("INSERT INTO `InspectionRequest` (JobRef, ContactNam, ContactTel, Location, InspcType, Date, TimePref) VALUES (‘$JobRef’, ‘$ContactNam’, ‘$ContactTel’, ‘$Location’, ‘$InspcType’, ‘$Date’, ‘$TimePref’ )");
if($count==1){ session_register("AddInspection"); header("location:/Index.html"); } else { echo "Inspection did not add."; } ?>
</html>
Reply
rvalkass
Feb 14 2006, 01:55 PM
I think it is the MySQL query you run: CODE $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
It literally searches for rows containing $myusername and $mypassword. You should replace it with something like this: CODE $sql="SELECT * FROM $tbl_name WHERE username='".$myusername."' and password='".$mypassword."'";
Also, nowhere above that point do you actually define those variables, which may also be the problem  The same also applies to the second MySQL query near the bottom. See if that helps.
Reply
Yarrgh
Feb 14 2006, 04:50 PM
It doesn't have to be defined. But it is a security risk. I am assuming you use the 'post' method on your form. If I am wrong ignore this post.If did this, http://blah.com/blah.php?JobRef=blah&ContactNam=blah... and finished out the rest of the values (in your insert query) I could add what ever I want in it. I don't know if you purposely left them off or what, but, always use $_POST[variable]. If you want you can do this CODE $blah = $_POST["blah"]
Same applies for cookies. I do have to know what the variable names are, but it can be done.
Reply
kvkv
Feb 15 2006, 07:41 PM
Summarizing your code, 1. check for username & password (get count) 2. insert into InspectionRequest 3. if count is not 1, print "Did not add" else redirect to index. By the above, it is evident that you are printing wrong message. Check your InspectionRequest table in phpmyadmin and you should see your rows inserted. You need to rewrite your logic to this. 1. check for username & password (get count) 2. if count is not 1, print "Login failed", exit 3. insert into InspectionRequest 4. if insertion successful, redirect to index else print "Add to InspectionRequest failed"
Reply
Similar Topics
Keywords : query running submitting- Parse: Error Unexpected T_lnumber
- php parse error when running script (4)
Hi. I've just created a php script. The main object of the script is to delete some old files
and replace it with a new file with some new content, effectively moving the contents from one file
to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
$a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&...
Sql Query
- Mistake? (19)
Simple Mysql Query Limiting
- (9)
Simple MySQL Query Limiting CODE <?php // If mypage?limit=blah is not defined returs 5
if ( $_GET['limit'] == NULL ) { $limit = 5; } // Else else {
$limit = $_GET['limit']; } $query = mysql_query("SELECT
* FROM members LIMIT '$limit'") or die(mysql_error()); while
($sql = mysql_fetch_array ($query) ) { echo
$sql['mem_name'] . '<br>'; } ?> Have fun.....
Mysql Query
- (2)
theres a bug somewhere in this query and i can't seem to find it. does anyone else see it?
CODE $query = "insert into templates
(tuid,tname,tdescription,template,archivedefault) values (1,'Sample Archive
Template','A sample archive template that only shows the name of the article with a link to
the default article viewer.','<a
href='viewarticle1.php?aid=[id]'>[articletitle]</a>',FALSE
41;"; ...
Running Php Web Scripts On A Local Machine
- (6)
hi all I'm VERY new to PHP and I'm having a slight problem... I want to be able to run PHP
scripts on my computer without installing a web browser. Let's say I have this code....
myScript.php CODE <HTML> <HEAD> <TITLE>PHP
Example</TITLE> </HEAD> <BODY> [color=#009900] <?php
print "This is an awesome scripting example."; ?>[/color]
</BODY> </HTML> ok. if I open this with Firefox or IE or any other Browser, I
will get a blank docu...
Using And?or In A Mysql Query
- (2)
hi everyone,
I have been trying to get a script to come up with the total number of comments a news item has
under it
news ...
Error Importing Sql Query Via Php
- Works in PHPmyAdmin (6)
CODE function sql() { $fp =
fopen("sql.sql","r"); $sql =
fread($fp,filesize("sql.sql")); fclose($fp);
return $sql; } Thats $this->sql and here is the other source CODE
function insert_sql() { if($_GET['insert']) {
$template = new template; $db = new db;
$db->connect(); $query = $this->sql(); ...
Running Php And Asp On The Same Machine
- how to? (4)
hello dudes, i was asking me if i can install and run php and asp on the same machine and how to do
that, i'm migrating to asp.net but actually i need to test some php files, but i installed
recently asp.net and don't know how to run my old php files, so i will be grateful if someone
tells me how. thanks in advance!...
Php Error When Running Script
- Php error when running script (3)
Hello, I get the following error: Parse error: syntax error, unexpected T_STRING in
/usr/local/psa/home/vhosts/club-amigos.co.uk/httpdocs/contact.php on line 44 when l run the
following script: Any help would be appreciated. CODE <?php /* PHP Form Mailer -
phpFormMailer v2.1, last updated 30th Nov 2005 - check back often for updates! (easy to use
and more secure than many cgi form mailers) FREE from: www.TheDemoSite.co.uk Should work
fine on most Unix/Linux platforms */ // ------- three variables you MUST change below
-------------...
Sql Query
- How do i run an SQL query (6)
I have been attempting to add mods to PHPbb forums for a while now but i have been unable to because
i have no idea how to run a Mysql or SQL Query. if anyone could let me know how i would greatly
appreciate it....
Problem With Mysql Query
- (1)
I know this isn't the SQL forum but MySQL is used in PHP. I get an error Query: SELECT
COUNT(users.*), COUNT(guests.*) FROM users INNER JOIN guests ON users.code != '' AND
users.last_active >= 1106971028 AND guests.time >= 1106971028 AND users.last_ip != guests.ip
Error#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 '*), COUNT(guests.*) FROM users INNER JOIN
guests ON users.code...
No Mysql When Running Phpinfo.php?
- (3)
Hi I am running apache 2/Mysql/PHP5 on XP pro. I took my first steps with a tutorial sending sql
queries via a PHP script and I got an error message in the browser. So I ran phpinfo.php and there
is no sign of mysql at all. I have searched the web and found a lot of PHP 5 users having problems
with the installation. Some dropped back to PHP 4 as it was easy to install, others deleted it all
and reinstalled some bundled software with apache/mysql/PHP which was easy to install too, others
got it fixed and moved on. I have spent a lot of time on this and am a little frustr...
No Mysql When Running Phpinfo.php?
- (1)
Hi I am running apache 2/Mysql/PHP5 on XP pro. I took my first steps with a tutorial sending sql
queries via a PHP script and I got an error message in the browser. So I ran phpinfo.php and there
is no sign of mysql at all. I have searched the web and found a lot of PHP 5 users having problems
with the installation. Some dropped back to PHP 4 as it was easy to install, others deleted it all
and reinstalled some bundled software with apache/mysql/PHP which was easy to install too, others
got it fixed and moved on. I have spent a lot of time on this and am a little frustr...
Looking for query, running, submitting, form
|
|
Searching Video's for query, running, submitting, form
|
advertisement
|
|