9, January 2009

this page wont write to database - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: this page wont write to database
« previous next »
Pages: [1] 2 Print

Author Topic: this page wont write to database  (Read 1434 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« on: Jan 23, 2006, 10:06:06 PM »

Code:
<?php
ob_start
(); 
include(
"config.php"); 
if(
$logged[username] && $logged[level] ==5

//checks to see if the user is logged in, and if their user level 
//is 5 (this is administrator)
if($_GET[links]) 

//checks to see if there is a ?user=username variable in the url. 
if (!$_POST[update]) 

// the form hasn't been submitted.  We continue... 
$data mysql_query("SELECT * from links where id = '$_GET[links]'"); 
$data mysql_fetch_array($data); 
//these lines get the user's information and put it in an array. 
//we will display the information in the html form 
echo(
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"submit\" value=\"Update\"></td>
</tr>
</table>
</form> 
</div>"
); 
//displays the html form 

else 

$url = ($_POST[url]); 
$title = ($_POST[title]); 
$description = ($_POST[description]);
// the above lines get rid of all html. 
echo ("The link has been successfully updated."); 
$update mysql_query("Update links set url = '$url', title = '$title', description = '$description' where id = '$_GET[links]'"); 
// updates the information in the database. 


else 

$getlinks mysql_query("Select * from links order by id asc"); 
while(
$data mysql_fetch_array($getlinks)) 

//makes a list of all the links 
echo("<a href=\"?open=15&links=$data[id]\">$data[title]</a><br />"); 
//displays the link names 


}
else

//the user's level is not 5!  They cannot view this page 
echo("Sorry, but you are not allowed to view this page!"); 


?>


ive tried everything.. any ideas?

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #1 on: Jan 23, 2006, 10:37:12 PM »

You should use "INSERT INTO" instead of "UPDATE" if you want to write new records to your table. The "UPDATE" statement is to update a read record


Last blog : Are You Stumbling Yet?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #2 on: Jan 24, 2006, 07:59:21 AM »

this isnt for writing new records, this is for changing existing records..

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #3 on: Jan 24, 2006, 08:08:11 AM »

Don't you have to add the information on the existing record to the update statement the? (ie. Update table set field=value WHERE FIELD=OLDVALUE)


Last blog : Are You Stumbling Yet?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #4 on: Jan 24, 2006, 09:48:29 AM »

ive already done this, "$update = mysql_query... " so on & so forth, here is new code but still no luck:

Code:
<?php
ob_start
(); 
include(
"config.php"); 
if($logged[username] && $logged[level] == 5

//checks to see if the user is logged in, and if their user level 
//is 5 (this is administrator)
if($_GET[links]) 

//checks to see if there is a ?user=username variable in the url. 
if (!$_POST[update]) 

// the form hasn't been submitted.  We continue... 
$data mysql_query("SELECT * from links where id = '$_GET[links]'"); 
$data mysql_fetch_array($data); 
//these lines get the user's information and put it in an array. 
//we will display the information in the html form 
echo(
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"submit\" value=\"Update\"></td>
</tr>
</table>
</form> 
</div>"
); 
//displays the html form 

else 

$url $_POST[url]; 
$title $_POST[title]; 
$description $_POST[description];
// the above lines set variables used below
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '$_GET[links]'"); 
mysql_query($update) or die(mysql_error());
// updates the information in the database.
echo "The link has been successfully updated."


else 

$getlinks mysql_query("SELECT * from links order by id asc"); 
while($data mysql_fetch_array($getlinks)) 
//makes a list of all the links

  echo("<a href=\"?open=15&links=$data[id]\">$data[title]</a><br />"); 
//displays the link names 


}
else

//the user's level is not 5!  They cannot view this page 
echo("Sorry, but you are not allowed to view this page!"); 


?>


Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #5 on: Jan 24, 2006, 12:09:09 PM »

Is the page echoing "The link has been successfully updated."?


Last blog : Site of the Month - August 2007
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #6 on: Jan 24, 2006, 12:14:32 PM »

Try...
Code:
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '{$_GET[links]}'");


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #7 on: Jan 24, 2006, 01:33:43 PM »

no, it never displays the succesful message and that 2nd solution didnt work either Sad

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #8 on: Jan 24, 2006, 01:52:42 PM »

If this form posts to itself then try...

Code:
if (!$_POST[Update])


Last blog : Site of the Month - August 2007
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #9 on: Jan 24, 2006, 01:56:56 PM »

Please list a sample of your url string so I can see what $_GET[links] is...


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #10 on: Jan 24, 2006, 03:09:52 PM »

what u suggested for post update i already have in the page but i tried what u suggested and that also didnt work.. the url would look like ?open=15&links=13...

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #11 on: Jan 24, 2006, 03:16:41 PM »

What exactly are you getting when you click update?


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #12 on: Jan 24, 2006, 03:56:41 PM »

nothing page refreshes and the update never takes place

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #13 on: Jan 24, 2006, 03:58:26 PM »

so the form shows again...


Last blog : Site of the Month - August 2007
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #14 on: Jan 24, 2006, 04:04:31 PM »

AH... try...

Code:
if ($_POST['submit'] != 'Update')
« Last Edit: Jan 24, 2006, 04:11:44 PM by wineo »


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #15 on: Jan 24, 2006, 04:31:56 PM »

yes! it works now. awesome..thx wineo.. im working on creating my own CMS for sleekpixel.net its turning out quite nicely thx to you and this forum as well as nikolas Tongue

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #16 on: Jan 24, 2006, 04:34:51 PM »

No worries!


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #17 on: Jan 24, 2006, 04:54:35 PM »

think u could help with another page?

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #18 on: Jan 24, 2006, 05:03:25 PM »

Fire away, I will help where I can...


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #19 on: Jan 24, 2006, 05:04:47 PM »

another database update problem (man i suck with updating a database, thats the only probs i really have)

link_mod.php

Code:
<?
ob_start();
include("config.php");
if ($logged[username] && $logged[level] >= 2) 
{
// the user is logged in!  We continue...
if (!$_POST[update])
{
// the form hasn't been submitted.  We continue...
$data2 = mysql_query("SELECT * from users where username = '$logged[username]'");
$data2 = mysql_fetch_array($data2);
$urlid = $data2[urlid];
$data = mysql_query("SELECT * from links where id = '$urlid'");
$data = mysql_fetch_array($data);
// the above lines get the information so that it can be displayed in the html form.
echo("
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"update\" value=\"Update\"></td>
</tr>
</table>
</form>
</div>");
}
else
{
$url = $_POST[url];
$title = $_POST[title];
$description = $_POST[description];
// the above lines set variables used below
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '$urlid'");
mysql_query($update) or die(mysql_error());
// updates the information in the database.
echo "Your link has been successfully updated."; 
}
}
else
{
// They aren't logged in!
echo "You have either not paid for your link to even submit it, or you are not logged in.";
}
?>

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1329
Tags : php html forums databases cms Bookmark this thread : Digg Del.icio.us