Jump to content

Learning Mysql


Phty5h

Recommended Posts

[quote author=fenway link=topic=101799.msg403504#msg403504 date=1153868930]
Well, perhaps businessman332211 can help you out... I can't really jump in and debug his code at this point.
[/quote]

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.
Link to comment
Share on other sites

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;

[code]<!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>[/code]

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 : [code]$selectdb = mysql_select_db("fakedatabase");[/code]

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?
Link to comment
Share on other sites

[me=Phty5h]dances around like a chimpanzee drunk on laudenum[/me]

I did it !!!

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

heres the code im using:

[code]<!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>[/code]

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

[code]<!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>[/code]
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.
Link to comment
Share on other sites

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.
[code]<!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>[/code]
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.