Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

I'm a beginner, and can't see what's wrong here !

Hi, I was trying to write a simple PHP script that connect to MYSQL DB on windows 2000 on the same machine. This is my script :

<?php
 /* This program enters news items into a database */
if(isset($submit)):
 $db = mysql_connect("localhost", "root");
 mysql_select_db("dating", $db);
 $date = date("Y-m-d");
 $sql = "INSERT INTO profile
 (id, first_name, last_name, userid, password)
 VALUES(NULL,'$first_name','$last_name', '$userid','$password')";
 mysql_query($sql);
 print("<h2>The Data Has Been Entered</h2>\n");
 print("<b>You can add another news story below</b><hr>\n");
endif;
?>
<p><h3>Enter your profile into the database</h3>
<form action="index.php" method="post">
First Name:<br><input type="text" name="first_name"><p>
Last Name:<br><input type="text" name="last_name"><p>
User ID:<br><input type="text" name="userid"><p>
Password:<br><input type="password" name="password"><p>
<input type="submit" name="submit" value="Submit Details!">
</form>

Somehow, after I pressed the submit button, I always got the empty form without showing me the message : "The Data Has Been Entered." Why ? and the record wasn't successfully saved in the table. How come there is no error message display.

I'm running Apache 1.3.x webserver.
0
ck969
Asked:
ck969
  • 6
  • 4
1 Solution
 
jayrodCommented:
Try putting your entire sql statement on one line. PHP doesn't tend to like eol characters..

also try using 127.0.0.1 instead of localhost
0
 
VGRCommented:
is this normal ?
"if(isset($submit)):"

shouldn't be
"if(isset($submit)){"

?

I also recommend to add some "aerating" spaces like this "if (isset($submit)) {" and to NEVER write a query like you do.
Just use the .= operator
0
 
VGRCommented:
oh, and BTW, your script can ONLY work if you have register_globals=On in your php.ini :D
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
foranCommented:
take a look at this page it has the format in which you make sql queries :)

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20535888.html
0
 
VGRCommented:
thank you for the "B" grade, see you next time you ask a question jayrod 8-)
0
 
jayrodCommented:
:P Thank you VGR
0
 
VGRCommented:
this wasn't exactly a compliment ;-)
you may ask for a grade change in "community support" if you really want to thank me :D
0
 
jayrodCommented:
i'm confused VGR ? I didn't give you a b grade did I?
0
 
VGRCommented:
I'm afraid you did
0
 
jayrodCommented:
ok I'm confused.. I've asked one question on this board. and it was under ms-dos. I accepted the answer from someone else. Your name is no where to be found.

please enlighten me.
0
 
VGRCommented:
oh my confusion jayrod, please forgive me.
Was talking to ck969, of course


mes plus plates excuses
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now