Jump to content


Photo

Learning Mysql


  • Please log in to reply
36 replies to this topic

#21 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 July 2006 - 07:33 PM

Nothing to apologize for... just a general remark; shortcuts are an easy way to "miss the point", which defeats the entire purpose.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#22 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 25 July 2006 - 07:33 PM

Thanks for the advice, I appreciate and for the author of the post, if you needed any more help feel free to ask.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#23 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 25 July 2006 - 10:23 PM

that seems to work better.

but ... i dont get a confirmation echo'd out that the info has been placed in the database correctly.... it just seems to refresh the screen ..... tbh im not sure how id go about prooving to myself that the info is in the database when it does work... i assume ill be able to see the entries in phpmyadmin somewhere.

Am i supposed to be using 2 pages here?.... i have all the code on a single page at the moment?

*Phty5h feels stupid

#24 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 July 2006 - 10:34 PM

You don't need to have two pages... the same script can either insert or select.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#25 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 25 July 2006 - 10:48 PM

then i dont understand why this doesnt seem to work.... i must be missing something .... i understand what its doing... and logically this should work.

#26 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 July 2006 - 11:08 PM

Well, perhaps businessman332211 can help you out... I can't really jump in and debug his code at this point.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#27 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 25 July 2006 - 11:14 PM

Well, perhaps businessman332211 can help you out... I can't really jump in and debug his code at this point.


Hopefully i'll figure it out myself...... you 2 guys have been amazing so far... especially businessman.

Its past midnight here now... and ive been on this since 9am ..... not a bad days work considering i didnt even know how to create a database this morning.

I'm gonna get some shut eye, and ponder the situation, and hopefully ill be able to move forward in the morning when im refreshed, my mind is goo at the moment tbh.

I'll post tomorrow and let you know how i progress.... or, more likley to beg for some more of your assistance =P

Thanks again guys, i feel like im moving forward at last.

#28 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 26 July 2006 - 11:41 AM

Sorry guys, ive been playing with this all morning, and im getting no where.

In fact, the problem only seems to get worse, heres the code for reference;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>forumsugest.php</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?
if (isset($formsubmit)) {
$connect = mysql_connect("localhost", "???????", "???????");   //passwords ommitted
$selectdb = mysql_select_db("mydatabase");
if (!connect || !selectdb) {
echo "There was an error connecting to, or select the database";
echo mysql_error(); // remove this after you get it working properly
}
$textfield = $_POST['firstname'];
$textfield2 = $_POST['surname'];
$insert = "INSERT INTO name(first, second) VALUES ('$textfield', '$textfield2')";
if ($query = mysql_query($insert)) {
echo "The data was inserted into the database correctly";
}else {
echo mysql_error(); // take this out when it starts working.
echo "There was a problem inserting the data into the database";
  }
}
?>
<form method="insert" action="forumsugest.php">      
   <p>First Name 
     <input type="text" name="firstname" />
</p>
   <p>Surname 
     <input type="text" name="surname" />
</p>
   <p>
     <input type="submit" name="formsubmit" value="Submit" />
   </p>
</form>

</body>
</html>

Now when i run that, i get a window that displays my two text fields, when i enter text into the form and click submit the form seems to just refresh, when i check the database in phpmyadmin i cannot see any change.... and so can only assume that it is not working.

Ive played with it alot this morning, and one of the things i noticed is very odd.... as you can see from above the database im trying to connect to is called "mydatabase" which i created in phpmyadmin.... however .......

If i change the name of the database to :
$selectdb = mysql_select_db("fakedatabase");

where fakedatabase is none existant, the strange thing is that it doesnt seem to make any difference at all.... the same happens as when i have the actual database name in there.

Ive tried putting the form tags within the <?...?> tags,  but this gave me an error.

then i tried putting the php segmant within the form tags... and this works exactly as ive explained the above code works.

Im really confused and feel that everything i thought i acheived yesterday was just bullshit ......... i spent nearly 18 hours on this yesterday, and now i find out that it isnt even doing what i thoguht it was doing.

As i type this ive just checked and prooved that i havnt even connected to a database. i went to my other script, and put a made up name into the database connect bit, and it makes no difference.

I'm left with the worrying possibility that the problem lies with my actual database, and maybe that im not using phpmyadmin properly.

is there something im meant to do after i create my database in phpmyadmin?

do i need to export it?... or put the sql somewhere?

#29 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 26 July 2006 - 01:22 PM

*Phty5h dances around like a chimpanzee drunk on laudenum

I did it !!!

I managed to get the origional script to work  ;D ;D

heres the code im using:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>form.php</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?

$connect = mysql_connect('localhost', "???????", "???????")
or die ('Could Not Connect: ' . mysql_error());
echo '<b>Step 1 :</b> Connected Successfully! <br>';

$db = 'mydatabase';
mysql_select_db($db) or die('Could Not Select Database ('.$db.') Because of: '.mysql_error());
echo '<b>Step 2:</b> Connection to ('.$db.') successful!<BR>';

$textfield = $_POST['firstname'];
$textfield2 = $_POST['surname'];
// for not until you can get to where you can pass them straight into, you have to understand how the queries work first. name which has 3 fields : ID, First & Second
$insert = "INSERT INTO name (first, second) VALUES ('$textfield', '$textfield2')";
mysql_query($insert); 

mysql_close($connect);
?>
<form name="form1" id="form1" method="post" action="form.php">      
   <p>First Name 
     <input type="text" name="firstname" />
</p>
   <p>Surname 
     <input type="text" name="surname" />
</p>
   <p>
     <input type="submit" name="Submit" value="Submit" />
   </p>
</form>
</body>
</html>

Thank you so much guys, there is no way on earth i could have got this far without you ........ i have a lot further i need to go with this yet.

But for now, i still cant get the script that businessman provided to work, i think it would improve my understanding if you could help me fix that one .... as it seems to be a little more advanced than the one ive managed to get going.

Hope to hear from you soon.

And thanks again  ;D

#30 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 July 2006 - 03:32 PM

The bottom line is that it works, my script was the same thing your trying to do, but to help you learn,a nd you doubled the benefit from, what you are wanting, the bottom line is
1. Does it do what you wanted.
2. You created it yourself
you have created your first custom script I would guess unless you have done this before.  Congratulations, if you need anything else feel free to post, but you sometimes have to give me time, because phpfreaks doesn't always email notifications, so I sometimes have to check manually, sorry I didn't get back to it sooner, congratulations.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#31 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 July 2006 - 03:43 PM

The next step is only to process the form on submission, not on every page load.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#32 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 July 2006 - 03:47 PM

ah yes, good advice, here is what you would do, to get it to do that.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>form.php</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?

if (isset($submit)) {
$connect = mysql_connect('localhost', "???????", "???????")
or die ('Could Not Connect: ' . mysql_error());
echo '<b>Step 1 :</b> Connected Successfully! <br>';

$db = 'mydatabase';
mysql_select_db($db) or die('Could Not Select Database ('.$db.') Because of: '.mysql_error());
echo '<b>Step 2:</b> Connection to ('.$db.') successful!<BR>';

$textfield = $_POST['firstname'];
$textfield2 = $_POST['surname'];
// for not until you can get to where you can pass them straight into, you have to understand how the queries work first. name which has 3 fields : ID, First & Second
$insert = "INSERT INTO name (first, second) VALUES ('$textfield', '$textfield2')";
 if (mysql_query($insert)) {
echo "Custom message thanking the person for putting in the data";
$controller = true;
} // close if query 

mysql_close($connect);
} // close isset
?>
<?php
if ($controller != true) {
?>
<form name="form1" id="form1" method="post" action="form.php">      
   <p>First Name 
     <input type="text" name="firstname" />
</p>
   <p>Surname 
     <input type="text" name="surname" />
</p>
   <p>
     <input type="submit" name="Submit" value="Submit" />
   </p>
</form>
<?php
}
?>
</body>
</html>
That should be it, what that will do is, thank them for putting in the data, and make the form disappear when they enter the data.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#33 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 July 2006 - 03:49 PM

wait, you have to stop forgetting
<?php
?>
that php is very important, or it won't work with all php settings.
so here is what you should have know with what I gave you.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>form.php</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?php

if (isset($submit)) {
$connect = mysql_connect('localhost', "???????", "???????")
or die ('Could Not Connect: ' . mysql_error());
echo '<b>Step 1 :</b> Connected Successfully! <br>';

$db = 'mydatabase';
mysql_select_db($db) or die('Could Not Select Database ('.$db.') Because of: '.mysql_error());
echo '<b>Step 2:</b> Connection to ('.$db.') successful!<BR>';

$textfield = $_POST['firstname'];
$textfield2 = $_POST['surname'];
// for not until you can get to where you can pass them straight into, you have to understand how the queries work first. name which has 3 fields : ID, First & Second
$insert = "INSERT INTO name (first, second) VALUES ('$textfield', '$textfield2')";
 if (mysql_query($insert)) {
echo "Custom message thanking the person for putting in the data";
$controller = true;
} // close if query 

mysql_close($connect);
} // close isset
?>
<?php
if ($controller != true) {
?>
<form name="form1" id="form1" method="post" action="form.php">      
   <p>First Name 
     <input type="text" name="firstname" />
</p>
   <p>Surname 
     <input type="text" name="surname" />
</p>
   <p>
     <input type="submit" name="Submit" value="Submit" />
   </p>
</form>
<?php
}
?>
</body>
</html>
go through every current script you have
you have opening and closing tags
<?
?>
change those opening tags, all of them too
<?php
and let me know if you need any more help with anything else

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#34 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 July 2006 - 10:56 PM

.. minor detail, major problem.  If your form submit element is NAMEd 'Submit', you need to check isset($Submit) not isset($submit).
Legend has it that reading the manual never killed anyone.
My site

#35 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 July 2006 - 10:59 PM

thanks for noticing, just change that part of the script to a capitol S

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#36 Phty5h

Phty5h
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 July 2006 - 01:49 PM

Thanks for all the help guys, Been busy networking my offices these last few days.... but im retty much back to the code now (phew)..... Im about to start trying to build a membership system from scratch for my new business' website, so im pretty certain that im gonna have lots of questions over the next week or so.

Thanks again to everyone who's helped so far.... and keep an eye out for a new thread ill start for the membership system.


Many Thanks

#37 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 31 July 2006 - 01:51 PM

If I am going to be able to help at all unfortunatley you will have to use the same post, I am very busy the past few days with e-lost and found, and I try to only do posts when I have time.  So try and use the same one, or I can promise I won't get around to seeing it, I always help people when I start because I bookmark the page and have it email them to me, but sometimes I don't have time to hunt new posts.  Or either post a link to the new post in this one at least.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users