Jump to content

Recommended Posts

i am having problems editing the sql database
[code]
<?php
$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "***";
$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);
$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";
$sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";

if(isset($_POST['Submit_1'])) {

$gethead = $_POST['head'];
$getteacher = $_POST['teacher'];
$getnews = $_POST['news'];
$getmessage = $_POST['message'];
$getmembers = $_POST['members'];
$error = "";
if($gethead =="") $error.="*Please enter a head"."<br>";
if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
if($getnews=="") $error.="*Please enter some news"."<br>";
if($getmessage=="") $error.="*Please enter a message"."<br>";
if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

if($error==""){
   
      if(mysql_query($sqlqup))
{
    echo " Club page updated ";
    echo '<hr>';
    echo 'head:';
echo $gethead;
echo '<hr>';
echo 'Teacher:';
echo $getteacher;
echo '<hr>';
echo 'News:';
echo $getnews;
echo '<hr>';
echo 'Message:';
echo $getmessage;
echo '<hr>';
echo 'Members';
echo $getmembers;
echo '<hr>';
}
  else {
echo " Failed to upadate";
}

  }
  else{
    echo "<div align='center'>". $error ."</div>";
  }

}
else {
  $mclubqu=mysql_query($sqlview);
  $club= mysql_fetch_array($mclubqu);
  ?>

  <div align="center">
    <h1><? echo $club['Club']?> Club</h1>
      <form action="" method="POST">
  <table width="588"  border="1.2">
    <tr>
      <td width="95">Head</td>
  <td width="7">&nbsp;</td>
        <td width="302"><input name="head" type="text"/></td>
  <td width="166"><? echo $club['Head']?> </td>
    </tr>
        <tr>
      <td>Teacher</td>
  <td>&nbsp;</td>
      <td><input name="teacher" type="text"/></td>
  <td><? echo $club['Teacher']?> </td>
    </tr>
    <tr>
      <td>News</td>
  <td>&nbsp;</td>
      <td><textarea name="news" cols="40" rows="10"></textarea></td>
  <td><? echo $club['News']?> </td>
    </tr>
  <tr>
      <td>Message</td>
  <td>&nbsp;</td>
      <td><textarea name="message" cols="40" rows="10"></textarea></td>
  <td><? echo $club['Message']?> </td>
    </tr>
  <tr>
      <td>Members</td>
  <td>&nbsp;</td>
        <td><textarea name="members" cols="40" rows="10"></textarea></td>
  <td><? echo $club['members']?> </td>
    </tr>
  </tr>
  <tr>
      <td>&nbsp;</td>
  <td>&nbsp;</td>
      <td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
</td>
    <td>&nbsp;</td>
  </tr>
  </table>
</form>
    </div>

<?php
}
?>
[/code]

my problem is that it says
failed to update

this code here is a magnified verison of the top 1
where somthing goes wrong
[code]
<?php
$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID=$clubno";
if(mysql_query($sqlqup))
{
echo " Club page updated ";
echo '<hr>';
echo 'head:';
echo $gethead;
echo '<hr>';
echo 'Teacher:';
echo $getteacher;
echo '<hr>';
echo 'News:';
echo $getnews;
echo '<hr>';
echo 'Message:';
echo $getmessage;
echo '<hr>';
echo 'Members';
echo $getmembers;
echo '<hr>';
}
 
else {

        echo " Failed to upadate";

}[/code]
what could be wrong
is it a sql query error
cause i have bo clue

ps it says that the sql query is correct on sqlyog

regards ludger
Link to comment
https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/
Share on other sites

the error is that it does not edit database witch it is ment to edit it
just returns to the main page with the header looking like this
[code]http://localhost/intranet/clubs/admins/edit.php?head=213324&teacher=234324&latest+news=234324324&message=234234423&members=324324324324&Submit=Submit[/code]

PS.. the 1234123 is what i edited it into
here is a better one
[code]http://localhost/intranet/clubs/admins/edit.php?head=Ludger&teacher=Piet&latest+news=Welcome&message=This+is+a+club&members=22&Submit=Submit[/code]

i am thinking of getting the info from the headder using
[code]<?php
if (isset($_GET['club'])) $club = $_GET['club'];
php?>[/code]

but there could be alot of info so i really dont know

regards
Ludger


Are you getting the "Failed to Update" error or is the data just not changing?

ALWAYS... let me repeat ALWAYS do the following:

1) build your query outside of the mysql_query function:
<?php
$query = "UPDATE tablexyz blah blah";
$result = mysql_query($query) or die(mysql_error());
?>

Right now, you're checking whether you have a valid result or not, but you're not displaying any error or even logging the error.  Mysql can provide you with some valuable troubleshooting information!
Chnage this:
[code]echo " Failed to upadate";[/code]
to
[code]echo " Failed to upadate, Reason for failing<br />\n" . mysql_error());[/code]
With this code you shoul now get an error message from MySQL why your query is failing

What I think is the problem is is becuase you are not use quotes around your values. Try thhe following as the query:
[code]$sqlqup = "UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";[/code]
[code]Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Teacher=, News=, Message=, members= WHERE ClubID='1'' at line 1[/code]
i see

i will try it now with quots
ye it did
[quote]Club page updated
--------------------------------------------------------------------------------
head:sanan
--------------------------------------------------------------------------------
Teacher:none
--------------------------------------------------------------------------------
News:noen
--------------------------------------------------------------------------------
Message:13
--------------------------------------------------------------------------------
Members12213[/quote]

but now another error

they did not go into the database

my database is emtey

[attachment deleted by admin]
maby if you could give me a quick example
on taking a string and putting it into a database
cause i know that it is getting the info from the forms
but its not getting onto the database
it puts " " (nothing and turns current into nothing) in the database

thx alot

ludger
I think I know whats happing. You are setting up your query before you define the variables you use in your query. The query should be defined before this: [code=php:0]if(mysql_query($sqlqup))[/code] This si what your code should be:
[code]<?php

$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "***";

$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);

if(isset($_POST['Submit_1']))
{

    $gethead = $_POST['head'];
$getteacher = $_POST['teacher'];
$getnews = $_POST['news'];
$getmessage = $_POST['message'];
$getmembers = $_POST['members'];
$error = "";

    if($gethead =="") $error.="*Please enter a head"."<br>";
if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
if($getnews=="") $error.="*Please enter some news"."<br>";
if($getmessage=="") $error.="*Please enter a message"."<br>";
if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

if(isset($errro))
    {
        $sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))
{
        echo " Club page updated ";
    echo '<hr>';
    echo 'head:';
echo $gethead;
echo '<hr>';
echo 'Teacher:';
echo $getteacher;
echo '<hr>';
echo 'News:';
echo $getnews;
echo '<hr>';
echo 'Message:';
echo $getmessage;
echo '<hr>';
echo 'Members';
echo $getmembers;
echo '<hr>';
}
  else
        {
    echo " Failed to upadate";
}

}
else
    {
        echo "<div align='center'>". $error ."</div>";
}
}
else
{
    $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";

    $mclubqu = mysql_query($sqlview);
   
$club = mysql_fetch_array($mclubqu);
?>
  <div align="center">
    <h1><? echo $club['Club']?> Club</h1>
      <form action="" method="POST">
  <table width="588"  border="1.2">
    <tr>
      <td width="95">Head</td>
  <td width="7">&nbsp;</td>
        <td width="302"><input name="head" type="text"/></td>
  <td width="166"><? echo $club['Head']?> </td>
    </tr>
        <tr>
      <td>Teacher</td>
  <td>&nbsp;</td>
      <td><input name="teacher" type="text"/></td>
  <td><? echo $club['Teacher']?> </td>
    </tr>
    <tr>
      <td>News</td>
  <td>&nbsp;</td>
      <td><textarea name="news" cols="40" rows="10"></textarea></td>
  <td><? echo $club['News']?> </td>
    </tr>
  <tr>
      <td>Message</td>
  <td>&nbsp;</td>
      <td><textarea name="message" cols="40" rows="10"></textarea></td>
  <td><? echo $club['Message']?> </td>
    </tr>
  <tr>
      <td>Members</td>
  <td>&nbsp;</td>
        <td><textarea name="members" cols="40" rows="10"></textarea></td>
  <td><? echo $club['members']?> </td>
    </tr>
  </tr>
  <tr>
      <td>&nbsp;</td>
  <td>&nbsp;</td>
      <td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
</td>
    <td>&nbsp;</td>
  </tr>
  </table>
</form>
    </div>

<?php
}
?>[/code]
it says no database selected??

[code]Failed to upadate, Reason for failing
No database selected[/code]

i used your code and it said that
then i tried using my code but just move

$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))

same resault both ways
Add
[code]mysql_select_db($database_intranet, $intranet);[/code]

after
[code]$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);[/code]
Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head=sanan, Teacher=none, News=noneeen, Message=noneoneo, member' at line 1

here is my qeury
[code]UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher',
News='$getnews', Message='$getmessage', members='$getmembers'
WHERE ClubID='$clubno'[/code]
You dont need quotes around club_data, that is fine on its own as its the table name. You only use quotes around the columns values.
So use this as the query:
[code]UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'[/code]
If I put quotes around club_data then I apologiese fro my mistake.
if there are no quots then it gives no database selected


so i used your query and add the quots and this is what i got

with quots:
[code]Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head='sanan', Teacher='none', News='noneeen', Message='noneoneo'' at line 1[/code]

without:
[code]Failed to upadate, Reason for failing
No database selected[/code]
[code]<?php
/*session checker */
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  // For security, start by assuming the visitor is NOT authorized.
  $isValid = False;

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  if (!empty($UserName)) {
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
    // Parse the strings into arrays.
    $arrUsers = Explode(",", $strUsers);
    $arrGroups = Explode(",", $strGroups);
    if (in_array($UserName, $arrUsers)) {
      $isValid = true;
    }
    // Or, you may restrict access to only certain users based on their username.
    if (in_array($UserGroup, $arrGroups)) {
      $isValid = true;
    }
    if (($strUsers == "") && true) {
      $isValid = true;
    }
  }
  return $isValid;
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { 
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}
##club veryfiyer
if (isset($_GET['club'])) $club = $_GET['club'];

else $club = 'error';
$error='no';

switch ($club) {

case 'error':
$error='yes'; 
break;

case '1':
$clubno='1'; 
break;
case '2':
$clubno='2'; 
break;
case '3':
$clubno='3'; 
break;

default:
$error='yes';
break;
}

$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "jam3s0n";

$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($club_data, $intranet);

if(isset($_POST['Submit_1']))
{

    $gethead = $_POST['head'];
$getteacher = $_POST['teacher'];
$getnews = $_POST['news'];
$getmessage = $_POST['message'];
$getmembers = $_POST['members'];
$error = "";

    if($gethead =="") $error.="*Please enter a head"."<br>";
if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
if($getnews=="") $error.="*Please enter some news"."<br>";
if($getmessage=="") $error.="*Please enter a message"."<br>";
if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

if(isset($error))
    {
        $sqlqup= "UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))
{
        echo " Club page updated ";
    echo '<hr>';
    echo 'head:';
echo $gethead;
echo '<hr>';
echo 'Teacher:';
echo $getteacher;
echo '<hr>';
echo 'News:';
echo $getnews;
echo '<hr>';
echo 'Message:';
echo $getmessage;
echo '<hr>';
echo 'Members';
echo $getmembers;
echo '<hr>';
}
  else
        {
    echo " Failed to upadate, Reason for failing<br />\n" . mysql_error();
}

}
else
    {
        echo "<div align='center'>". $error ."</div>";
}
}
else
{
    $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";

    $mclubqu = mysql_query($sqlview);
   
$club = mysql_fetch_array($mclubqu);
?>
  <div align="center">
    <h1><? echo $club['Club']?> Club</h1>
      <form action="" method="POST">
  <table width="588"  border="1.2">
    <tr>
      <td width="95">Head</td>
  <td width="7">&nbsp;</td>
        <td width="302"><input name="head" type="text"/></td>
  <td width="166"><? echo $club['Head']?> </td>
    </tr>
        <tr>
      <td>Teacher</td>
  <td>&nbsp;</td>
      <td><input name="teacher" type="text"/></td>
  <td><? echo $club['Teacher']?> </td>
    </tr>
    <tr>
      <td>News</td>
  <td>&nbsp;</td>
      <td><textarea name="news" cols="40" rows="10"></textarea></td>
  <td><? echo $club['News']?> </td>
    </tr>
  <tr>
      <td>Message</td>
  <td>&nbsp;</td>
      <td><textarea name="message" cols="40" rows="10"></textarea></td>
  <td><? echo $club['Message']?> </td>
    </tr>
  <tr>
      <td>Members</td>
  <td>&nbsp;</td>
        <td><textarea name="members" cols="40" rows="10"></textarea></td>
  <td><? echo $club['members']?> </td>
    </tr>
  </tr>
  <tr>
      <td>&nbsp;</td>
  <td>&nbsp;</td>
      <td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
</td>
    <td>&nbsp;</td>
  </tr>
  </table>
</form>
    </div>

<?php
}
?>[/code]
[code]
$sqlqup= "UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";
[/code]

that's how it should look. as wildteen said, no quotes around the table name.  but you say it gives you a no database selected error when you do this?

edit: shouldn't

mysql_select_db($club_data, $intranet);

be

mysql_select_db($database_intranet, $intranet);


yip
it says

Failed to upadate, Reason for failing
No database selected

and if i do put quots around it then
Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ''club_data' SET Head='sanan', Teacher='none', News='noneeen',
Message='noneoneo'' at line 1
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.