Everything looks ok, but doesn't show up in the database???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Everything looks ok, but doesn't show up in the database???

Post by boom4x »

Hello,

I have this little dillema...

This thing just doesn't want to show up in the database
1. in mysql everything is set to "all privelages"
2. connection is OK

Do you see anything wrong with this code?

Code: Select all

<?
include('settings.inc.php');
if($submit)
	{
    $sql = "INSERT INTO list
    (
    name,
    loc,
    incall,
    outcall,
    phone,
    stat,
    day,
    ref,
    photo,
    description,
    adddate,
    lid,
    id
    ) VALUES (
    '$name',
    '$loc',
    '$incall',
    '$outcall',
    '$phone',
    '$stat',
    '$day',
    '$ref,
    '$photo,
    '$description',
    '$adddate'
    '$lid',
    '$id'
    )";
    $result = mysql_query($sql);
    print ("<b><font face=arial color=red size=3>..... Added to the database.</b></font><br><br>");
    include('list.inc.php');
    print ("<br><b><font face=arial size=2><center><a href=list_add.inc.php>add listing</a></center></b></font><br><br>");
	}
else if($update)
	{
    $sql_update = "UPDATE list SET
    name='$name',
    loc='$loc',
    incall='$incall',
    outcall='$outcall',
    phone='$phone',
    stat='$stat',
    day='$day',
    ref='$ref',
    photo='$photo',
    description='$description'
    lid='$lid',
    WHERE
    id='$id'";
    $result = mysql_query($sql_update);
    print ("<b><font face=arial color=red size=3>..... Updated database.</b></font><br><br>");
    include('list.inc.php');
	}
else if($id)
	{
	$result = mysql_query("SELECT * FROM list WHERE id=$id",$db);
	$info = mysql_fetch_array($result);
?>
<? include('header.inc.php'); ?>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height=100% width="100%">
  <tr>
    <td width="100%" valign="top">

<form method="post" action="<? echo $PHP_SELF?>">
<input type="hidden" name="id" value="<? echo $info['id']; ?>">
Name: <input type="text" name="name" value="<? echo $info['name']; ?>"><br>
Location: <input type="text" name="loc" value="<? echo $info['loc']; ?>"><br>
Incall: <input type="text" name="incall" value="<? echo $info['incall']; ?>"><br>
Outcall: <input type="text" name="outcall" value="<? echo $info['outcall']; ?>"><br>
Phone #: <input type="text" name="phone" value="<? echo $info['phone']; ?>"><br>
Status: <input type="text" name="stat" value="<? echo $info['stat']; ?>"><br>
Referrer: <input type="text" name="ref" value="<? echo $info['ref']; ?>"><br>
Photo: <input type="text" name="photo" value="<? echo $info['photo']; ?>"><br>
Added on: <input type="text" name="adddate" value="<? echo $info['adddate']; ?>"><br>
Description:<br>
<textarea cols="40" rows="4" name="description"><? echo $info['description']; ?></textarea>
<br>
<input type="submit" name="update" value="Update Listing">
</form>

    </td>
  </tr>
</table>

<? include('footer.inc.php'); ?>
<?
	}

else
	{
?>

<? include('header.inc.php'); ?>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height=100% width="100%">
  <tr>
    <td width="100%" valign="top">

    <form method="post" action="<? echo $PHP_SELF?>">
Name: <input type="text" name="name"><br>
Location: <input type="text" name="loc"><br>
Incall: <input type="text" name="incall"><br>
Outcall: <input type="text" name="outcall"><br>
Phone #: <input type="text" name="phone"><br>
Status: <input type="text" name="stat"><br>
Referrer: <input type="text" name="ref"><br>
Photo: <input type="text" name="photo"><br>
Added on: <input type="text" name="adddate"><br>
Description:<br>
<textarea cols="40" rows="4" name="description"></textarea>
<br>
<input type="submit" name="submit" value="Add Listing">
</form>

    </td>
  </tr>
</table>

<?
}
?>
<? include('footer.inc.php'); ?>
If you have any idea what im doing wrong then please let me know.. Thank you in advance!
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

Chage this line:

Code: Select all

$result = mysql_query($sql_update);
To:

Code: Select all

$result = mysql_query($sql_update) or die (mysql_error());
to see if you're getting any errors
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

It's never going to get run, the insert that is. Now that I look at this a little more...

Refer to my response here:
viewtopic.php?t=19671&postdays=0&postorder=asc&start=30

scroll until you see my response starting with you submit php code is not going to run.
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Post by boom4x »

Thanks a lot for your quick reply!

Ok i did it but I can't add any new info and update the listings.

this is what i did

Code: Select all

<?
error_reporting(E_ALL);
include('settings.inc.php');
if (isset($_GET["action"]))
{
  if ($_GET["action"] == "submit")
  {
    $sql = "INSERT INTO categories
    (
    name,
    description,
    id
    ) VALUES (
    '$name',
    '$description',
    '$id'
    )";
    $result = mysql_query($sql);
    print ("<b><font face=arial color=red size=3>..... Added to the database.</b></font><br><br>");
    include('categories.inc.php');
    print ("<br><b><font face=arial size=2><center><a href=categories_add.inc.php>add category</a></center></b></font><br><br>");
  }
}
else if (isset($_GET["action"]))
{
  if ($_GET["action"] == "update")
  {
    $sql_update = "UPDATE categories SET
    name='$name',
    description='$description'
    WHERE
    id='$id'";
    $result = mysql_query($sql_update) or die (mysql_error());
    print ("<b><font face=arial color=red size=3>..... Updated database.</b></font><br><br>");
    include('categories.inc.php');
  }
}
else if (isset($_GET["action"]))
{
  if ($_GET["action"] == "id")
  {
	$result = mysql_query("SELECT * FROM categories WHERE id=$id",$db);
	$info = mysql_fetch_array($result);
?>
<? include('header.inc.php'); ?>
<form method="post" action="<? echo $PHP_SELF?>">
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<? echo $info['id']; ?>">
Name: <input type="text" name="name" value="<? echo $info['name']; ?>"><br>
Notes:<br>
<textarea cols="40" rows="4" name="description"><? echo $info['description']; ?></textarea>
<br>
<input type="submit" name="update" value="Add Listing">
</form>
<? include('footer.inc.php'); ?>
<?
  }
}

else
	{
?>

<? include('header.inc.php'); ?>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height=100% width="100%">
  <tr>
    <td width="100%" valign="top">
    <input type="hidden" name="action" value="submit">
    <form method="post" action="<? echo $PHP_SELF?>">
      <p>Name:<br>
      <input type="text" name="name" size="20"><br>
      Notes:<br>
      <textarea cols="42" rows="11" name="description"></textarea><br>
<input type="submit" name="submit" value="Add Listing">
    </form>
&nbsp;</td>
  </tr>
</table>

<?
}
?>
<? include('footer.inc.php'); ?>
Still doesn't work... am I missing something?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try echoing out your $sql... and see if all the values are right
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Post by boom4x »

Everything looks good... in that AND still having trouble cant add nor update!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Is that your FULL code?? Because i don't see any databse connection/selecting....
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Post by boom4x »

db connection is set in the settings.inc.php file. you also got the footer and the header files.

This script is ment to do 2 things... add and update listings on a website.

No one can figure it out?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

you already have one if isset($_GET['actin']) why do oyu do it 3 other times in the same if/else ??
try:

Code: Select all

<?php
error_reporting(E_ALL);
include('settings.inc.php');
if (isset($_GET["action"]))
{
  if ($_GET["action"] == "submit"){
    $sql = "INSERT INTO categories(name,description,id) VALUES ('$name','$description','$id')";
    $result = mysql_query($sql);
    print ("<b><font face=arial color=red size=3>..... Added to the database.</b></font><br><br>");
    include('categories.inc.php');
    print ("<br><b><font face=arial size=2><center><a href=categories_add.inc.php>add category</a></center></b></font><br><br>");
  }elseif ($_GET["action"] == "update"){
    $sql_update = "UPDATE categories SET name='$name', description='$description' WHERE id='$id'";
    $result = mysql_query($sql_update) or die (mysql_error());
    print ("<b><font face=arial color=red size=3>..... Updated database.</b></font><br><br>");
    include('categories.inc.php');
  }elseif ($_GET["action"] == "id"){
   $result = mysql_query("SELECT * FROM categories WHERE id=$id",$db);
   $info = mysql_fetch_array($result);
   include('header.inc.php'); ?>
   <form method="post" action="<? echo $PHP_SELF?>">
   <input type="hidden" name="action" value="update">
   <input type="hidden" name="id" value="<? echo $info['id']; ?>">
   Name: <input type="text" name="name" value="<? echo $info['name']; ?>"><br>
   Notes:<br>
   <textarea cols="40" rows="4" name="description"><? echo $info['description']; ?></textarea>
   <br>
   <input type="submit" name="update" value="Add Listing">
   </form>
   <? include('footer.inc.php'); 
  }else{
   echo "not a valid action.";
   }
}else{
include('header.inc.php'); ?>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height=100% width="100%">
  <tr>
    <td width="100%" valign="top">
    <input type="hidden" name="action" value="submit">
    <form method="post" action="<? echo $PHP_SELF?>">
      <p>Name:<br>
      <input type="text" name="name" size="20"><br>
      Notes:<br>
      <textarea cols="42" rows="11" name="description"></textarea><br>
<input type="submit" name="submit" value="Add Listing">
    </form>
 </td>
  </tr>
</table>

<?
}
include('footer.inc.php');
?>
Changed your code around, quite a bit. Try it and see if it works. It should unless i missed a few ; or ' or " :-D
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Post by boom4x »

Hello, I FIGURED IT OUT!!!

All this time... wow im suprised no one noticed what what wrong....

NO ONE NOTICED that I have "post" ... such a basic thing and it took me a day to figure out!

I'd like to thank everyone here that help me out with this... hehe but i had to nail the mistake in the finale.

So next time you're wondering why your information doesn't get posted in the database. Check your <form action=get or post> tags!!

thank you... hope this information will help someone else well.[/b]
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

ahhh!! such a silly mistake!! lol, don't you hate it?!
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Post by boom4x »

Yea, but i know one thing, i won't let it "get" me again! :roll:
Post Reply