Page 1 of 1

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

Posted: Sun Mar 21, 2004 4:45 pm
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!

Posted: Sun Mar 21, 2004 5:43 pm
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

Posted: Sun Mar 21, 2004 5:46 pm
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.

Posted: Sun Mar 21, 2004 7:03 pm
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?

Posted: Sun Mar 21, 2004 7:27 pm
by Illusionist
try echoing out your $sql... and see if all the values are right

Posted: Sun Mar 21, 2004 7:46 pm
by boom4x
Everything looks good... in that AND still having trouble cant add nor update!

Posted: Sun Mar 21, 2004 8:25 pm
by Illusionist
Is that your FULL code?? Because i don't see any databse connection/selecting....

Posted: Sun Mar 21, 2004 8:36 pm
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?

Posted: Sun Mar 21, 2004 8:58 pm
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

Posted: Sun Mar 21, 2004 10:11 pm
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]

Posted: Mon Mar 22, 2004 11:17 am
by Illusionist
ahhh!! such a silly mistake!! lol, don't you hate it?!

Posted: Tue Mar 23, 2004 12:42 am
by boom4x
Yea, but i know one thing, i won't let it "get" me again! :roll: