PDA

View Full Version : Adding to a database



Chris2k2
February 8th, 2003, 08:58
Hello, Not been on here in ages but i am back again.

I have a problem. Im creating a Admin CP for one of my sites that all runs through a database.

Well i am creating a form to enter info then it will put it into the database.

Here is the code.


<?php
include('config.php');

mysql_query("INSERT INTO cheats VALUES ('$id', '$name', '$content')");

?>

<title>The Cheats Directory Admin CP</title>
<body bgcolor="#006699" link="#000080"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">

<tr>
<td><img src="left.gif"></td>
<td width="100%" background="center.gif" align="center"><font size="3" face="Verdana">Admin CP<u></u></font></td>
<td><img src="right.gif"></td>
<p align="center">&nbsp;</th>
</tr>
<tr>
<td width="100%" bgcolor="#669999" colspan="3">&nbsp;<center>

ID: <input type="text" name="id" size="20">
<P>
Name: <input type="text" name="name" size="20">
<P>
Cheats: <textarea rows=15 cols=50 name="content"></textarea>
<P>
<P>
<input type="submit" name="">
<P></center></td>
</tr>
</tr>
</table>

Nothing may look wrong with it but it has a bug, it adds a empty row to the database every time the page is loaded.

So any ideas how i can stop this?

thank you,

Kaliber
February 8th, 2003, 09:18
try this


mysql_query("INSERT INTO cheats (id, name, content) VALUES '$id', '$name', '$content')");

Chris2k2
February 8th, 2003, 09:29
Well it stops it entering the info into the database, but now the submit button isn't working :confused: :confused2

Kaliber
February 8th, 2003, 09:33
just replace your query with my query

Kaliber
February 8th, 2003, 09:35
hmm, where are your <form> tags?

Chris2k2
February 8th, 2003, 09:37
He He, i forgot the form tags, just put them in.

I did replace that query but it stopped it submitting

Kaliber
February 8th, 2003, 19:15
How did they add an empty row if that form went nowhere?

jetalomar
February 8th, 2003, 23:47
Firstable you don't have any form tag on the code.
you forgot to put this <form> </form>. if you want that form to work you must do this.

here is the solution. it's adding a empty row every time you refresh the page. to avoid that you must do this.

copy and paste this code to your page. replacing your old code.

<?php
include('config.php');
if($status==ok){
mysql_query("INSERT INTO cheats VALUES ('$id', '$name', '$content')");}

?>

<title>The Cheats Directory Admin CP</title>
<body bgcolor="#006699" link="#000080"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<form name="form1" method="post" action="">

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">

<tr>
<td height="33"><img src="left.gif"></td>
<td width="100%" background="center.gif" align="center"><font size="3" face="Verdana">Admin CP<u></u></font></td>
<td><img src="right.gif"></td>
<p align="center">&nbsp;</th>
</tr>
<tr>
<td width="100%" bgcolor="#669999" colspan="3">&nbsp;<center>

ID: <input type="text" name="id" size="20">
<input name="status" type="hidden" id="status" value="ok">
<P>
Name: <input type="text" name="name" size="20">
<P>
Cheats: <textarea rows=15 cols=50 name="content"></textarea>
<P>
<P>
<input type="submit" name="">
<P></center></td>
</tr>
</tr>
</table></form>



that code should solve your problem.

Chris2k2
February 9th, 2003, 06:21
Thanks all, well i found someone on my hosts forum who was willing to help me code my Admin CP for my site and it seems it has gone good and i can now add, edit, delete, and update the number of cheats in the database using the script i have coded.

So thanks for your help all.