Jump to content

Recommended Posts

  $query=mysql_query("SELECT * FROM person");

My mistake - I put the wrong table name there.

 

What do you mean by it won't let you add tables or fields?

It just won't add the table... And when I added that snippet of code you gave me to read all the fields from the table, it gave me the error at the top of my last post. One second, I'll try that "," instead of ";"...

 

EDIT: With the "," instead of ";" I still get the same error, but I guess that really doesn't relate to the fetch method.

That comma shouldn't be there as no other table data is following - age is the last field.

Ya, I changed the last comma after 'age' to a semicolon, but I still get
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/neomoonc/public_html/mysql.php on line 26

I'm going to have to go and get some sleep as it's 1:35am here.

 

Been driving all over Devon trying to find a new place to live and I'm completely shattered!

 

At least while using phpMyAdmin you can run queries from there and as you perform operations on your database, it'll show you the queries as well so you can also use it as a teaching aid.

The best thing I can recommend is going into phpMyAdmin via cPanel and checking the database.

 

Controlling the database purely via PHP is a bit like working blind.

Hmm... Okay, but I wanted to make a 'reply' system for suggestions from people and I was going to use MySQL to do it. Each field being a reply. I know it's a little risky giving them power lol, but I'll make something to delete some replies. I'll still be able to let people reply with PHP right? All I should do with PHPMyAdmin is make the tables? Then I can add fields through PHP easily?

 

EDIT: Thanks for the help, see ya.

if assoc is the prob then the error is in the select statement any way i edit the code and read the comment

 

<?php

if (isset($_POST['submit']))

{

$host = "localhost";

$user = "--edited--";

$pass = "--edited--";

$con = mysql_connect($host,$user,$pass)ordie('Could not connect: '. mysql_error()) ;

mysql_select_db("neomoonc?p?bb1",$con);// put the proper name of your db????

 

$sql = "CREATE TABLE person (firstname varchar(25),lastname varchar(25),age int(10))";

//this may work but y need to create table over and over again

mysql_query("INSERT INTO person (firstname,lastname,age) VALUES ('".$_POST['firstname']."', '".$_POST['lastname']."', '".$_POST['age']."')");

  $query=mysql_query("SELECT * FROM people");//person or people

  while ($fetch=mysql_fetch_assoc($query)) {

echo $fetch['firstname'].' '.$fetch['lastname'].' is '.$fetch['age'].'<br />';

  }

mysql_close($con);

}

?>

<HTML>

<head>

<title>MySQL Test</title>

</head>

<body>

<form name="input" action="<?=$_SERVER['PHP_SELF']?>" method="post">

<input type="text" name="firstname"><br>

<input type="text" name="lastname"><br>

<input type="text" name="age"><br>

<input type="submit" value="submit">

</form>

</body>

</html>

Last pressie before I go:

<?php
  if ($_POST['submit']) {
    $user = "--edited--";
    $pass = "--edited--";
    $dbh=mysql_connect("localhost",$user,$pass) or die ('I cannot connect to the database because: '.mysql_error());
    mysql_select_db("neomoonc?p?bb1",$con);
    //$sql = "CREATE TABLE person (firstname varchar(25),lastname varchar(25),age int(10))";
    if (mysql_query("INSERT INTO person (firstname,lastname,age) VALUES ('".$_POST['firstname']."', '".$_POST['lastname']."', '".$_POST['age']."')")) {
      $query=mysql_query("SELECT * FROM person");
      while ($fetch=mysql_fetch_assoc($query)) {
        echo $fetch['firstname'].' '.$fetch['lastname'].' is '.$fetch['age'].'<br />';
      }
    } else {echo 'Unable to insert the data into teh table';}
  }
?>
<html>
<head>
  <title>MySQL Test</title>
</head>
<body>
  <form name="input" action="<?=$_SERVER['PHP_SELF']?>" method="post">
  <input type="text" name="firstname">
  <input type="text" name="lastname">
  <input type="text" name="age">
  <input type="submit" value="submit">
  </form>
</body>
</html>

 

I added a short piece to check if the data gets inserted into the table. If it doesn't it doesn't bother to try and read the table. I also corrected the name of teh table in the SELECT query. As I said - best to check the status of the database using phpMyAdmin.

 

@teng84: If you don't surround your code in CODE tags and line breaks in any HTML don't appear as HTML!

ya sorry and take a sleep now ;D

 

Night all ;)

Goodnight.

 

Okay lol... New Problem... I figured why not try making a reply system. So, I edited just a little bit... Here's my new 2 things: (By the way, if you want to see the error for yourself go here: www.neo-moon.com/input.php )

<?php
if (isset($_POST['submit']))
{
   $host = "localhost";
   $user = "--edited--";
   $pass = "--edited--";
   $con = mysql_connect($host,$user,$pass)ordie('Could not connect: '. mysql_error()) ;
   mysql_select_db("neomoonc_main",$con);// put the proper name of your db?Huh

   //this may work but y need to create table over and over again
   mysql_query("INSERT INTO reply (reply) VALUES ('".$_POST['reply']."')");
     $query=mysql_query("SELECT * FROM reply");//person or people
     while ($fetch=mysql_fetch_assoc($query)) {
      echo $fetch['reply'].'
';
     }
    mysql_close($con);
}
?>

and for the HTML:

<Html>
<head>
<title>MySQL Test</title>
</heaD>
<body>
<form name="input" action="mysql.php" method="post">
Reply (Max length = 255):<br> <input type="text" name="reply" maxlength="255"><br>
<input type="submit" value="submit">
</form>
</body>
</html>

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.