?
Solved

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

Posted on 2003-03-17
11
Medium Priority
?
224 Views
Last Modified: 2008-03-06
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
Comment
Question by:ck969
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 3

Expert Comment

by:jayrod
ID: 8153109
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
 
LVL 15

Expert Comment

by:VGR
ID: 8153868
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
 
LVL 15

Accepted Solution

by:
VGR earned 75 total points
ID: 8153877
oh, and BTW, your script can ONLY work if you have register_globals=On in your php.ini :D
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

Expert Comment

by:foran
ID: 8156248
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
 
LVL 15

Expert Comment

by:VGR
ID: 8157593
thank you for the "B" grade, see you next time you ask a question jayrod 8-)
0
 
LVL 3

Expert Comment

by:jayrod
ID: 8158669
:P Thank you VGR
0
 
LVL 15

Expert Comment

by:VGR
ID: 8158979
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
 
LVL 3

Expert Comment

by:jayrod
ID: 8159625
i'm confused VGR ? I didn't give you a b grade did I?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8160947
I'm afraid you did
0
 
LVL 3

Expert Comment

by:jayrod
ID: 8161066
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
 
LVL 15

Expert Comment

by:VGR
ID: 8161114
oh my confusion jayrod, please forgive me.
Was talking to ck969, of course


mes plus plates excuses
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question